conn

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Apache-2.0 Imports: 20 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// process message from the connection
	ServeConn()

	// SetReadDeadline sets the deadline for future Read calls
	// and any currently-blocked Read call.
	// A zero value for t means Read will not time out.
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline sets the deadline for future Write calls
	// and any currently-blocked Write call.
	// Even if write times out, it may return n > 0, indicating that
	// some of the data was successfully written.
	// A zero value for t means Write will not time out.
	SetWriteDeadline(t time.Time) error

	// Read read raw data from the connection
	// you can also set raw data consumer when new client/server instance
	Read(raw []byte) (int, error)

	// Write write raw data to the connection
	// it will open a stream for raw data
	Write(raw []byte) (int, error)

	// WriteMessageAsync writes data to the connection and don't care about the response.
	WriteMessageAsync(msg *model.Message) error

	// WriteMessageSync writes data to the connection and care about the response.
	WriteMessageSync(msg *model.Message) (*model.Message, error)

	// ReadMessage reads message from the connection.
	// it will be blocked when no message received
	// if you want to use this api for message reading,
	// make sure AutoRoute be false
	ReadMessage(msg *model.Message) error

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr

	// ConnectState return the current connection state
	ConnectionState() ConnectionState

	// Close closes the connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Close() error
}

the operation set of connection

func NewConnection

func NewConnection(opts *ConnectionOptions) Connection

get connection interface by ConnTye

type ConnectionOptions

type ConnectionOptions struct {
	// the protocol type that the connection based on
	ConnType string
	// connection or session object for each kind of protocol
	Base interface{}
	// control lane
	CtrlLane interface{}
	// connect stat
	State *ConnectionState
	// the message route to
	Handler mux.Handler
	// package type
	// only used by websocket mode
	ConnUse api.UseType
	// consumer for raw data
	Consumer io.Writer
	// auto route into entries
	AutoRoute bool
	// OnReadTransportErr
	OnReadTransportErr func(nodeID, projectID string)
}

connection options

type ConnectionState

type ConnectionState struct {
	State            string
	Headers          http.Header
	PeerCertificates []*x509.Certificate
}

connection states TODO: add connection state filed

type QuicConnection

type QuicConnection struct {
	OnReadTransportErr func(nodeID, projectID string)
	// contains filtered or unexported fields
}

QuicConnection the connection based on quic protocol

func NewQuicConn

func NewQuicConn(options *ConnectionOptions) *QuicConnection

NewQuicConn new quic connection

func (*QuicConnection) Close

func (conn *QuicConnection) Close() error

Close will cancel write and read close the session

func (*QuicConnection) ConnectionState

func (conn *QuicConnection) ConnectionState() ConnectionState

func (*QuicConnection) LocalAddr

func (conn *QuicConnection) LocalAddr() net.Addr

func (*QuicConnection) Read

func (conn *QuicConnection) Read(raw []byte) (int, error)

func (*QuicConnection) ReadMessage

func (conn *QuicConnection) ReadMessage(msg *model.Message) error

ReadMessage read message from fifo it will blocked when no message received

func (*QuicConnection) RemoteAddr

func (conn *QuicConnection) RemoteAddr() net.Addr

func (*QuicConnection) ServeConn

func (conn *QuicConnection) ServeConn()

ServeConn start control lan and session loop

func (*QuicConnection) SetReadDeadline

func (conn *QuicConnection) SetReadDeadline(t time.Time) error

func (*QuicConnection) SetWriteDeadline

func (conn *QuicConnection) SetWriteDeadline(t time.Time) error

func (*QuicConnection) Write

func (conn *QuicConnection) Write(raw []byte) (int, error)

Write write raw data into stream

func (*QuicConnection) WriteMessageAsync

func (conn *QuicConnection) WriteMessageAsync(msg *model.Message) error

WriteMessageAsync send async message

func (*QuicConnection) WriteMessageSync

func (conn *QuicConnection) WriteMessageSync(msg *model.Message) (*model.Message, error)

WriteMessageSync write sync message please set write deadline before WriteMessageSync called

type WSConnection

type WSConnection struct {
	WriteDeadline time.Time
	ReadDeadline  time.Time

	OnReadTransportErr func(nodeID, projectID string)
	// contains filtered or unexported fields
}

func NewWSConn

func NewWSConn(options *ConnectionOptions) *WSConnection

func (*WSConnection) Close

func (conn *WSConnection) Close() error

func (*WSConnection) ConnectionState

func (conn *WSConnection) ConnectionState() ConnectionState

get connection state TODO:

func (*WSConnection) LocalAddr

func (conn *WSConnection) LocalAddr() net.Addr

func (*WSConnection) Read

func (conn *WSConnection) Read(raw []byte) (int, error)

func (*WSConnection) ReadMessage

func (conn *WSConnection) ReadMessage(msg *model.Message) error

func (*WSConnection) RemoteAddr

func (conn *WSConnection) RemoteAddr() net.Addr

func (*WSConnection) ServeConn

func (conn *WSConnection) ServeConn()

ServeConn start to receive message from connection

func (*WSConnection) SetReadDeadline

func (conn *WSConnection) SetReadDeadline(t time.Time) error

func (*WSConnection) SetWriteDeadline

func (conn *WSConnection) SetWriteDeadline(t time.Time) error

func (*WSConnection) Write

func (conn *WSConnection) Write(raw []byte) (int, error)

func (*WSConnection) WriteMessageAsync

func (conn *WSConnection) WriteMessageAsync(msg *model.Message) error

func (*WSConnection) WriteMessageSync

func (conn *WSConnection) WriteMessageSync(msg *model.Message) (*model.Message, error)

Directories

Path Synopsis
Package testing is a generated GoMock package.
Package testing is a generated GoMock package.

Jump to

Keyboard shortcuts

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