pub struct Acceptor<A: Application = NoOpApplication> { /* private fields */ }Expand description
Server-side FIX engine.
Owns the session configuration and the Application callbacks. Each
accepted connection (Acceptor::accept / Acceptor::serve) establishes
one live session and returns a Connection handle for it. Cloning the
application is cheap, so an Acceptor is typically wrapped in an Arc
and shared across the tasks serving each connection.
The configuration is stated from the acceptor’s point of view: its
sender_comp_id is the acceptor’s own CompID and its target_comp_id is
the initiator it expects — the reverse of what the peer stamps on the wire,
which is exactly what the inbound-identity check validates against.
Implementations§
Source§impl<A: Application + 'static> Acceptor<A>
impl<A: Application + 'static> Acceptor<A>
Sourcepub fn new(config: SessionConfig, application: Arc<A>) -> Self
pub fn new(config: SessionConfig, application: Arc<A>) -> Self
Creates a new acceptor.
§Arguments
config- The session configuration (sender = this acceptor’s CompID, target = the initiator it expects)application- The application callback handler
Sourcepub fn with_initial_sequences(self, sender_seq: u64, target_seq: u64) -> Self
pub fn with_initial_sequences(self, sender_seq: u64, target_seq: u64) -> Self
Seeds each accepted session with initial sequence numbers, for
continuity with a previous session. Ignored when the inbound Logon
carries ResetSeqNumFlag (141) = Y, which resets both counters to 1.
§Arguments
sender_seq- Next outgoing sequence numbertarget_seq- Next expected incoming sequence number
Sourcepub fn with_outbound_capacity(self, capacity: usize) -> Self
pub fn with_outbound_capacity(self, capacity: usize) -> Self
Sets the capacity of each session’s outbound message queue (default 1024).
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Returns the session configuration.
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Returns the session identifier.
Sourcepub async fn accept(
&self,
listener: &TcpListener,
) -> Result<Connection, EngineError>
pub async fn accept( &self, listener: &TcpListener, ) -> Result<Connection, EngineError>
Accepts the next inbound connection on listener and establishes a
session on it.
This is a thin convenience over Acceptor::serve: it awaits one TCP
connection and hands the stream to the handshake. For concurrent
handshakes, run the accept loop yourself and spawn a serve per
connection (see the module example).
§Arguments
listener- A boundTcpListener
§Errors
Returns EngineError::Io if the TCP accept fails, or any error
Acceptor::serve can produce.
Sourcepub async fn serve(&self, stream: TcpStream) -> Result<Connection, EngineError>
pub async fn serve(&self, stream: TcpStream) -> Result<Connection, EngineError>
Establishes a session on an already-accepted TcpStream, completing
the acceptor-side Logon handshake and spawning the session reactor.
On success the session is Active: on_logon has fired and the returned
Connection can send application messages. The reactor owns the
socket and handles heartbeats, TestRequests, sequence validation, and
admin replies until the session closes.
§Arguments
stream- An accepted TCP connection from the counterparty
§Errors
Returns an EngineError if framing or the Logon handshake fails. That
includes EngineError::LogonTimeout when no Logon arrives within
SessionConfig::logon_timeout, EngineError::UnexpectedMessage when
the first frame is not a Logon, EngineError::IdentityMismatch when
the Logon’s CompIDs do not match the configured counterparty, and
EngineError::SequenceExhausted when a sequence counter has reached
u64::MAX. EngineError::LogonRejected covers the acceptor-side
refusals: the from_admin authentication hook, a BeginString (8) that
does not match this session’s version, an unsupported EncryptMethod
(98), a HeartBtInt (108) that is missing, non-numeric, or out of range,
and a second concurrent Logon for a session already established. A
BeginString this engine cannot frame at all is refused up front with
EngineError::UnsupportedVersion.