[][src]Trait lightning::ln::peer_handler::SocketDescriptor

pub trait SocketDescriptor: Eq + Hash + Clone {
    fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize;
fn disconnect_socket(&mut self); }

Provides an object which can be used to send data to and which uniquely identifies a connection 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.

You probably want to just extend an int and put a file descriptor in a struct and implement send_data. Note that if you are using a higher-level net library that may close() itself, be careful to ensure you don't have races whereby you might register a new connection with an fd the same as a yet-to-be-disconnect_event()-ed.

Required methods

fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize

Attempts to send some data from the given slice to the peer.

Returns the amount of data which was sent, possibly 0 if the socket has since disconnected. Note that in the disconnected case, a disconnect_event must still fire and further write attempts may occur until that time.

If the returned size is smaller than data.len(), a write_available event must trigger the next time more data can be written. Additionally, until the a send_data event completes fully, no further read_events should trigger on the same peer!

If a read_event on this descriptor had previously returned true (indicating that read events should be paused to prevent DoS in the send buffer), resume_read may be set indicating that read events on this descriptor should resume. A resume_read of false does not imply that further read events should be paused.

fn disconnect_socket(&mut self)

Disconnect the socket pointed to by this SocketDescriptor. Once this function returns, no more calls to write_event, read_event or disconnect_event may be made with this descriptor. No disconnect_event should be generated as a result of this call, though obviously races may occur whereby disconnect_socket is called after a call to disconnect_event but prior to that event completing.

Loading content...

Implementors

Loading content...