[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / SocketDescriptor.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * Provides an object which can be used to send data to and which uniquely identifies a connection
10  * to a remote host. You will need to be able to generate multiple of these which meet Eq and
11  * implement Hash to meet the PeerManager API.
12  * 
13  * For efficiency, [`Clone`] should be relatively cheap for this type.
14  * 
15  * Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
16  * has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
17  * having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
18  * further calls to the [`PeerManager`] related to the original socket occur. This allows you to
19  * use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
20  * to simply use another value which is guaranteed to be globally unique instead.
21  */
22 public class SocketDescriptor : CommonBase {
23         internal readonly bindings.LDKSocketDescriptor bindings_instance;
24         internal SocketDescriptor(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
25         private SocketDescriptor(bindings.LDKSocketDescriptor arg) : base(bindings.LDKSocketDescriptor_new(arg)) {
26                 this.ptrs_to.AddLast(arg);
27                 this.bindings_instance = arg;
28         }
29         ~SocketDescriptor() {
30                 if (ptr != 0) { bindings.SocketDescriptor_free(ptr); }
31         }
32
33         public interface SocketDescriptorInterface {
34                 /**
35                  * Attempts to send some data from the given slice to the peer.
36                  * 
37                  * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
38                  * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
39                  * called and further write attempts may occur until that time.
40                  * 
41                  * If the returned size is smaller than `data.len()`, a
42                  * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
43                  * written. Additionally, until a `send_data` event completes fully, no further
44                  * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
45                  * prevent denial-of-service issues, you should not read or buffer any data from the socket
46                  * until then.
47                  * 
48                  * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
49                  * (indicating that read events should be paused to prevent DoS in the send buffer),
50                  * `resume_read` may be set indicating that read events on this descriptor should resume. A
51                  * `resume_read` of false carries no meaning, and should not cause any action.
52                  */
53                 long send_data(byte[] _data, bool _resume_read);
54                 /**
55                  * Disconnect the socket pointed to by this SocketDescriptor.
56                  * 
57                  * You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
58                  * call (doing so is a noop).
59                  */
60                 void disconnect_socket();
61                 /**
62                  * Checks if two objects are equal given this object's this_arg pointer and another object.
63                  */
64                 bool eq(SocketDescriptor _other_arg);
65                 /**
66                  * Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
67                  * This is used, for example, for inclusion of this object in a hash map.
68                  */
69                 long hash();
70         }
71         private class LDKSocketDescriptorHolder { internal SocketDescriptor held; }
72         private class LDKSocketDescriptorImpl : bindings.LDKSocketDescriptor {
73                 internal LDKSocketDescriptorImpl(SocketDescriptorInterface arg, LDKSocketDescriptorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
74                 private SocketDescriptorInterface arg;
75                 private LDKSocketDescriptorHolder impl_holder;
76                 public long send_data(byte[] _data, bool _resume_read) {
77                         long ret = arg.send_data(_data, _resume_read);
78                                 GC.KeepAlive(arg);
79                         return ret;
80                 }
81                 public void disconnect_socket() {
82                         arg.disconnect_socket();
83                                 GC.KeepAlive(arg);
84                 }
85                 public bool eq(long _other_arg) {
86                         SocketDescriptor ret_hu_conv = new SocketDescriptor(null, _other_arg);
87                         if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
88                         bool ret = arg.eq(ret_hu_conv);
89                                 GC.KeepAlive(arg);
90                         return ret;
91                 }
92                 public long hash() {
93                         long ret = arg.hash();
94                                 GC.KeepAlive(arg);
95                         return ret;
96                 }
97         }
98         public static SocketDescriptor new_impl(SocketDescriptorInterface arg) {
99                 LDKSocketDescriptorHolder impl_holder = new LDKSocketDescriptorHolder();
100                 impl_holder.held = new SocketDescriptor(new LDKSocketDescriptorImpl(arg, impl_holder));
101                 return impl_holder.held;
102         }
103         /**
104          * Attempts to send some data from the given slice to the peer.
105          * 
106          * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
107          * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
108          * called and further write attempts may occur until that time.
109          * 
110          * If the returned size is smaller than `data.len()`, a
111          * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
112          * written. Additionally, until a `send_data` event completes fully, no further
113          * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
114          * prevent denial-of-service issues, you should not read or buffer any data from the socket
115          * until then.
116          * 
117          * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
118          * (indicating that read events should be paused to prevent DoS in the send buffer),
119          * `resume_read` may be set indicating that read events on this descriptor should resume. A
120          * `resume_read` of false carries no meaning, and should not cause any action.
121          */
122         public long send_data(byte[] data, bool resume_read) {
123                 long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read);
124                 GC.KeepAlive(this);
125                 GC.KeepAlive(data);
126                 GC.KeepAlive(resume_read);
127                 return ret;
128         }
129
130         /**
131          * Disconnect the socket pointed to by this SocketDescriptor.
132          * 
133          * You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
134          * call (doing so is a noop).
135          */
136         public void disconnect_socket() {
137                 bindings.SocketDescriptor_disconnect_socket(this.ptr);
138                 GC.KeepAlive(this);
139         }
140
141         /**
142          * Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
143          * This is used, for example, for inclusion of this object in a hash map.
144          */
145         public long hash() {
146                 long ret = bindings.SocketDescriptor_hash(this.ptr);
147                 GC.KeepAlive(this);
148                 return ret;
149         }
150
151         public override int GetHashCode() {
152                 return (int)this.hash();
153         }
154         internal long clone_ptr() {
155                 long ret = bindings.SocketDescriptor_clone_ptr(this.ptr);
156                 GC.KeepAlive(this);
157                 return ret;
158         }
159
160         /**
161          * Creates a copy of a SocketDescriptor
162          */
163         public SocketDescriptor clone() {
164                 long ret = bindings.SocketDescriptor_clone(this.ptr);
165                 GC.KeepAlive(this);
166                 if (ret >= 0 && ret <= 4096) { return null; }
167                 SocketDescriptor ret_hu_conv = new SocketDescriptor(null, ret);
168                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
169                 return ret_hu_conv;
170         }
171
172 }
173 } } }