Documentation
¶
Overview ¶
Package connmgr provides connection management for server scenarios.
This package implements connection limiting, tracking, and lifecycle management for high-concurrency server deployments.
Index ¶
- Variables
- type Config
- type ConnInfo
- func (c *ConnInfo) AddBytesIn(n int64)
- func (c *ConnInfo) AddBytesOut(n int64)
- func (c *ConnInfo) BytesIn() int64
- func (c *ConnInfo) BytesOut() int64
- func (c *ConnInfo) Close()
- func (c *ConnInfo) Duration() time.Duration
- func (c *ConnInfo) IsClosed() bool
- func (c *ConnInfo) LastActive() time.Time
- func (c *ConnInfo) UpdateActive()
- type Manager
- func (m *Manager) Accept(conn net.Conn) (*ConnInfo, error)
- func (m *Manager) Active() int64
- func (m *Manager) CloseIdle(timeout time.Duration) []string
- func (m *Manager) ForEach(fn func(id string, info *ConnInfo) bool)
- func (m *Manager) GetInfo(id string) (*ConnInfo, bool)
- func (m *Manager) GetStats() Stats
- func (m *Manager) Rejected() int64
- func (m *Manager) Release(info *ConnInfo)
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) Total() int64
- func (m *Manager) WrapConn(conn net.Conn, info *ConnInfo) *WrappedConn
- type Stats
- type WrappedConn
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectionLimit is returned when the connection limit is reached. ErrConnectionLimit = errors.New("connection limit reached") // ErrManagerClosed is returned when the manager is closed. ErrManagerClosed = errors.New("connection manager closed") )
Errors returned by the connection manager.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxConnections is the maximum number of concurrent connections.
// 0 means unlimited.
MaxConnections int
// ConnectionTimeout is the idle timeout for connections.
// 0 means no timeout.
ConnectionTimeout time.Duration
// AcceptTimeout is the timeout for accepting new connections.
AcceptTimeout time.Duration
}
Config holds the configuration for the connection manager.
type ConnInfo ¶
type ConnInfo struct {
ID string
RemoteAddr string
StartTime time.Time
// contains filtered or unexported fields
}
ConnInfo holds information about a connection.
func (*ConnInfo) AddBytesIn ¶
AddBytesIn adds to the bytes received counter.
func (*ConnInfo) AddBytesOut ¶
AddBytesOut adds to the bytes sent counter.
func (*ConnInfo) LastActive ¶
LastActive returns the last active time.
func (*ConnInfo) UpdateActive ¶
func (c *ConnInfo) UpdateActive()
UpdateActive updates the last active time to now.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages connections for server scenarios.
func (*Manager) Accept ¶
Accept processes a new connection. Returns ErrConnectionLimit if the connection limit is reached.
func (*Manager) CloseIdle ¶
CloseIdle closes connections that have been idle for longer than the timeout.
type WrappedConn ¶
WrappedConn wraps a net.Conn with connection management.
func (*WrappedConn) Close ¶
func (w *WrappedConn) Close() error
Close closes the connection and releases resources.