Skip to main content

AbstractSocket

Trait AbstractSocket 

Source
pub trait AbstractSocket {
    type Message;
    type Param;

    // Required methods
    fn create_client_socket(
        &mut self,
        _param: &PSocketParam,
        _extra_param: &Self::Param,
    ) -> bool;
    fn create_server_socket(
        &mut self,
        param: &PSocketParam,
        extra_param: &Self::Param,
    ) -> bool;
    fn send_data<T>(&mut self, data: &T, flag: PSendFlag) -> PSendStatus
       where T: Default + DataStream + Debug;
    fn recv_data<T>(&mut self, data: &mut T, flag: PRecvFlag) -> PRecvStatus
       where T: Default + DataStream + Debug;
    fn send_msg(
        &mut self,
        message: &Self::Message,
        flag: PSendFlag,
    ) -> PSendStatus;
    fn recv_msg(
        &mut self,
        message: &mut Self::Message,
        flag: PRecvFlag,
    ) -> PRecvStatus;
    fn close(&mut self);
    fn is_connected(&mut self) -> bool;
}
Expand description

Abtract implementation of a socket. It can send and recieved arbitrary data and can also be close and tell if it is connected to and other socket.

Required Associated Types§

Source

type Message

Message to be used with the backend

Source

type Param

Extra parameters to be used with the backend

Required Methods§

Source

fn create_client_socket( &mut self, _param: &PSocketParam, _extra_param: &Self::Param, ) -> bool

Create a client Socket

§Parameters
  • _param : parameters to be used to create the basic socket (hostname, port)
  • _extra_param : extra parameters to be used to create the socket
§Returns

True on success, false otherwise

Source

fn create_server_socket( &mut self, param: &PSocketParam, extra_param: &Self::Param, ) -> bool

Create a server Socket

§Parameters
  • param : parameters to be used to create the basic socket (hostname, port)
  • extra_param : extra parameters to be used to create the socket
§Returns

True on success, false otherwise

Source

fn send_data<T>(&mut self, data: &T, flag: PSendFlag) -> PSendStatus
where T: Default + DataStream + Debug,

Abstract method to send data

§Parameters
  • data : data to be sent
  • flag : PSendFlag to determine if the send is blocking or not
§Returns

corresponding PSendStatus

Source

fn recv_data<T>(&mut self, data: &mut T, flag: PRecvFlag) -> PRecvStatus
where T: Default + DataStream + Debug,

Abstract method to recieved data

§Parameters
  • data : recieved data
  • flag : PRecvFlag to determine if the recv is blocking or not
§Returns

corresponding PRecvStatus

Source

fn send_msg(&mut self, message: &Self::Message, flag: PSendFlag) -> PSendStatus

Method to send data

§Parameters
  • message : message to be sent
  • flag : PSendFlag to determine if the send is blocking or not
§Returns

corresponding PSendStatus

Source

fn recv_msg( &mut self, message: &mut Self::Message, flag: PRecvFlag, ) -> PRecvStatus

Method to recieved message

§Parameters
  • message : recieved message
  • flag : PRecvFlag to determine if the recv is blocking or not
§Returns

corresponding PRecvStatus

Source

fn close(&mut self)

Close the socket

Source

fn is_connected(&mut self) -> bool

Say if the socket is connected

§Returns

true if the socket is connected, false otherwise

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.

Implementors§