* 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
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.
}
@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;
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;
}