Documentation
ΒΆ
Index ΒΆ
- Variables
- func FD_ISSET(fd int, set *syscall.FdSet) bool
- func FD_SET(fd int, set *syscall.FdSet)
- func FD_ZERO(set *syscall.FdSet)
- type Config
- func (c *Config) Validate() error
- func (c *Config) WithBacklog(backlog int) *Config
- func (c *Config) WithBufferSizes(send, recv int) *Config
- func (c *Config) WithDeferAccept(duration time.Duration) *Config
- func (c *Config) WithLogger(logger Logger) *Config
- func (c *Config) WithMaxConns(maxConns int) *Config
- func (c *Config) WithPort(port int) *Config
- func (c *Config) WithReusePort(reusePort bool) *Config
- type Conn
- type Listener
- type ListenerStats
- type LogLevel
- type Logger
- type Server
- type SimpleLogger
- type TimeoutError
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( ErrConnClosed = errors.New("connection closed") ErrTimeout = errors.New("i/o timeout") )
var ( ErrListenerClosed = errors.New("listener closed") ErrMaxConnsReached = errors.New("max connections reached") ErrInvalidConfig = errors.New("invalid configuration") ErrAcceptTimeout = errors.New("accept timeout") )
var (
ErrServerClosed = errors.New("server closed")
)
Functions ΒΆ
Types ΒΆ
type Config ΒΆ
type Config struct {
Network string // Only "tcp" supported for now
Port int // Port to listen on
// Socket options
ReuseAddr bool // SO_REUSEADDR - allow binding to TIME_WAIT addresses
ReusePort bool // SO_REUSEPORT - allow multiple processes on same port
NoDelay bool // TCP_NODELAY - disable Nagle's algorithm
KeepAlive bool // SO_KEEPALIVE - enable TCP keepalive
QuickAck bool // TCP_QUICKACK - disable delayed ACKs
// Advanced TCP options
DeferAccept time.Duration // TCP_DEFER_ACCEPT - wait for data before accept
FastOpen bool // TCP_FASTOPEN - enable TFO for lower latency
// Buffer sizes (0 = use system defaults)
SendBuffer int // SO_SNDBUF - send buffer size
RecvBuffer int // SO_RCVBUF - receive buffer size
// Connection limits
Backlog int // Listen backlog (SYN queue size)
MaxConns int // Maximum concurrent connections (0 = unlimited)
// Timeouts
AcceptTimeout time.Duration // Timeout for accept operations
// Observability
Logger Logger // Optional structured logger
}
Config holds listener configuration
func DefaultConfig ΒΆ
func DefaultConfig() *Config
DefaultConfig returns a production-ready default configuration
func (*Config) WithBacklog ΒΆ added in v0.0.2
WithBacklog sets the listen backlog
func (*Config) WithBufferSizes ΒΆ added in v0.0.2
WithBufferSizes sets send and receive buffer sizes
func (*Config) WithDeferAccept ΒΆ added in v0.0.2
WithDeferAccept sets TCP_DEFER_ACCEPT timeout
func (*Config) WithLogger ΒΆ added in v0.0.2
WithLogger sets the logger
func (*Config) WithMaxConns ΒΆ added in v0.0.2
func (*Config) WithReusePort ΒΆ added in v0.0.2
type Conn ΒΆ
type Conn interface {
io.ReadWriteCloser
// LocalAddr returns the local network address
LocalAddr() string
// RemoteAddr returns the remote network address
RemoteAddr() string
// SetDeadline sets read and write deadlines
SetDeadline(t time.Time) error
// SetReadDeadline sets the read deadline
SetReadDeadline(t time.Time) error
// SetWriteDeadline sets the write deadline
SetWriteDeadline(t time.Time) error
// CloseRead closes the read side of the connection
CloseRead() error
// CloseWrite closes the write side of the connection
CloseWrite() error
}
Conn represents a network connection
type Listener ΒΆ
type Listener interface {
Accept() (Conn, error)
AcceptContext(ctx context.Context) (Conn, error)
Close() error
GracefulShutdown(timeout time.Duration) error
Addr() string
Stats() ListenerStats
}
Listener defines the interface for accepting connections
type ListenerStats ΒΆ added in v0.0.2
type ListenerStats struct {
ActiveConns int64
TotalAccepted int64
TotalRejected int64
TotalErrors int64
}
ListenerStats provides runtime statistics
type Logger ΒΆ added in v0.0.2
type Logger interface {
Debug(msg string, fields ...any)
Info(msg string, fields ...any)
Error(msg string, fields ...any)
}
Logger interface for structured logging
type Server ΒΆ
type Server struct {
// contains filtered or unexported fields
}
Server wraps a listener and handles connections with a handler function
func (*Server) Ready ΒΆ added in v0.0.2
func (s *Server) Ready() <-chan struct{}
Ready returns a channel that is closed when the server is ready to accept connections
func (*Server) Stats ΒΆ added in v0.0.2
func (s *Server) Stats() struct { ActiveConnections int64 ListenerStats ListenerStats }
Stats returns server statistics
type SimpleLogger ΒΆ added in v0.0.2
type SimpleLogger struct {
// contains filtered or unexported fields
}
SimpleLogger is a basic implementation of the Logger interface
func NewSimpleLogger ΒΆ added in v0.0.2
func NewSimpleLogger(level LogLevel) *SimpleLogger
NewSimpleLogger creates a new simple logger
func (*SimpleLogger) Debug ΒΆ added in v0.0.2
func (l *SimpleLogger) Debug(msg string, fields ...any)
func (*SimpleLogger) Error ΒΆ added in v0.0.2
func (l *SimpleLogger) Error(msg string, fields ...any)
func (*SimpleLogger) Info ΒΆ added in v0.0.2
func (l *SimpleLogger) Info(msg string, fields ...any)
type TimeoutError ΒΆ
type TimeoutError struct {
// contains filtered or unexported fields
}
TimeoutError represents a timeout error
func (*TimeoutError) Error ΒΆ
func (e *TimeoutError) Error() string
func (*TimeoutError) Temporary ΒΆ
func (e *TimeoutError) Temporary() bool
func (*TimeoutError) Timeout ΒΆ
func (e *TimeoutError) Timeout() bool
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
benchmark
command
|
|
|
echo-server
command
|
|
|
http-benchmark
command
|
|
|
http-server
command
|