Documentation ¶
Index ¶
- Variables
- type Connection
- func (c *Connection) AddErrors(count int)
- func (c *Connection) AddRecBytes(count int)
- func (c *Connection) AddSentBytes(count int)
- func (c *Connection) Address() net.Addr
- func (c *Connection) CancelCtx()
- func (c *Connection) Close() error
- func (c *Connection) Closed() bool
- func (c *Connection) ClosedAt() time.Time
- func (c *Connection) ConnectedAt() time.Time
- func (c *Connection) DropOldStats()
- func (c *Connection) Errors() int
- func (c *Connection) GetMessage() (*Message, error)
- func (c *Connection) ID() string
- func (c *Connection) LastAct() time.Time
- func (c *Connection) MessageChanWrite() chan<- *Message
- func (c *Connection) Next() bool
- func (c *Connection) Online() time.Duration
- func (c *Connection) ReadWithContext(buffer, maxSize int, terminator byte) ([]byte, int, error)
- func (c *Connection) Received() int
- func (c *Connection) SendByte(bytesToSend []byte) (int, error)
- func (c *Connection) SendString(s string) (int, error)
- func (c *Connection) Sent() int
- func (c *Connection) SetLastAct()
- func (c *Connection) SetMessageTerminator(t byte)
- func (c *Connection) Stats() (int, int, int)
- type Message
Constants ¶
This section is empty.
Variables ¶
var (
ErrConnectionClosed = errors.New("connection closed")
)
var ErrMessageSizeLimit = errors.New("message size limits reached")
ErrMessageSizeLimit is returned after message length is over server max message size directive.
var ErrReaderAlreadyClosed = errors.New("reader already closed")
ErrReaderAlreadyClosed is returned when client code attempts to read from previously closed connection.
var ErrReaderClosedByContext = errors.New("reader closed by context")
ErrReaderClosedByContext is returned after connection was closed by context cancelFunc during reading operation.
var ErrStreamClosed = errors.New("stream closed")
ErrStreamClosed is returned after io.EOF is appeared in TLS stream.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents incoming client connection.
func NewConnection ¶
func (*Connection) AddErrors ¶ added in v1.3.0
func (c *Connection) AddErrors(count int)
AddErrors adds number to count of total errors.
func (*Connection) AddRecBytes ¶ added in v1.3.0
func (c *Connection) AddRecBytes(count int)
AddRecBytes adds number to count of total received bytes.
func (*Connection) AddSentBytes ¶ added in v1.3.0
func (c *Connection) AddSentBytes(count int)
AddSentBytes adds number to count of total sent bytes.
func (*Connection) Address ¶
func (c *Connection) Address() net.Addr
Address returns remote address of client.
func (*Connection) CancelCtx ¶ added in v1.3.0
func (c *Connection) CancelCtx()
CancelCtx cancels the connection context.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close forsibly closes the connection. Active reader may still return bytes read between message start and connection close.
IMPORTANT: 'close_notify' exchange is built on lower logic levels, but attempt to read/write with closed connection is still possible and will return error. If there is a risk that your app may do so, then you may need to use some flags to mark closed connections and avoid possible errors.
func (*Connection) Closed ¶
func (c *Connection) Closed() bool
Closed returns true if the connection was closed.
func (*Connection) ClosedAt ¶
func (c *Connection) ClosedAt() time.Time
ConnectedAt returns time the connection was init.
func (*Connection) ConnectedAt ¶
func (c *Connection) ConnectedAt() time.Time
ConnectedAt returns time the connection was init.
func (*Connection) DropOldStats ¶
func (c *Connection) DropOldStats()
DropOldStats sets bytes received, sent and error count to zero.
func (*Connection) Errors ¶ added in v1.3.0
func (c *Connection) Errors() int
Sent returns total count of bytes sent into connection.
func (*Connection) GetMessage ¶ added in v1.4.0
func (c *Connection) GetMessage() (*Message, error)
GetMessage returns new message or error. Code will be locked until new message appears or connection is closed. The only possible error is ErrConnectionClosed.
func (*Connection) ID ¶ added in v1.3.0
func (c *Connection) ID() string
ID returns connection ID in pool.
func (*Connection) LastAct ¶
func (c *Connection) LastAct() time.Time
ConnectedAt returns time the connection was init.
func (*Connection) MessageChanWrite ¶ added in v1.3.0
func (c *Connection) MessageChanWrite() chan<- *Message
MessageChanWrite returns connection's message channel to write only.
func (*Connection) Next ¶ added in v1.4.0
func (c *Connection) Next() bool
Next returns true if connection is open and able to receive new messages.
func (*Connection) Online ¶
func (c *Connection) Online() time.Duration
Online returns duration of the connection.
func (*Connection) ReadWithContext ¶
readWithContext reads bytes from connection until Terminator / error occurs or context is done. It can be used to read with timeout or any other way to break reader. Usual readers are vulnerable to routine-leaks, so this way is more confident.
IMPORTANT: if EOF or context deadline appear, readWithContext will mark connection as 'closed'. Other errors should be treated manually by external code. In all cases method will return last bytes read.
func (*Connection) Received ¶ added in v1.3.0
func (c *Connection) Received() int
Received returns total count of bytes received from connection.
func (*Connection) SendByte ¶
func (c *Connection) SendByte(bytesToSend []byte) (int, error)
SendByte sends bytes to remote by writing directrly into connection interface.
func (*Connection) SendString ¶
func (c *Connection) SendString(s string) (int, error)
SendString converts s into byte slice and calls to SendByte.
func (*Connection) Sent ¶ added in v1.3.0
func (c *Connection) Sent() int
Sent returns total count of bytes sent into connection.
func (*Connection) SetLastAct ¶ added in v1.3.0
func (c *Connection) SetLastAct()
func (*Connection) SetMessageTerminator ¶
func (c *Connection) SetMessageTerminator(t byte)
SetMessageTerminator sets byte that will be used as message terminator.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represents incoming message with its bytes and pointer to associated connection.
func NewMessage ¶
func NewMessage(conn *Connection, length int, bytes []byte) *Message
func (*Message) Conn ¶
func (m *Message) Conn() *Connection
Conn returns pointer to connection in which message was received.