xcomm

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_DELAY       = float64(0.5)
	POLL_INTERVAL     = float64(0.2)
	POLL_CHUNKSIZE    = int(1024)
	POLL_MAXSIZE      = int(0)
	POLL_WAITNULLREAD = false
)
View Source
const (
	NET_CONNECT_TIMEOUT    = float64(10)
	NET_KEEPALIVE_INTERVAL = float64(30)
	NET_CONNECTIONS_LIMIT  = int(0)
)

Variables

View Source
var (
	ErrError      = errors.New("")
	ErrUri        = fmt.Errorf("%winvalid uri", ErrError)
	ErrConnection = fmt.Errorf("%wconnection failed", 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 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)
}

interface representing connection

func NewConnection

func NewConnection(
	uri string, log *Logger, opts Options) (Connection, error)

create new connection handler

type Listener

type Listener interface {
	Uri() string
	Type() string
	IsActive() bool
	Start() error
	Stop()
	SetConnHandler(func(Connection))
}

interface representing listener

func NewListener

func NewListener(
	uri string, log *Logger, opts Options) (Listener, error)

create new listener handler

type Logger added in v0.3.9

type Logger = xlog.Logger

type NetConnection

type NetConnection struct {

	// 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 *Logger, opts Options) (*NetConnection, error)

NewNetConnection creates a new SockClient instance

func (*NetConnection) Cancel

func (nc *NetConnection) Cancel()

cancel blocking operations

func (*NetConnection) Close

func (nc *NetConnection) Close()

Closes the socket connection

func (*NetConnection) IsOpened

func (nc *NetConnection) IsOpened() bool

func (*NetConnection) NetHandler

func (nc *NetConnection) NetHandler() net.Conn

func (*NetConnection) Open

func (nc *NetConnection) Open() error

Opens the socket connection

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

func (NetConnection) String added in v0.3.11

func (bs NetConnection) String() string

implement Stringer interface

func (NetConnection) Type added in v0.3.11

func (bs NetConnection) Type() string

func (NetConnection) Uri added in v0.3.11

func (bs NetConnection) Uri() string

type NetListener

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

Network Listener

func NewNetListener

func NewNetListener(
	uri string, log *Logger, opts Options) (*NetListener, error)

func (*NetListener) IsActive

func (nl *NetListener) IsActive() bool

func (*NetListener) NetHandler

func (nl *NetListener) NetHandler() net.Listener

func (*NetListener) SetConnHandler

func (nl *NetListener) SetConnHandler(h func(Connection))

func (*NetListener) Start

func (nl *NetListener) Start() error

func (*NetListener) Stop

func (nl *NetListener) Stop()

func (NetListener) String added in v0.3.11

func (bs NetListener) String() string

implement Stringer interface

func (NetListener) Type added in v0.3.11

func (bs NetListener) Type() string

func (NetListener) Uri added in v0.3.11

func (bs NetListener) Uri() string

type Options added in v0.3.9

type Options = types.NDict

type SerialConnection

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

Serial Connection

func NewSerialConnection

func NewSerialConnection(
	uri string, log *Logger, opts Options) (*SerialConnection, error)

func (*SerialConnection) Cancel

func (sc *SerialConnection) Cancel()

cancel blocking operations

func (*SerialConnection) Close

func (sc *SerialConnection) Close()

Closes the serial connection

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 serial connection

func (*SerialConnection) RecvWait

func (sc *SerialConnection) RecvWait(timeout float64) ([]byte, error)

Receives data with a specified timeout from the serial connection

func (*SerialConnection) Send

func (sc *SerialConnection) Send(data []byte) error

Sends data over the serial connection

func (SerialConnection) String added in v0.3.11

func (bs SerialConnection) String() string

implement Stringer interface

func (SerialConnection) Type added in v0.3.11

func (bs SerialConnection) Type() string

func (SerialConnection) Uri added in v0.3.11

func (bs SerialConnection) Uri() string

type SerialListener

type SerialListener struct {
	*SerialConnection
	// contains filtered or unexported fields
}

Serial Listener

func NewSerialListener

func NewSerialListener(
	uri string, log *Logger, opts Options) (*SerialListener, error)

func (*SerialListener) Close added in v0.3.11

func (sl *SerialListener) Close()

no close action in listener mode, nust use stop method

func (*SerialListener) IsActive

func (sl *SerialListener) IsActive() bool

func (*SerialListener) PortHandler

func (sl *SerialListener) PortHandler() serial.Port

func (*SerialListener) SetConnHandler

func (sl *SerialListener) SetConnHandler(h func(Connection))

func (*SerialListener) Start

func (sl *SerialListener) Start() error

func (*SerialListener) Stop

func (sl *SerialListener) Stop()

func (SerialListener) String added in v0.3.11

func (bs SerialListener) String() string

implement Stringer interface

func (SerialListener) Type added in v0.3.11

func (bs SerialListener) Type() string

func (SerialListener) Uri added in v0.3.11

func (bs SerialListener) Uri() string

Jump to

Keyboard shortcuts

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