buffconn

package
Version: v0.0.0-...-5dd4785 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0, BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IOTimeout specifies the timeout for sending and receiving multi packet messages.
	IOTimeout = 4 * time.Second
)

Variables

View Source
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.

type BufferedConnectionEvents

type BufferedConnectionEvents struct {
	ReceiveMessage *events.Event
	Close          *events.Event
}

BufferedConnectionEvents contains all the events that are triggered during the peer discovery.

Source Files

Jump to

Keyboard shortcuts

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