pub trait SocketDescriptor:
Eq
+ Hash
+ Clone {
// Required methods
fn send_data(&mut self, data: &[u8], continue_read: bool) -> usize;
fn disconnect_socket(&mut self);
}Expand description
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.
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
having triggered the disconnection or a call to PeerManager::socket_disconnected), and no
further calls to the PeerManager related to the original socket occur. This allows you to
use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
to simply use another value which is guaranteed to be globally unique instead.
Required Methods§
Sourcefn send_data(&mut self, data: &[u8], continue_read: bool) -> usize
fn send_data(&mut self, data: &[u8], continue_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, PeerManager::socket_disconnected must still be
called and further write attempts may occur until that time.
If the returned size is smaller than data.len(), a
PeerManager::write_buffer_space_avail call must be made the next time more data can be
written.
If continue_read is not set, further PeerManager::read_event calls should be
avoided until another call is made with it set. This allows us to pause read if there are
too many outgoing messages queued for a peer to avoid DoS issues where a peer fills our
buffer by sending us messages that need response without reading the responses.
Note that calls may be made with an empty data to update the continue_read flag.
Sourcefn disconnect_socket(&mut self)
fn disconnect_socket(&mut self)
Disconnect the socket pointed to by this SocketDescriptor.
You do not need to call PeerManager::socket_disconnected with this socket after this
call (doing so is a noop).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.