Documentation ¶
Index ¶
- Constants
- type AtomicConnectionState
- type Connection
- type ConnectionRole
- type ConnectionState
- type Message
- type MessageHandler
- type MessageType
- type OptionFunction
- func WithConnectionTimeout(timeout time.Duration) OptionFunction
- func WithReadHandler(handler MessageHandler) OptionFunction
- func WithReadTimeout(timeout time.Duration) OptionFunction
- func WithServerHost(host string) OptionFunction
- func WithServerPort(port int) OptionFunction
- func WithWriteTimeout(timeout time.Duration) OptionFunction
- type StateHandler
Constants ¶
View Source
const ( ClientConnection ConnectionRole = "client" ServerConnection ConnectionRole = "server" DefaultServerHost = "127.0.0.1" DefaultServerPort = 33333 DefaultConnectionTimeout = time.Second * 60 DefaultReadTimeout = time.Millisecond * 500 DefaultWriteTimeout = time.Millisecond * 500 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicConnectionState ¶
type AtomicConnectionState struct {
// contains filtered or unexported fields
}
func NewAtomicConnectionState ¶
func NewAtomicConnectionState(initial ConnectionState) AtomicConnectionState
func (*AtomicConnectionState) Get ¶
func (a *AtomicConnectionState) Get() ConnectionState
func (*AtomicConnectionState) Set ¶
func (a *AtomicConnectionState) Set(val ConnectionState)
type Connection ¶
type Connection interface { ListenAndServe(ctx context.Context, callbackFn StateHandler) error Read(ctx context.Context) ([]byte, error) Write(ctx context.Context, data []byte) error Close() error IsConnected() bool }
func NewConnection ¶
func NewConnection(role ConnectionRole, opts ...OptionFunction) (Connection, error)
type ConnectionRole ¶
type ConnectionRole string
type ConnectionState ¶
type ConnectionState int32
const ( NotConnected ConnectionState = iota ConnectionPending Connected Disconnecting Disconnected )
type MessageHandler ¶
type OptionFunction ¶
type OptionFunction func(*connection)
func WithConnectionTimeout ¶
func WithConnectionTimeout(timeout time.Duration) OptionFunction
func WithReadHandler ¶
func WithReadHandler(handler MessageHandler) OptionFunction
func WithReadTimeout ¶
func WithReadTimeout(timeout time.Duration) OptionFunction
func WithServerHost ¶
func WithServerHost(host string) OptionFunction
func WithServerPort ¶
func WithServerPort(port int) OptionFunction
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) OptionFunction
type StateHandler ¶
type StateHandler func(state ConnectionState) error
Click to show internal directories.
Click to hide internal directories.