[Java] Update auto-generated bindings to 0.0.115
[ldk-java] / src / main / java / org / ldk / structs / SocketDescriptor.java
index c1bdaf55971aef36f86281db2396f0be40e178fe..cf17dab68c23a529fa25016acace085ffd6b940a 100644 (file)
@@ -4,6 +4,7 @@ import org.ldk.impl.bindings;
 import org.ldk.enums.*;
 import org.ldk.util.*;
 import java.util.Arrays;
+import java.lang.ref.Reference;
 import javax.annotation.Nullable;
 
 /**
@@ -11,7 +12,7 @@ import javax.annotation.Nullable;
  * to a remote host. You will need to be able to generate multiple of these which meet Eq and
  * implement Hash to meet the PeerManager API.
  * 
- * For efficiency, Clone should be relatively cheap for this type.
+ * For efficiency, [`Clone`] should be relatively cheap for this type.
  * 
  * Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
  * has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
@@ -33,7 +34,19 @@ public class SocketDescriptor extends CommonBase {
        protected void finalize() throws Throwable {
                if (ptr != 0) { bindings.SocketDescriptor_free(ptr); } super.finalize();
        }
-
+       /**
+        * Destroys the object, freeing associated resources. After this call, any access
+        * to this object may result in a SEGFAULT or worse.
+        *
+        * You should generally NEVER call this method. You should let the garbage collector
+        * do this for you when it finalizes objects. However, it may be useful for types
+        * which represent locks and should be closed immediately to avoid holding locks
+        * until the GC runs.
+        */
+       public void destroy() {
+               if (ptr != 0) { bindings.SocketDescriptor_free(ptr); }
+               ptr = 0;
+       }
        public static interface SocketDescriptorInterface {
                /**
                 * Attempts to send some data from the given slice to the peer.
@@ -78,19 +91,23 @@ public class SocketDescriptor extends CommonBase {
                impl_holder.held = new SocketDescriptor(new bindings.LDKSocketDescriptor() {
                        @Override public long send_data(byte[] data, boolean resume_read) {
                                long ret = arg.send_data(data, resume_read);
+                               Reference.reachabilityFence(arg);
                                return ret;
                        }
                        @Override public void disconnect_socket() {
                                arg.disconnect_socket();
+                               Reference.reachabilityFence(arg);
                        }
                        @Override public boolean eq(long other_arg) {
                                SocketDescriptor ret_hu_conv = new SocketDescriptor(null, other_arg);
-                               ret_hu_conv.ptrs_to.add(this);
+                               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                                boolean ret = arg.eq(ret_hu_conv);
+                               Reference.reachabilityFence(arg);
                                return ret;
                        }
                        @Override public long hash() {
                                long ret = arg.hash();
+                               Reference.reachabilityFence(arg);
                                return ret;
                        }
                });
@@ -117,6 +134,9 @@ public class SocketDescriptor extends CommonBase {
         */
        public long send_data(byte[] data, boolean resume_read) {
                long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(data);
+               Reference.reachabilityFence(resume_read);
                return ret;
        }
 
@@ -128,6 +148,7 @@ public class SocketDescriptor extends CommonBase {
         */
        public void disconnect_socket() {
                bindings.SocketDescriptor_disconnect_socket(this.ptr);
+               Reference.reachabilityFence(this);
        }
 
        /**
@@ -136,6 +157,16 @@ public class SocketDescriptor extends CommonBase {
         */
        public long hash() {
                long ret = bindings.SocketDescriptor_hash(this.ptr);
+               Reference.reachabilityFence(this);
+               return ret;
+       }
+
+       @Override public int hashCode() {
+               return (int)this.hash();
+       }
+       long clone_ptr() {
+               long ret = bindings.SocketDescriptor_clone_ptr(this.ptr);
+               Reference.reachabilityFence(this);
                return ret;
        }
 
@@ -144,9 +175,10 @@ public class SocketDescriptor extends CommonBase {
         */
        public SocketDescriptor clone() {
                long ret = bindings.SocketDescriptor_clone(this.ptr);
-               if (ret < 1024) { return null; }
+               Reference.reachabilityFence(this);
+               if (ret >= 0 && ret <= 4096) { return null; }
                SocketDescriptor ret_hu_conv = new SocketDescriptor(null, ret);
-               ret_hu_conv.ptrs_to.add(this);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }