serverutil

package module
v0.0.0-...-7847555 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: CC0-1.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK         = ResponseCode(iota) // Everything went OK.
	Error                           // An error occurred performing the task.
	Goodbye                         // The server is going away.
	Processing                      // The server is still processing a task.
)

The valid response codes.

View Source
const (
	DefaultWait      = 10 * time.Minute
	DefaultRead      = 5 * time.Minute
	DefaultWrite     = 5 * time.Second
	DefaultKeepAlive = 3 * time.Minute
)

The default client timeout durations.

View Source
const (
	KeepAliveTask = TaskCode(ReservedTaskCode + iota)
)

The task codes used internally.

View Source
const ReservedTaskCode = TaskCode(250)

ReservedTaskCode is the first task code reserved for internal use. All task codes >= ReservedTaskCode are reserved for internal use.

Variables

View Source
var (
	ErrConnectionClosed          = errors.New("Connection closed")                                          // ErrConnectionClosed indicates that the client's connection to the server has been closed.
	ErrConnectionClosing         = errors.New("Not accepting new tasks (connection is scheduled to close)") // ErrConnectionClosing indicates that a future disconnection has been schedules, so the client is no-longer accepting new tasks.
	ErrTimeoutWaitingForResponse = errors.New("Timeout whilst waiting for response")                        // ErrTimeoutWaitingForResponse indicates that the client timed-out whilst waiting for a response from the server.
)

Client errors.

Functions

This section is empty.

Types

type BaseServer

type BaseServer interface {
	log.Logable
	metrics.Metricsable
	Clients() []Client          // Clients returns all client connections currently being handled by this server. The returned slice is sorted by increasing timestamp.
	NumClients() int            // NumClients returns the number of client connections currently being handled by this server.
	Disconnect(d time.Duration) // Disconnect calls the Disconnect method with duration d for each client currently being handled by this server.
	Wait()                      // Wait blocks until no client connections are being handled by this server.
}

BaseServer is the base server interface.

type Client

type Client interface {
	log.Logable
	io.Closer
	netutil.Addrer
	Timestamp() time.Time       // Timestamp returns the connection timestamp for the client.
	Disconnect(d time.Duration) // Disconnect begins a graceful disconnection, preventing new tasks from running, and scheduling a future Close on the connection after duration d has elapsed. Note that there is no way to cancel a graceful disconnection once started. If Disconnect is called again, then the final Close will be performed after the shortest of the two durations has expired. This is a non-blocking method.
	TaskCodes() []TaskCode      // TaskCodes returns a slice of all assigned tasks codes. When relevant, the task codes are sorted in assigned order, from oldest (at index 0) to most recent.
}

Client is the common interface satisfied by a client.

type ErrorCode

type ErrorCode uint8

ErrorCode is a one-byte value indicating the error from the server.

func (ErrorCode) String

func (e ErrorCode) String() string

String returns a string description of the error code.

type ErrorCoder

type ErrorCoder interface {
	ErrorCode() ErrorCode // ErrorCode returns the error code.
}

ErrorCoder is the interface satisfied by an object with an ErrorCode method.

type HandleConnectioner

type HandleConnectioner interface {
	HandleConnection(ctx context.Context, conn net.Conn, e binary.ByteOrder, args ...interface{}) error // HandleConnection handles tasks from the given connection conn using the given byte order e. Use the given context to trigger a graceful disconnection. The connection will be closed on return. The given args will be passed to the task functions.
}

HandleConnectioner is the common interface satisfied by the HandleConnection method.

type ResponseCode

type ResponseCode uint8

ResponseCode is a one-byte value indicating the response from the server.

func (ResponseCode) IsValid

func (r ResponseCode) IsValid() bool

IsValid returns true iff the response code is valid.

func (ResponseCode) String

func (r ResponseCode) String() string

String returns a string description of the response code.

type TaskCode

type TaskCode uint8

TaskCode is a one-byte value indicating the task the client is requesting.

func (TaskCode) String

func (t TaskCode) String() string

String returns a string description of the task code.

type Timeout

type Timeout struct {
	Wait      time.Duration // Waiting for a response.
	Read      time.Duration // Reading task data.
	Write     time.Duration // Writing task data.
	KeepAlive time.Duration // The keep-alive ping interval (0 means no ping).
}

Timeout describes the various client timeout durations when communicating with a server.

func DefaultTimeout

func DefaultTimeout() *Timeout

DefaultTimeout returns a copy of the default client timeout settings.

Directories

Path Synopsis
asyncserver
Package asyncserver provides the framework for an async server.
Package asyncserver provides the framework for an async server.
internal
Package serial provides a framework for synchronous client-server communication.
Package serial provides a framework for synchronous client-server communication.
serialclient
Package serialclient provides a client for synchronous client-server communication.
Package serialclient provides a client for synchronous client-server communication.
serialserver
Package serialserver provides a server for synchronous client-server communication.
Package serialserver provides a server for synchronous client-server communication.

Jump to

Keyboard shortcuts

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