pub struct TcpSession { /* private fields */ }Expand description
A connected FCI command socket.
TcpSession is Sync: one thread may block in
TcpSession::blocking_receive_response while another calls
TcpSession::send_request, which is how Robot::stop() interrupts a running motion in
libfranka.
Implementations§
Source§impl TcpSession
impl TcpSession
Sourcepub fn connect(
addr: SocketAddr,
timeout: Duration,
layout: HeaderLayout,
) -> FrankaResult<TcpSession>
pub fn connect( addr: SocketAddr, timeout: Duration, layout: HeaderLayout, ) -> FrankaResult<TcpSession>
Connects to addr and configures the socket the way franka::Network’s constructor
does: blocking, 1 s connect timeout, TCP keepalive with a 1 s idle time, 3 probes and a
1 s interval (best effort — libfranka swallows failures of the three setOption calls).
The receive timeout is set to POLL_TIMEOUT so that a blocking receive wakes every
10 ms exactly like libfranka’s poll(kTimeout, SELECT_READ).
Error texts are libfranka’s, verbatim.
Sourcepub fn layout(&self) -> HeaderLayout
pub fn layout(&self) -> HeaderLayout
The header layout this session frames with.
Sourcepub fn local_addr(&self) -> FrankaResult<SocketAddr>
pub fn local_addr(&self) -> FrankaResult<SocketAddr>
Local address of the command socket (used by tests).
Sourcepub fn send_request(&self, command: u32, payload: &[u8]) -> FrankaResult<u32>
pub fn send_request(&self, command: u32, payload: &[u8]) -> FrankaResult<u32>
Sends a request and returns its command_id.
The header’s size is header_len + payload.len(), i.e. it counts the header, exactly
like CommandHeader::size in libfranka. Command ids start at 0 and increase by one per
request (Network::command_id_).
Sourcepub fn blocking_receive_response(
&self,
command_id: u32,
) -> FrankaResult<Vec<u8>>
pub fn blocking_receive_response( &self, command_id: u32, ) -> FrankaResult<Vec<u8>>
Blocks until the response with command_id has been received and returns the whole
message, header included.
Port of Network::tcpBlockingReceiveResponse: lock, read for at most 10 ms, look the id
up, unlock, std::this_thread::yield(), repeat.
Sourcepub fn try_receive_response(
&self,
command_id: u32,
) -> FrankaResult<Option<Vec<u8>>>
pub fn try_receive_response( &self, command_id: u32, ) -> FrankaResult<Option<Vec<u8>>>
Tries to claim the response with command_id without blocking.
Port of Network::tcpReceiveResponse: a try_lock that gives up immediately if another
thread holds the socket, then a zero-timeout read. Returns Ok(None) when the response
has not arrived yet.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Whether the socket is free of pending errors (Network::isTcpSocketAlive).
Sourcepub fn throw_if_connection_closed(&self) -> FrankaResult<()>
pub fn throw_if_connection_closed(&self) -> FrankaResult<()>
Returns Err(Network("libfranka: server closed connection")) when the peer performed an
orderly shutdown (Network::tcpThrowIfConnectionClosed).
Like libfranka this is a no-op when another thread holds the socket lock, and it peeks rather than consuming, so a queued response is not lost.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shuts the command socket down in both directions, best effort.
libfranka calls tcp_socket_.shutdown() whenever a UDP receive fails
(network.h:146) so that the next TCP operation fails fast instead of waiting on a
connection the robot has already given up on; crate::network::Network does the same.
Trait Implementations§
Source§impl Debug for TcpSession
impl Debug for TcpSession
Auto Trait Implementations§
impl !Freeze for TcpSession
impl RefUnwindSafe for TcpSession
impl Send for TcpSession
impl Sync for TcpSession
impl Unpin for TcpSession
impl UnsafeUnpin for TcpSession
impl UnwindSafe for TcpSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.