Documentation ¶
Index ¶
- Constants
- Variables
- type BufferedConnection
- func (c *BufferedConnection) BytesRead() uint64
- func (c *BufferedConnection) BytesWritten() uint64
- func (c *BufferedConnection) Close() (err error)
- func (c *BufferedConnection) LocalAddr() net.Addr
- func (c *BufferedConnection) Read() error
- func (c *BufferedConnection) RemoteAddr() net.Addr
- func (c *BufferedConnection) Write(msg []byte) (int, error)
- type BufferedConnectionEvents
Constants ¶
const ( // IOTimeout specifies the timeout for sending and receiving multi packet messages. IOTimeout = 4 * time.Second )
Variables ¶
var ( ErrInvalidHeader = errors.New("invalid message header") ErrInsufficientBuffer = errors.New("insufficient buffer") )
Errors returned by the BufferedConnection.
Functions ¶
This section is empty.
Types ¶
type BufferedConnection ¶
type BufferedConnection struct { Events BufferedConnectionEvents // contains filtered or unexported fields }
BufferedConnection is a wrapper for sending and reading messages with a buffer.
func NewBufferedConnection ¶
func NewBufferedConnection(conn net.Conn, maxMessageSize int) *BufferedConnection
NewBufferedConnection creates a new BufferedConnection from a net.Conn.
func (*BufferedConnection) BytesRead ¶
func (c *BufferedConnection) BytesRead() uint64
BytesRead returns the total number of bytes read.
func (*BufferedConnection) BytesWritten ¶
func (c *BufferedConnection) BytesWritten() uint64
BytesWritten returns the total number of bytes written.
func (*BufferedConnection) Close ¶
func (c *BufferedConnection) Close() (err error)
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*BufferedConnection) LocalAddr ¶
func (c *BufferedConnection) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*BufferedConnection) Read ¶
func (c *BufferedConnection) Read() error
Read starts reading on the connection, it only returns when an error occurred or when Close has been called. If a complete message has been received and ReceiveMessage event is triggered with its complete payload. If read leads to an error, the loop will be stopped and that error returned.
func (*BufferedConnection) RemoteAddr ¶
func (c *BufferedConnection) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*BufferedConnection) Write ¶
func (c *BufferedConnection) Write(msg []byte) (int, error)
Write sends a stream of bytes as messages. Each array of bytes you pass in will be pre-pended with it's size. If the connection isn't open you will receive an error. If not all bytes can be written, Write will keep trying until the full message is delivered, or the connection is broken.