Documentation ¶
Index ¶
- Constants
- Variables
- type Acceptor
- type AcceptorHandler
- type AcceptorHandlerFactory
- type Conn
- type DefaultHandler
- func (h *DefaultHandler) CloseErrorChan()
- func (h *DefaultHandler) Context() context.Context
- func (h *DefaultHandler) HandleIncoming(msgType string, handle IncomingHandlerFunc) (id int64)
- func (h *DefaultHandler) HandleOutgoing(msgType string, handle OutgoingHandlerFunc) (id int64)
- func (h *DefaultHandler) OnConnect(handlerFunc utils.EventHandlerFunc)
- func (h *DefaultHandler) OnDisconnect(handlerFunc utils.EventHandlerFunc)
- func (h *DefaultHandler) OnStopped(handlerFunc utils.EventHandlerFunc)
- func (h *DefaultHandler) Outgoing() <-chan []byte
- func (h *DefaultHandler) RemoveIncomingHandler(msgType string, id int64) (err error)
- func (h *DefaultHandler) RemoveOutgoingHandler(msgType string, id int64) (err error)
- func (h *DefaultHandler) Run() (err error)
- func (h *DefaultHandler) Send(message SendingMessage) error
- func (h *DefaultHandler) SendBatch(messages []SendingMessage) error
- func (h *DefaultHandler) SendRaw(data []byte) error
- func (h *DefaultHandler) ServeIncoming(msg []byte)
- func (h *DefaultHandler) Stop()
- func (h *DefaultHandler) StopWithError(err error)
- type HandlerFactory
- type HandlerPool
- type IncomingHandlerFunc
- type IncomingHandlerPool
- type Initiator
- type InitiatorHandler
- type OutgoingHandlerFunc
- type OutgoingHandlerPool
- type Sender
- type SendingMessage
Constants ¶
const AllMsgTypes = "ALL"
Variables ¶
var ( ErrNotEnoughMessages = errors.New("not enough messages in the storage") ErrInvalidBoundaries = errors.New("invalid boundaries") ErrInvalidSequence = errors.New("unexpected sequence index") )
var ErrConnClosed = fmt.Errorf("the reader is closed")
ErrConnClosed handles connection errors.
var ErrHandleNotFound = errors.New("handler not found")
ErrHandleNotFound is returned when a required handler is not found.
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor struct {
// contains filtered or unexported fields
}
Acceptor is a server-side service used for handling client connections.
func NewAcceptor ¶
func NewAcceptor(listener net.Listener, factory HandlerFactory, writeTimeout time.Duration, handleNewClient func(handler AcceptorHandler)) *Acceptor
NewAcceptor is used to create a new Acceptor instance.
func (*Acceptor) Close ¶
func (s *Acceptor) Close()
Close is called to cancel the Acceptor context and close a connection.
func (*Acceptor) ListenAndServe ¶
ListenAndServe is used for listening and maintaining connections. It verifies and accepts connection requests from new clients.
type AcceptorHandler ¶
type AcceptorHandler interface { ServeIncoming(msg []byte) Outgoing() <-chan []byte Run() error Stop() StopWithError(err error) CloseErrorChan() Send(message SendingMessage) error SendBatch(messages []SendingMessage) error SendRaw(data []byte) error RemoveIncomingHandler(msgType string, id int64) (err error) RemoveOutgoingHandler(msgType string, id int64) (err error) HandleIncoming(msgType string, handle IncomingHandlerFunc) (id int64) HandleOutgoing(msgType string, handle OutgoingHandlerFunc) (id int64) OnDisconnect(handlerFunc utils.EventHandlerFunc) OnConnect(handlerFunc utils.EventHandlerFunc) OnStopped(handlerFunc utils.EventHandlerFunc) Context() context.Context }
AcceptorHandler is a set of methods providing basic functionality to the Acceptor.
type AcceptorHandlerFactory ¶
type AcceptorHandlerFactory struct {
// contains filtered or unexported fields
}
AcceptorHandlerFactory is a handler factory for an Acceptor object.
func NewAcceptorHandlerFactory ¶
func NewAcceptorHandlerFactory(msgTypeTag string, bufferSize int) *AcceptorHandlerFactory
NewAcceptorHandlerFactory returns a new AcceptorHandlerFactory instance.
func (*AcceptorHandlerFactory) MakeHandler ¶
func (h *AcceptorHandlerFactory) MakeHandler(ctx context.Context) AcceptorHandler
MakeHandler creates a new AcceptorHandler instance.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a net.Conn wrapper that is used for handling split messages.
func NewConn ¶
func NewConn(ctx context.Context, conn net.Conn, msgBuffSize int, writeDeadline time.Duration) *Conn
NewConn is called to create a new connection.
func (*Conn) Close ¶
func (c *Conn) Close()
Close is called to cancel a connection context and close a connection.
type DefaultHandler ¶
type DefaultHandler struct {
// contains filtered or unexported fields
}
DefaultHandler is a standard handler for the Acceptor and Initiator objects.
func NewAcceptorHandler ¶
func NewAcceptorHandler(ctx context.Context, msgTypeTag string, bufferSize int) *DefaultHandler
NewAcceptorHandler creates a handler for an Acceptor object.
func NewInitiatorHandler ¶
func NewInitiatorHandler(ctx context.Context, msgTypeTag string, bufferSize int) *DefaultHandler
NewInitiatorHandler creates a handler for the Initiator object.
func (*DefaultHandler) CloseErrorChan ¶ added in v1.14.5
func (h *DefaultHandler) CloseErrorChan()
CloseErrorChan is a function that closes the handler's error chan.
func (*DefaultHandler) Context ¶
func (h *DefaultHandler) Context() context.Context
func (*DefaultHandler) HandleIncoming ¶
func (h *DefaultHandler) HandleIncoming(msgType string, handle IncomingHandlerFunc) (id int64)
HandleIncoming subscribes a handler function to incoming messages with a specific msgType. To subscribe to all messages, specify the AllMsgTypes constant for the msgType field (such messages will have a higher priority than the ones assigned to specific handlers).
func (*DefaultHandler) HandleOutgoing ¶
func (h *DefaultHandler) HandleOutgoing(msgType string, handle OutgoingHandlerFunc) (id int64)
HandleOutgoing subscribes a handler function to outgoing messages with a specific msgType (this may be required for modifying messages before sending). To subscribe to all messages, specify the AllMsgTypes constant for the msgType field (such messages will have a higher priority than the ones assigned to specific handlers).
func (*DefaultHandler) OnConnect ¶
func (h *DefaultHandler) OnConnect(handlerFunc utils.EventHandlerFunc)
OnConnect handles connection events.
func (*DefaultHandler) OnDisconnect ¶
func (h *DefaultHandler) OnDisconnect(handlerFunc utils.EventHandlerFunc)
OnDisconnect handles disconnection events.
func (*DefaultHandler) OnStopped ¶
func (h *DefaultHandler) OnStopped(handlerFunc utils.EventHandlerFunc)
OnStopped handles session termination events.
func (*DefaultHandler) Outgoing ¶
func (h *DefaultHandler) Outgoing() <-chan []byte
Outgoing is a service method that provides an outgoing channel to the server or client connection manager.
func (*DefaultHandler) RemoveIncomingHandler ¶
func (h *DefaultHandler) RemoveIncomingHandler(msgType string, id int64) (err error)
RemoveIncomingHandler removes an existing handler for incoming messages.
func (*DefaultHandler) RemoveOutgoingHandler ¶
func (h *DefaultHandler) RemoveOutgoingHandler(msgType string, id int64) (err error)
RemoveOutgoingHandler removes an existing handler for outgoing messages.
func (*DefaultHandler) Run ¶
func (h *DefaultHandler) Run() (err error)
Run is a function that is used for listening and processing messages.
func (*DefaultHandler) Send ¶
func (h *DefaultHandler) Send(message SendingMessage) error
Send is a function that sends a previously prepared message.
func (*DefaultHandler) SendBatch ¶ added in v1.11.0
func (h *DefaultHandler) SendBatch(messages []SendingMessage) error
SendBatch is a function that sends previously prepared messages.
func (*DefaultHandler) SendRaw ¶
func (h *DefaultHandler) SendRaw(data []byte) error
SendRaw sends a message in the byte array format without involving any additional handlers.
func (*DefaultHandler) ServeIncoming ¶
func (h *DefaultHandler) ServeIncoming(msg []byte)
ServeIncoming is an internal method for handling incoming messages.
func (*DefaultHandler) Stop ¶
func (h *DefaultHandler) Stop()
Stop is a function that enables graceful termination of a session.
func (*DefaultHandler) StopWithError ¶
func (h *DefaultHandler) StopWithError(err error)
StopWithError is a function that enables graceful termination of a session with throwing an error.
type HandlerFactory ¶
type HandlerFactory interface {
MakeHandler(ctx context.Context) AcceptorHandler
}
HandlerFactory creates handlers for the Acceptor.
type HandlerPool ¶
type HandlerPool struct {
// contains filtered or unexported fields
}
HandlerPool is used for managing the pool of message handlers.
func NewHandlerPool ¶
func NewHandlerPool() *HandlerPool
NewHandlerPool creates a new HandlerPool instance.
func (*HandlerPool) Add ¶
func (p *HandlerPool) Add(msgType string, handle OutgoingHandlerFunc) int64
Add is used to add a new message handler for the specified message type. The function returns the ID of a message for which a handler was added.
type IncomingHandlerFunc ¶
IncomingHandlerFunc is used for handling incoming messages.
type IncomingHandlerPool ¶
type IncomingHandlerPool struct {
*HandlerPool
}
IncomingHandlerPool is used to manage the pool of incoming messages stored in the form of byte arrays.
func NewIncomingHandlerPool ¶
func NewIncomingHandlerPool() IncomingHandlerPool
NewIncomingHandlerPool creates a new HandlerPool instance.
func (*IncomingHandlerPool) Add ¶
func (p *IncomingHandlerPool) Add(msgType string, handle IncomingHandlerFunc) int64
Add is used to add a new message handler for the specified message type. The function returns the ID of a message for which a handler was added.
func (IncomingHandlerPool) Range ¶
func (p IncomingHandlerPool) Range(msgType string, f func(IncomingHandlerFunc) bool)
Range is used for traversal through handlers. The traversal stops if any handler returns false.
type Initiator ¶
type Initiator struct {
// contains filtered or unexported fields
}
Initiator provides the client-side service functionality.
func NewInitiator ¶
func NewInitiator(conn net.Conn, handler InitiatorHandler, bufSize int, writeDeadline time.Duration) *Initiator
NewInitiator creates a new Initiator instance.
func (*Initiator) Close ¶
func (c *Initiator) Close()
Close is used to cancel the specified Initiator context.
func (*Initiator) Send ¶
func (c *Initiator) Send(message SendingMessage) error
Send is used to send a FIX message.
type InitiatorHandler ¶
type InitiatorHandler interface { ServeIncoming(msg []byte) Outgoing() <-chan []byte Run() error StopWithError(err error) CloseErrorChan() Send(message SendingMessage) error Context() context.Context Stop() }
InitiatorHandler is an interface implementing basic methods required for handling the Initiator object.
type OutgoingHandlerFunc ¶
type OutgoingHandlerFunc func(msg SendingMessage) bool
OutgoingHandlerFunc is used for handling outgoing messages.
type OutgoingHandlerPool ¶
type OutgoingHandlerPool struct {
*HandlerPool
}
OutgoingHandlerPool is used to manage the pool of outgoing messages stored as structures.
func NewOutgoingHandlerPool ¶
func NewOutgoingHandlerPool() OutgoingHandlerPool
NewOutgoingHandlerPool creates a new OutgoingHandlerPool instance.
func (OutgoingHandlerPool) Range ¶
func (p OutgoingHandlerPool) Range(msgType string, f func(OutgoingHandlerFunc) bool) (res bool)
Range is used for traversal through handlers. The traversal stops if any handler returns false.
type Sender ¶
type Sender interface {
Send(message SendingMessage) error
}
Sender is an interface implemented by any structure that can issue a SendingMessage.
type SendingMessage ¶
type SendingMessage interface { HeaderBuilder() messages.HeaderBuilder MsgType() string ToBytes() ([]byte, error) }
SendingMessage provides a basic method for sending messages.