pub struct Connection { /* private fields */ }Expand description
Handle to a live FIX session.
Cloning is cheap; all clones refer to the same session. The session is
closed when the transport drops, the counterparty logs out, a heartbeat
timeout is detected, or Connection::logout completes.
§Dropping every handle logs out
The reactor stops when the last clone is dropped: it reads that as “nobody
can drive this session any more” and performs a graceful Logout rather than
leaving a task holding a socket forever. A consumer that wants the session
to outlive its handle must keep one alive — typically by holding it until
Connection::wait_closed returns.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Returns the session identifier.
Sourcepub async fn send(&self, message: OutboundMessage) -> Result<(), EngineError>
pub async fn send(&self, message: OutboundMessage) -> Result<(), EngineError>
Sends an application message on the session.
The engine stamps the standard header (including MsgSeqNum) and trailer; the message only needs body fields. It is checked here, before it is queued, so a message the session layer will not carry is refused to the caller rather than dropped later.
§Arguments
message- The application message to send
§Errors
EngineError::ReservedMsgTypefor an administrative MsgType. Logon, Logout, SequenceReset and the rest belong to the session state machine; one sent here would bypass the typestate and the engine’s phase tracking — a Logout sent this way never arms the logout timeout.EngineError::ReservedTagfor a body field that repeats a tag the engine stamps itself (seecrate::outbound::RESERVED_TAGS), which would put two occurrences of it in the frame.EngineError::InvalidFieldfor a value with no legal wire form.EngineError::Closedif the session is already closed.
§Accepted is not sent
Ok means the message was queued for the reactor, not that it reached
the counterparty. A message queued while a Logout is already pending is
dropped with a warning — the session is on its way out and a new
application message would arrive after the Logout the counterparty has
already seen. Use Connection::wait_closed to observe the end of the
session and next_sender_seq to observe progress.
Sourcepub async fn logout(&self) -> Result<(), EngineError>
pub async fn logout(&self) -> Result<(), EngineError>
Initiates a graceful logout.
A Logout message is sent to the counterparty; the session closes when
the Logout acknowledgement arrives or the logout timeout elapses.
Use Connection::wait_closed to observe completion.
§Errors
Returns EngineError::Closed if the session is already closed.
Sourcepub async fn wait_closed(&self)
pub async fn wait_closed(&self)
Waits until the session is closed.
Fires on transport drop, counterparty logout, heartbeat timeout, or completion of a locally initiated logout. Returns immediately if the session is already closed.
It fires after the inbound application messages already queued have
been through from_app and on_logout has run, so a handler still in
flight when the session ends delays this by however long it takes to
finish, up to an internal drain bound.
Sourcepub fn is_timed_out(&self) -> bool
pub fn is_timed_out(&self) -> bool
Returns true if the session has detected a heartbeat timeout (a TestRequest went unanswered for a full heartbeat interval).
Sourcepub fn next_sender_seq(&self) -> u64
pub fn next_sender_seq(&self) -> u64
Returns the next outgoing (sender) sequence number.
Sourcepub fn next_target_seq(&self) -> u64
pub fn next_target_seq(&self) -> u64
Returns the next expected incoming (target) sequence number.
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more