Struct message_io::network::Network [−][src]
Network is in charge of managing all the connections transparently. It transforms raw data from the network into message events and vice versa, and manages the different adapters for you.
Implementations
impl<'a> Network
[src]
pub fn new<M, C>(user_event_callback: C) -> Network where
M: for<'b> Deserialize<'b> + Send + 'static,
C: Fn(NetEvent<M>) + Send + Clone + 'static,
[src]
M: for<'b> Deserialize<'b> + Send + 'static,
C: Fn(NetEvent<M>) + Send + Clone + 'static,
Creates a new Network. The user must register an event_callback that can be called each time the network generate and NetEvent.
pub fn connect<A: ToSocketAddrs>(
&mut self,
transport: Transport,
addr: A
) -> Result<Endpoint>
[src]
&mut self,
transport: Transport,
addr: A
) -> Result<Endpoint>
Creates a connection to the specific address by TCP. The endpoint, an identified of the new connection, will be returned. If the connection can not be performed (e.g. the address is not reached) an error is returned.
pub fn listen<A: ToSocketAddrs>(
&mut self,
transport: Transport,
addr: A
) -> Result<(ResourceId, SocketAddr)>
[src]
&mut self,
transport: Transport,
addr: A
) -> Result<(ResourceId, SocketAddr)>
Listen messages from specified transport. The giver address will be used as interface and listening port. If the port can be opened, a ResourceId identifying the listener is returned along with the local address, or an error if not. The address is returned despite you passed as parameter because when a '0' port is specified, the OS will give a value. If the protocol is UDP and the address is Ipv4 in the range of multicast ips (from 224.0.0.0 to 239.255.255.255) it will be listening is multicast mode.
pub fn remove_resource(&mut self, resource_id: ResourceId) -> Option<()>
[src]
Remove a network resource.
Returns None
if the resource id not exists.
This is used mainly to remove resources that the program has been created explicitely,
as connection or listeners.
Resources of endpoints generated by listening from TCP can also be removed
to close the connection.
Note: UDP endpoints generated by listening from UDP shared the resource.
This means that there is no resource to remove as the TCP case.
(in fact there is no connection itself to close, 'there is no spoon').
pub fn local_addr(&self, resource_id: ResourceId) -> Option<SocketAddr>
[src]
Request a local address of a resource.
Returns None
if the endpoint id does not exists.
Note: UDP endpoints generated by a listen from UDP shared the resource.
pub fn send<M: Serialize>(
&mut self,
endpoint: Endpoint,
message: M
) -> SendingStatus
[src]
&mut self,
endpoint: Endpoint,
message: M
) -> SendingStatus
Serialize and send the message thought the connection represented by the given endpoint. If the same message should be sent to different endpoints, use Network::send_all() to get a better performance. The funcion panics if the endpoint do not exists in the Network. If the endpoint disconnects during the sending, a RemoveEndpoint is generated. A SendingStatus is returned with the information about the sending.
pub fn send_all<'b, M: Serialize>(
&mut self,
endpoints: impl IntoIterator<Item = &'b Endpoint>,
message: M
) -> &Vec<SendingStatus>
[src]
&mut self,
endpoints: impl IntoIterator<Item = &'b Endpoint>,
message: M
) -> &Vec<SendingStatus>
This functions performs the same actions as Network::send() but for several endpoints. When there are severals endpoints to send the data, this function is faster than consecutive calls to Network::send() since the encoding and serialization is performed only one time for all endpoints. The funcion panics if some of endpoints do not exists in the Network.
Auto Trait Implementations
impl !RefUnwindSafe for Network
[src]
impl Send for Network
[src]
impl Sync for Network
[src]
impl Unpin for Network
[src]
impl !UnwindSafe for Network
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,