Documentation
¶
Index ¶
- Variables
- type BaseConnection
- type Connection
- type Listener
- type NetConnection
- func (nc *NetConnection) Cancel()
- func (nc *NetConnection) Close()
- func (nc *NetConnection) IsOpened() bool
- func (nc *NetConnection) NetHandler() net.Conn
- func (nc *NetConnection) Open() error
- func (nc *NetConnection) Parent() Listener
- func (nc *NetConnection) Recv() ([]byte, error)
- func (nc *NetConnection) RecvWait(timeout float64) ([]byte, error)
- func (nc *NetConnection) Send(data []byte) error
- type NetListener
- type SerialConnection
- func (sc *SerialConnection) Cancel()
- func (sc *SerialConnection) Close()
- func (sc *SerialConnection) IsOpened() bool
- func (sc *SerialConnection) Open() error
- func (sc *SerialConnection) Parent() Listener
- func (sc *SerialConnection) PortHandler() serial.Port
- func (sc *SerialConnection) Recv() ([]byte, error)
- func (sc *SerialConnection) RecvWait(timeout float64) ([]byte, error)
- func (sc *SerialConnection) Send(data []byte) error
- type SerialListener
Constants ¶
This section is empty.
Variables ¶
var ( ErrError = errors.New("") ErrInvalidUri = fmt.Errorf("%winvalid uri format", ErrError) ErrOpen = fmt.Errorf("%wopen connection failed", ErrError) ErrNotOpend = fmt.Errorf("%wconnection not opened", ErrError) ErrClosed = fmt.Errorf("%wconnection closed", ErrError) ErrBreak = fmt.Errorf("%woperation break", ErrError) ErrTimeout = fmt.Errorf("%woperation timeout", ErrError) ErrRead = fmt.Errorf("%wread failed", ErrError) ErrWrite = fmt.Errorf("%wwrite failed", ErrError) )
Define common errors
Functions ¶
This section is empty.
Types ¶
type BaseConnection ¶
type BaseConnection struct {
Log *xlog.Logger
// error delay for execution loop
ErrorDelay float64
// read/write polling params
PollInterval float64
PollChunkSize int
PollMaxSize int
// contains filtered or unexported fields
}
BaseConnection is a base structure for connection handling
func (*BaseConnection) Sleep ¶
func (bs *BaseConnection) Sleep(timeout float64) bool
Sleep pauses the execution for the specified duration in seconds.
func (*BaseConnection) String ¶
func (bs *BaseConnection) String() string
implement Stringer interface
func (*BaseConnection) Type ¶
func (bs *BaseConnection) Type() string
func (*BaseConnection) Uri ¶
func (bs *BaseConnection) Uri() string
type Connection ¶
type Connection interface {
Uri() string
Type() string
Parent() Listener
IsOpened() bool
Open() error
Close()
Cancel()
Send([]byte) error
Recv() ([]byte, error)
RecvWait(float64) ([]byte, error)
Sleep(float64) bool
}
interface representing connection
func NewConnection ¶
func NewConnection(uri string, log *xlog.Logger) (Connection, error)
create new connection handler
type Listener ¶
type Listener interface {
Uri() string
Type() string
IsActive() bool
Start() error
Stop()
Sleep(float64) bool
SetConnHandler(func(Connection))
}
interface representing listener
type NetConnection ¶
type NetConnection struct {
*BaseConnection
// connect timeout in sec
ConnectTimeout float64
// keepalive interval in sec, use 0 to disable
KeepAliveInterval float64
// contains filtered or unexported fields
}
Network Connection
func NewNetConnection ¶
func NewNetConnection( uri string, log *xlog.Logger) (*NetConnection, error)
NewNetConnection creates a new SockClient instance
func (*NetConnection) IsOpened ¶
func (nc *NetConnection) IsOpened() bool
func (*NetConnection) NetHandler ¶
func (nc *NetConnection) NetHandler() net.Conn
func (*NetConnection) Parent ¶
func (nc *NetConnection) Parent() Listener
func (*NetConnection) Recv ¶
func (nc *NetConnection) Recv() ([]byte, error)
Recv data from the socket connection
func (*NetConnection) RecvWait ¶
func (nc *NetConnection) RecvWait(timeout float64) ([]byte, error)
Receives data with a specified timeout from the socket connection
func (*NetConnection) Send ¶
func (nc *NetConnection) Send(data []byte) error
Sends data over the socket connection
type NetListener ¶
type NetListener struct {
*BaseConnection
// max number for connected clients
ListenerPool int
// contains filtered or unexported fields
}
Network Listener
func NewNetListener ¶
func NewNetListener(uri string, log *xlog.Logger) (*NetListener, error)
func (*NetListener) IsActive ¶
func (nl *NetListener) IsActive() bool
func (*NetListener) NetHandler ¶
func (nc *NetListener) NetHandler() net.Listener
func (*NetListener) SetConnHandler ¶
func (nl *NetListener) SetConnHandler(f func(Connection))
func (*NetListener) Start ¶
func (nl *NetListener) Start() error
func (*NetListener) Stop ¶
func (nl *NetListener) Stop()
type SerialConnection ¶
type SerialConnection struct {
*BaseConnection
// contains filtered or unexported fields
}
Serial Connection
func NewSerialConnection ¶
func NewSerialConnection( uri string, log *xlog.Logger) (*SerialConnection, error)
func (*SerialConnection) IsOpened ¶
func (sc *SerialConnection) IsOpened() bool
func (*SerialConnection) Open ¶
func (sc *SerialConnection) Open() error
func (*SerialConnection) Parent ¶
func (sc *SerialConnection) Parent() Listener
func (*SerialConnection) PortHandler ¶
func (sc *SerialConnection) PortHandler() serial.Port
func (*SerialConnection) Recv ¶
func (sc *SerialConnection) Recv() ([]byte, error)
Recv data from the socket connection
func (*SerialConnection) RecvWait ¶
func (sc *SerialConnection) RecvWait(timeout float64) ([]byte, error)
Receives data with a specified timeout from the socket connection
func (*SerialConnection) Send ¶
func (sc *SerialConnection) Send(data []byte) error
Sends data over the serial connection
type SerialListener ¶
type SerialListener struct {
*SerialConnection
// contains filtered or unexported fields
}
Serial Listener
func NewSerialListener ¶
func NewSerialListener(uri string, log *xlog.Logger) (*SerialListener, error)
func (*SerialListener) IsActive ¶
func (sl *SerialListener) IsActive() bool
func (*SerialListener) PortHandler ¶
func (sl *SerialListener) PortHandler() serial.Port
func (*SerialListener) SetConnHandler ¶
func (sl *SerialListener) SetConnHandler(f func(Connection))
func (*SerialListener) Start ¶
func (sl *SerialListener) Start() error
func (*SerialListener) Stop ¶
func (sl *SerialListener) Stop()