Trait message_io::network::adapter::Remote[][src]

pub trait Remote: Resource + Sized {
    fn connect(remote_addr: RemoteAddr) -> Result<ConnectionInfo<Self>>;
fn receive(&self, process_data: impl FnMut(&[u8])) -> ReadStatus;
fn send(&self, data: &[u8]) -> SendStatus;
fn pending(&self, readiness: Readiness) -> PendingStatus; fn ready_to_write(&self) -> bool { ... } }
Expand description

The resource used to represent a remote. It usually is a wrapper over a socket/stream.

Required methods

Called when the user performs a connection request to an specific remote address. The implementator is in change of creating the corresponding remote resource. The RemoteAddr contains either a SocketAddr or a url::Url. It is in charge of deciding what to do in both cases. It also must return the extracted address as SocketAddr.

Called when a remote resource received an event. The resource must be ready to receive this call. It means that it has available data to read, or there is some connection related issue, as a disconnection. The implementator is in charge of processing that action and returns a ReadStatus.

The process_data function must be called for each data chunk that represents a message. This call will produce a crate::network::NetEvent::Message API event. Note that receive() could imply more than one call to read. The implementator must be read all data from the resource. For most of the cases it means read until the network resource returns WouldBlock.

Sends raw data from a resource. The resource must be ready to receive this call. The implementator is in charge to send the entire data. The SendStatus will contain the status of this attempt.

Called when a Remote is created (explicity of by a listener) and it is not consider ready yet. A remote resource is considered ready when it is totally connected and can be used for writing data. It implies that the user has received the Connected or Accepted method for that resource.

This method is in charge to determine if a resource is ready or not. No Connected or Accepted events will be generated until this function return PendingStatus::Ready. The method wil be called several times with different Readiness until the implementator returns a PendingStatus::Ready or PendingStatus::Disconnected.

Provided methods

The resource is available to write. It must be ready to receive this call. Here the implementator optionally can try to write any pending data. The return value is an identification of the operation result. If the method returns true, the operation was successful, otherwise, the resource will be disconnected and removed.

Implementors