[−][src]Struct socket_collection::UdpSock
Asynchronous UDP socket wrapper with some specific behavior to our use cases:
- The maximum message length is as long as max UDP payload size.
- Incoming/outgoing messages are buffered.
- All messages are encrypted with
EncryptContextand decrypted withDecryptContextthat can be changed at any time.
Methods
impl UdpSock[src]
impl UdpSockpub fn wrap(sock: UdpSocket) -> Self[src]
pub fn wrap(sock: UdpSocket) -> SelfWrap UdpSocket and use the default socket configuration.
pub fn wrap_with_conf(sock: UdpSocket, conf: SocketConfig) -> Self[src]
pub fn wrap_with_conf(sock: UdpSocket, conf: SocketConfig) -> SelfWrap UdpSocket and use given socket configuration.
pub fn bind(addr: &SocketAddr) -> Res<Self>[src]
pub fn bind(addr: &SocketAddr) -> Res<Self>Create new UdpSock bound to the given address with default configuration.
pub fn bind_with_conf(addr: &SocketAddr, conf: SocketConfig) -> Res<Self>[src]
pub fn bind_with_conf(addr: &SocketAddr, conf: SocketConfig) -> Res<Self>Create new UdpSock bound to the given address with given configuration.
pub fn set_encrypt_ctx(&mut self, enc_ctx: EncryptContext) -> Res<()>[src]
pub fn set_encrypt_ctx(&mut self, enc_ctx: EncryptContext) -> Res<()>Specify data encryption context which will determine how outgoing data is encrypted.
pub fn set_decrypt_ctx(&mut self, dec_ctx: DecryptContext) -> Res<()>[src]
pub fn set_decrypt_ctx(&mut self, dec_ctx: DecryptContext) -> Res<()>Specify data decryption context which will determine how incoming data is decrypted.
pub fn connect(&mut self, addr: &SocketAddr) -> Res<()>[src]
pub fn connect(&mut self, addr: &SocketAddr) -> Res<()>Set default destination address for UDP socket.
pub fn local_addr(&self) -> Res<SocketAddr>[src]
pub fn local_addr(&self) -> Res<SocketAddr>Get the local address UDP socket is bound to.
pub fn peer_addr(&self) -> Res<SocketAddr>[src]
pub fn peer_addr(&self) -> Res<SocketAddr>Get the address UdpSock was connected to.
pub fn set_ttl(&self, ttl: u32) -> Res<()>[src]
pub fn set_ttl(&self, ttl: u32) -> Res<()>Set Time To Live value for the underlying UDP socket.
pub fn ttl(&self) -> Res<u32>[src]
pub fn ttl(&self) -> Res<u32>Retrieve Time To Live value.
pub fn take_error(&self) -> Res<Option<Error>>[src]
pub fn take_error(&self) -> Res<Option<Error>>Retrieve last socket error, if one exists.
pub fn read<T: DeserializeOwned + Serialize>(&mut self) -> Res<Option<T>>[src]
pub fn read<T: DeserializeOwned + Serialize>(&mut self) -> Res<Option<T>>Read message from the connected socket. Call this from inside the ready handler.
Returns:
- Ok(Some(data)): data has been successfully read from the socket
- Ok(None): there is not enough data in the socket. Call
read()again in the next invocation of thereadyhandler. - Err(error): there was an error reading from the socket.
pub fn read_frm<T: DeserializeOwned + Serialize>(
&mut self
) -> Res<Option<(T, SocketAddr)>>[src]
pub fn read_frm<T: DeserializeOwned + Serialize>(
&mut self
) -> Res<Option<(T, SocketAddr)>>Read message from the socket. Call this from inside the ready handler.
Returns:
- Ok(Some((data, peer_address))): data has been successfully read from the socket
- Ok(None): there is not enough data in the socket. Call
read()again in the next invocation of thereadyhandler. - Err(error): there was an error reading from the socket.
pub fn write<T: Serialize>(&mut self, msg: Option<(T, Priority)>) -> Res<bool>[src]
pub fn write<T: Serialize>(&mut self, msg: Option<(T, Priority)>) -> Res<bool>Write a message to the connected socket.
Returns:
- Ok(true): the message has been successfully written.
- Ok(false): the message has been queued, but not yet fully written. will be attempted in the next write schedule.
- Err(error): there was an error while writing to the socket.
pub fn write_to<T: Serialize>(
&mut self,
msg: Option<(T, SocketAddr, Priority)>
) -> Res<bool>[src]
pub fn write_to<T: Serialize>(
&mut self,
msg: Option<(T, SocketAddr, Priority)>
) -> Res<bool>Write a message to the socket to the given address.
Returns:
- Ok(true): the message has been successfully written.
- Ok(false): the message has been queued, but not yet fully written. will be attempted in the next write schedule.
- Err(error): there was an error while writing to the socket.
pub fn into_underlying_sock(self) -> Res<UdpSocket>[src]
pub fn into_underlying_sock(self) -> Res<UdpSocket>Retrieve the underlying mio UdpSocket.
Trait Implementations
impl From<UdpSock> for Socket[src]
impl From<UdpSock> for Socketimpl Default for UdpSock[src]
impl Default for UdpSockimpl Debug for UdpSock[src]
impl Debug for UdpSockimpl Evented for UdpSock[src]
impl Evented for UdpSockAuto Trait Implementations
Blanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut Timpl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeIdimpl<T> DebugAny for T where
T: Any + Debug,
impl<T> DebugAny for T where
T: Any + Debug, impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any, impl<T> Same for T
impl<T> Same for Ttype Output = T
Should always be Self