FixAlchemy.Server.Session (FIXAlchemy v0.2.0)

View Source

One connection an acceptor has taken, from its Logon to its disconnect.

The process is started by FixAlchemy.Server with a socket that has already been accepted, and is anonymous until the counterparty identifies itself. Its first inbound message must be a Logon; FixAlchemy.Server.Logon matches it to a configured session, and only then does the process register itself in FixAlchemy.Registry under {connection_id, session_name} and start running the session protocol through a FixAlchemy.Engine.

A Logon that matches nothing, fails authentication, or names a session that is already connected is answered with a Logout carrying the reason, and the connection is closed.

Unlike an initiator, an accepted session never reconnects. When the socket closes the process ends, and the counterparty dialing back in produces a new one.

Sequence numbers

A Logon with ResetSeqNumFlag (141=Y) resets both directions to 1. Otherwise the session adopts the Logon's MsgSeqNum as the number it has received and expects the next inbound message to follow it. Outbound numbering starts at 1 on every connection. Resuming numbering across connections requires a FixAlchemy.MessageStore and a sequence that outlive the process.

Summary

Functions

Returns a specification to start this module under a supervisor.

Send a message on this session.

The {connection_id, session_name} this session registered under, once established.

Take ownership of the socket handed over by the acceptor.

Functions

child_spec(init_arg)

@spec child_spec(term()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

send_message(session, arg)

@spec send_message(
  GenServer.server(),
  {binary(), list()}
) :: :ok

Send a message on this session.

session_key(session)

@spec session_key(GenServer.server()) :: {binary() | nil, atom() | binary()} | nil

The {connection_id, session_name} this session registered under, once established.

start_link(arg)

subscribe(session, subscriber, type, value \\ :all, opts \\ [])

@spec subscribe(GenServer.server(), pid(), binary(), binary() | :all, keyword()) ::
  :ok

Subscribe subscriber to a message type; see FixAlchemy.Dispatch.subscribe/5.

take_socket(session)

@spec take_socket(pid()) :: :ok

Take ownership of the socket handed over by the acceptor.

unsubscribe(session, subscriber)

@spec unsubscribe(GenServer.server(), pid()) :: :ok