wsstream

package module
v0.0.0-...-36fb70d Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: Apache-2.0 Imports: 8 Imported by: 4

README

wsstream

wsstream is a library that adds a very simple protocol on top of websockets. The protocol adds a channel byte to the start of every websocket message. In addition to the protocol, wsstream has functions that assist in writing interactive programs over websockets.

Documentation

Overview

This package was originally designed to have 3 channels for reading that represented stdin, stdout, stderr, also a channel that contained the exit code. Additional channels can be created by the user.

Index

Constants

View Source
const (
	StdinChan    int = 0
	StdoutChan   int = 1
	StderrChan   int = 2
	ExitCodeChan int = 3
)

Variables

This section is empty.

Functions

func PackMessage

func PackMessage(channel int, data []byte) []byte

func UnpackMessage

func UnpackMessage(frame []byte) (int, []byte, error)

Types

type MessageFrame

type MessageFrame []byte

type WSReadWriter

type WSReadWriter struct {
	*WSStream
	// contains filtered or unexported fields
}

func (*WSReadWriter) CreateReader

func (ws *WSReadWriter) CreateReader(channel int) *WSReader

func (*WSReadWriter) CreateWriter

func (ws *WSReadWriter) CreateWriter(channel int) *WSWriter

func (*WSReadWriter) RunDispatch

func (ws *WSReadWriter) RunDispatch()

type WSReader

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

func (*WSReader) IsClosed

func (r *WSReader) IsClosed() bool

func (*WSReader) Read

func (r *WSReader) Read(p []byte) (n int, err error)

type WSStream

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

func NewWSStream

func NewWSStream(conn *websocket.Conn) *WSStream

func (*WSStream) CloseAndCleanup

func (ws *WSStream) CloseAndCleanup() error

CloseAndCleanup MUST be called. Should be called by the user of the stream in response to hearing about the close from selecting on Closed(). Should only be called once but MUST be called by the user of the WSStream or else we'll leak the open WS connection.

func (*WSStream) Closed

func (ws *WSStream) Closed() <-chan struct{}

func (*WSStream) ReadMsg

func (ws *WSStream) ReadMsg() <-chan []byte

func (*WSStream) StartReader

func (ws *WSStream) StartReader()

func (*WSStream) StartWriteLoop

func (ws *WSStream) StartWriteLoop()

func (*WSStream) WriteMsg

func (ws *WSStream) WriteMsg(channel int, msg []byte) error

func (*WSStream) WriteRaw

func (ws *WSStream) WriteRaw(framedMsg []byte) error

type WSWriter

type WSWriter struct {
	*WSStream
	WriteChan int
}

func (*WSWriter) Write

func (ws *WSWriter) Write(p []byte) (n int, err error)

type WebsocketParams

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

Jump to

Keyboard shortcuts

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