internal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected   = errors.New("transport error: not connected")
	ErrConnLoopActive = errors.New("transport error: connection loop is already active")
)

Functions

This section is empty.

Types

type StreamTransportConn

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

StreamTransportConn is a client stream connection; it's typically wrapped into more specific type of connection: e.g. MarketConn, which knows how to unmarshal the data being received.

func NewStreamTransportConn

func NewStreamTransportConn(params *StreamTransportParams) (*StreamTransportConn, error)

NewStreamTransportConn creates a new stream transport connection.

Note that a client should manually call Connect on a newly created connection; the rationale is that clients might register state and/or message handler before the connection, to avoid any possible races.

func (*StreamTransportConn) Close

func (c *StreamTransportConn) Close() error

Close stops reconnection loop (if reconnection was requested), and if websocket connection is active at the moment, closes it as well (with the code 1000, i.e. normal closure). If graceful websocket closure fails, the forceful one is performed.

func (*StreamTransportConn) CloseOpt

func (c *StreamTransportConn) CloseOpt(data []byte, stopReconnecting bool) error

func (*StreamTransportConn) Connect

func (c *StreamTransportConn) Connect() error

Connect either starts a connection goroutine (if state is TransportStateDisconnected), or makes it to stop waiting a timeout and connect right now (if state is TransportStateWaitBeforeReconnect). For other states, returns an error.

It doesn't wait for the connection to establish, and returns immediately.

func (*StreamTransportConn) GetState

func (c *StreamTransportConn) GetState() TransportState

GetState returns connection state

func (*StreamTransportConn) OnRead

func (c *StreamTransportConn) OnRead(cb onReadCallback)

OnRead sets on-read callback; it should be called once right after creation of the StreamTransportConn, before the connection is established.

func (*StreamTransportConn) OnStateChange

func (c *StreamTransportConn) OnStateChange(cb onStateChangeCallback)

func (*StreamTransportConn) ResetTimeout

func (c *StreamTransportConn) ResetTimeout()

func (*StreamTransportConn) Send

func (c *StreamTransportConn) Send(ctx context.Context, data []byte) error

Send sends data to the websocket if it's connected

func (*StreamTransportConn) URL

func (c *StreamTransportConn) URL() string

URL returns an url used for connection

type StreamTransportParams

type StreamTransportParams struct {
	URL string

	Reconnect           bool
	Backoff             bool
	ReconnectTimeout    time.Duration
	MaxReconnectTimeout time.Duration
}

StreamTransportParams contains params for opening a client stream connection (see StreamTransportConn)

type TransportState

type TransportState int
const (
	// TransportStateDisconnected means we're disconnected and not trying to connect.
	// connLoop is not running.
	TransportStateDisconnected TransportState = iota

	// TransportStateWaitBeforeReconnect means we already tried to connect, but then
	// either the connection failed, or succeeded but later disconnected for some
	// reason (see stateCause), and now we're waiting for a timeout before
	// connecting again. wsConn is nil, but connCtx and connCtxCancel are not,
	// and connLoop is running.
	TransportStateWaitBeforeReconnect

	// TransportStateConnecting means we're calling websocket.DefaultDialer.Dial() right
	// now.
	TransportStateConnecting

	// TransportStateConnected means the websocket connection is established.
	TransportStateConnected
)

type WebsocketTx

type WebsocketTx struct {
	MessageType int
	Data        []byte
	Res         chan error
}

websocketTx represents message to send to the websocket

Jump to

Keyboard shortcuts

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