ws

package
v0.0.0-...-a17a3e0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBuffer = 64

DefaultBuffer is the size of the DefaultRead buffer.

Variables

This section is empty.

Functions

func Bind

func Bind(sr SendRecver, read SocketReader) xws.Handler

Bind routes messages and errors between a SendRecver and a websocket connection.

func BindRead

func BindRead(r RecvCloser) xws.Handler

BindRead receives messages from a Recver and writes them to the Conn. It should be used in place of Bind for one-way messaging from the backend to the websocket client. It reads and discards all bytes sent on the Conn, and closes if Conn.Read returns io.EOF.

func Check

func Check(config *xws.Config, req *http.Request) error

Check is a Handshaker which does nothing.

func DefaultRead

func DefaultRead(c *xws.Conn) ([]byte, bool, error)

DefaultRead receives raw bytes from the websocket. It starts with a buffer of 128 and grows it as needed. It never rejects a message as malformed.

Types

type Binder

type Binder interface {
	Bind(*xws.Conn)
}

type Handshaker

type Handshaker func(config *xws.Config, req *http.Request) error

Handshaker is a function that checks an HTTP request for websockets.

type HangupRecver

type HangupRecver struct {
	river.Responder
	// contains filtered or unexported fields
}

HangupRecver is a type which is hung up when it sends its response, and upon being hung up, will close the River socket used in its Recv.

func MakeHangupRecver

func MakeHangupRecver(rsp river.Responder, r RecvCloser) HangupRecver

MakeHangupRecver makes a new HangupRecver which will close its Recver socket when it responds to a hangup Survey.

func (HangupRecver) Recver

func (h HangupRecver) Recver() RecvCloser

Recver returns the HangupRecver's Recv socket, which is closed when the HangupRecver replies to a hangup survey.

func (HangupRecver) Send

func (h HangupRecver) Send(bs []byte) error

Send implements Responder.Send on HangupRecver, closing its signal channel and calling Send on the underlying Responder. Make sure this is only called once!

type HangupSender

type HangupSender struct {
	river.Responder
	// contains filtered or unexported fields
}

HangupSender is a Responder river which closes its signal channel after Sending.

func MakeHangup

func MakeHangup(r river.Responder, sr SocketReader) HangupSender

MakeHangup creates a new HangupSender from the given river.Responder and SocketReader. If the SocketReader is nil, DefaultReader will be used.

func (HangupSender) Read

func (h HangupSender) Read(c *xws.Conn) (bs []byte, ok bool, e error)

Read is a SocketReader which returns io.EOF when the HangupSender has Sent and closes the Conn.

TODO: Tighten this up a lot!

func (HangupSender) Send

func (h HangupSender) Send(msg []byte) error

Send implements river.Responder.Send on HangupSender, closing its signal channel and calling Send on the underlying Responder. Make sure this is only called once.

type MessageError

type MessageError struct{ Error error }

MessageError is a JSON-serializable error message.

func (MessageError) MarshalJSON

func (m MessageError) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON.Marshaler on MessageError.

type RecvCloser

type RecvCloser interface {
	io.Closer
	Recver
}

type Recver

type Recver interface {
	Recv() ([]byte, error)
}

type SendRecver

type SendRecver interface {
	Sender
	Recver
}

type Sender

type Sender interface {
	Send([]byte) error
}

type SocketReader

type SocketReader func(c *xws.Conn) ([]byte, bool, error)

SocketReader is a function that gets []byte from a Websocket conn. If there's a formatting error which the client needs to be told about, the bool value will be false.

Jump to

Keyboard shortcuts

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