pub struct EgmPeer { /* private fields */ }
Expand description
Blocking EGM peer for sending and receiving messages over UDP.
Implementations
sourceimpl EgmPeer
impl EgmPeer
sourcepub fn new(socket: UdpSocket) -> Self
pub fn new(socket: UdpSocket) -> Self
Wrap an existing UDP socket in a peer.
If you want to use the EgmPeer::recv
and EgmPeer::send
functions,
you should use an already connected socket.
Otherwise, you can only use EgmPeer::recv_from
and EgmPeer::send_to
.
sourcepub fn bind(addrs: impl ToSocketAddrs) -> Result<Self>
pub fn bind(addrs: impl ToSocketAddrs) -> Result<Self>
Create an EGM peer on a newly bound UDP socket.
The socket will not be connected to a remote peer,
so you can only use EgmPeer::recv_from
and EgmPeer::send_to
.
sourcepub fn socket_mut(&mut self) -> &mut UdpSocket
pub fn socket_mut(&mut self) -> &mut UdpSocket
Get an exclusive reference to the inner socket.
sourcepub fn into_socket(self) -> UdpSocket
pub fn into_socket(self) -> UdpSocket
Consume self and get the inner socket.
sourcepub fn recv(&mut self) -> Result<EgmRobot, ReceiveError>
pub fn recv(&mut self) -> Result<EgmRobot, ReceiveError>
Receive a message from the remote address to which the inner socket is connected.
To use this function, you must pass an already connected socket to EgmPeer::new
.
If the peer was created with an unconnected socket, this function will panic.
sourcepub fn recv_from(&mut self) -> Result<(EgmRobot, SocketAddr), ReceiveError>
pub fn recv_from(&mut self) -> Result<(EgmRobot, SocketAddr), ReceiveError>
Receive a message from any remote address.
sourcepub fn purge_recv_queue(&mut self) -> Result<()>
pub fn purge_recv_queue(&mut self) -> Result<()>
Purge all messages from the socket read queue.
Useful to ignore old messages when the socket has been left unpolled for a while.
This will leave the socket in blocking mode when the purging is done.
sourcepub fn send(&mut self, msg: &EgmSensor) -> Result<(), SendError>
pub fn send(&mut self, msg: &EgmSensor) -> Result<(), SendError>
Send a message to the remote address to which the inner socket is connected.
To use this function, you must pass an already connected socket to EgmPeer::new
.
If the peer was created with an unconnected socket, this function will panic.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for EgmPeer
impl Send for EgmPeer
impl Sync for EgmPeer
impl Unpin for EgmPeer
impl UnwindSafe for EgmPeer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more