conn

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionClosed = errors.New("connection closed")
)
View Source
var ErrMessageSizeLimit = errors.New("message size limits reached")

ErrMessageSizeLimit is returned after message length is over server max message size directive.

View Source
var ErrReaderAlreadyClosed = errors.New("reader already closed")

ErrReaderAlreadyClosed is returned when client code attempts to read from previously closed connection.

View Source
var ErrReaderClosedByContext = errors.New("reader closed by context")

ErrReaderClosedByContext is returned after connection was closed by context cancelFunc during reading operation.

View Source
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 NewConnection(address net.Addr, conn net.Conn, terminator byte) (*Connection, error)

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

func (c *Connection) ReadWithContext(buffer, maxSize int, terminator byte) ([]byte, int, error)

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.

func (*Connection) Stats

func (c *Connection) Stats() (int, int, int)

Stats returns Connection stats.

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) Bytes

func (m *Message) Bytes() []byte

Bytes returns message bytes.

func (*Message) Conn

func (m *Message) Conn() *Connection

Conn returns pointer to connection in which message was received.

func (*Message) Length

func (m *Message) Length() int

Length returns message bytes length.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL