tcpserver

package
v1.1.42 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCancelled = errors.New("cancelled")
)

Functions

This section is empty.

Types

type ConnectionHandler

type ConnectionHandler func(ctx context.Context, conn net.Conn, userData interface{})

ConnectionHandler is the signature of the handler function Returning an error in the handler exits the ListerAndServe function with that error

type ConnectionIntf added in v1.1.27

type ConnectionIntf interface {
	OnConnect(ctx context.Context, connection ConnectionParams) bool
	OnDisconnect(ctx context.Context, connection ConnectionParams)
	HandleConnection(ctx context.Context, connection ConnectionParams) error
}

type ConnectionParams added in v1.1.27

type ConnectionParams struct {
	Conn         net.Conn
	ServerConfig *ServerConfig
}

type Server added in v1.1.27

type Server struct {
	task.Runnable
	// contains filtered or unexported fields
}

Server represents a tcp server

func NewServer added in v1.1.27

func NewServer(config ServerConfig) *Server

func (Server) Run added in v1.1.27

func (s Server) Run(ctx context.Context, params ...interface{}) error

type ServerConfig added in v1.1.27

type ServerConfig struct {
	ListenAddress string // "0.0.0.0"
	ListenPort    int    // 8080
	TlsConfig     *tls.Config
	Logger        *logrus.Entry
	UserData      interface{} // any datas, passed to each connection, must be thread safe
	Connection    ConnectionIntf
}

ServerConfig holds the server configuration parameters for a Server

type TCPServer

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

TCPServer holds the data for our TCP Server

func (*TCPServer) GetNbAccepted

func (tcpServer *TCPServer) GetNbAccepted() int64

GetNbAccepted returns the number of connections accepted

func (*TCPServer) GetNbGoroutines

func (tcpServer *TCPServer) GetNbGoroutines() int64

GetNbGoroutines returns the number of goroutines currently handling connections

func (*TCPServer) ListerAndServe

func (tcpServer *TCPServer) ListerAndServe(ctx context.Context, address string, handler ConnectionHandler, tlsConfig *tls.Config, userData interface{}) error

ListerAndServe accepts incoming tcp connexions and calls the handler in a new goroutine

func (*TCPServer) Wait

func (tcpServer *TCPServer) Wait()

Wait waits until all the goroutines are finished

Directories

Path Synopsis
sample module

Jump to

Keyboard shortcuts

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