transport

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommandsTotal is total number of all requests broken down by command (get, put, etc.) and status.
	CommandsTotal = stats.NewInt64Counter()

	// ConnectionsTotal is total number of connections opened since the server started running.
	ConnectionsTotal = stats.NewInt64Counter()

	// CurrentConnections is current number of open connections.
	CurrentConnections = stats.NewInt64Gauge()

	// WrittenBytesTotal is total number of bytes sent by this server to network.
	WrittenBytesTotal = stats.NewInt64Counter()

	// ReadBytesTotal is total number of bytes read by this server from network.
	ReadBytesTotal = stats.NewInt64Counter()
)
View Source
var ErrConnPoolTimeout = errors.New("timeout exceeded")
View Source
var ErrInvalidMagic = errors.New("invalid magic")

ErrInvalidMagic means that an OBP message is read from the TCP socket but the magic number is not valid.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the client implementation for the internal TCP server. It maintains a connection pool and manages request-response cycle.

func NewClient

func NewClient(cc *config.Client) *Client

NewClient returns a new Client.

func (*Client) Close

func (c *Client) Close()

Close all the connections in the connection pool.

func (*Client) ClosePool

func (c *Client) ClosePool(addr string)

ClosePool closes the underlying connections in a pool, deletes from the pools map and frees resources.

func (*Client) CreateStream added in v0.3.0

func (c *Client) CreateStream(ctx context.Context, addr string, read chan<- protocol.EncodeDecoder, write <-chan protocol.EncodeDecoder) error

CreateStream creates a new Stream connection which provides a bidirectional communication channel between Olric nodes and clients.

func (*Client) RequestTo

func (c *Client) RequestTo(addr string, req protocol.EncodeDecoder) (protocol.EncodeDecoder, error)

RequestTo initiates a request-response cycle to given host.

type ConnWithTimeout added in v0.3.0

type ConnWithTimeout struct {
	net.Conn
	// contains filtered or unexported fields
}

ConnWithTimeout denotes a composite type which can used to implement i/o timeout feature for TCP sockets.

func NewConnWithTimeout added in v0.3.0

func NewConnWithTimeout(conn net.Conn, readTimeout, writeTimeout time.Duration) *ConnWithTimeout

NewConnWithTimeout returns a new ConnWithTimeout instance.

func (*ConnWithTimeout) Close added in v0.3.0

func (c *ConnWithTimeout) Close() error

Close closes the connection.

func (*ConnWithTimeout) MarkUnusable added in v0.3.0

func (c *ConnWithTimeout) MarkUnusable()

MarkUnusable() marks the connection not usable any more, to let the pool close it instead of returning it to pool. Wrapper around connpool.PoolConn.MarkUnusable

func (*ConnWithTimeout) Read added in v0.3.0

func (c *ConnWithTimeout) Read(b []byte) (int, error)

Read reads data from the connection and calls net.SetReadDeadline before reading.

func (*ConnWithTimeout) UnsetDeadline added in v0.3.0

func (c *ConnWithTimeout) UnsetDeadline() error

UnsetDeadline unsets Read/Write deadline directive.

func (*ConnWithTimeout) Write added in v0.3.0

func (c *ConnWithTimeout) Write(b []byte) (int, error)

Write writes data to the connection and calls net.SetWriteDeadline before writing.

type Server

type Server struct {
	StartedCtx context.Context
	// contains filtered or unexported fields
}

Server implements a concurrent TCP server.

func NewServer

func NewServer(c *ServerConfig, l *flog.Logger) *Server

NewServer creates and returns a new Server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address addr.

func (*Server) SetDispatcher

func (s *Server) SetDispatcher(f func(w, r protocol.EncodeDecoder))

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).

type ServerConfig added in v0.3.0

type ServerConfig struct {
	BindAddr        string
	BindPort        int
	KeepAlivePeriod time.Duration
	// GracefulPeriod is useful to close busy connections when you want to shutdown the server.
	GracefulPeriod time.Duration
}

ServerConfig is a composite type to bundle configuration parameters.

Jump to

Keyboard shortcuts

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