Documentation ¶
Index ¶
- Constants
- Variables
- func NewWebsocketNamespace() *core.Namespace
- type WebsocketConnectParams
- type WebsocketConnection
- func (conn *WebsocketConnection) Close() error
- func (conn *WebsocketConnection) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, ...) bool
- func (conn *WebsocketConnection) GetGoMethod(name string) (*core.GoFunction, bool)
- func (conn *WebsocketConnection) IsClosedOrClosing() bool
- func (conn *WebsocketConnection) IsMutable() bool
- func (conn *WebsocketConnection) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, ...)
- func (conn *WebsocketConnection) Prop(ctx *core.Context, name string) core.Value
- func (*WebsocketConnection) PropertyNames(ctx *core.Context) []string
- func (conn *WebsocketConnection) ReadMessage(ctx *core.Context) (messageType WebsocketMessageType, p []byte, err error)
- func (conn *WebsocketConnection) RemoteAddrWithPort() netaddr.RemoteAddrWithPort
- func (conn *WebsocketConnection) SetPingHandler(ctx *core.Context, handler func(data string) error)
- func (*WebsocketConnection) SetProp(ctx *core.Context, name string, value core.Value) error
- func (conn *WebsocketConnection) StartReadingAllMessagesIntoChan(ctx *core.Context, channel chan WebsocketMessageChanItem) error
- func (conn *WebsocketConnection) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)
- func (conn *WebsocketConnection) WriteMessage(ctx *core.Context, messageType WebsocketMessageType, data []byte) error
- type WebsocketMessageChanItem
- type WebsocketMessageType
- type WebsocketServer
- func (s *WebsocketServer) Close(ctx *core.Context) error
- func (s *WebsocketServer) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, ...) bool
- func (s *WebsocketServer) GetGoMethod(name string) (*core.GoFunction, bool)
- func (s *WebsocketServer) IsMutable() bool
- func (s *WebsocketServer) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, ...)
- func (s *WebsocketServer) Prop(ctx *core.Context, name string) core.Value
- func (*WebsocketServer) PropertyNames(ctx *core.Context) []string
- func (*WebsocketServer) SetProp(ctx *core.Context, name string, value core.Value) error
- func (s *WebsocketServer) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)
- func (s *WebsocketServer) Upgrade(rw *http_ns.ResponseWriter, r *http_ns.Request) (*WebsocketConnection, error)
- func (s *WebsocketServer) UpgradeGoValues(rw http.ResponseWriter, r *http.Request, ...) (*WebsocketConnection, error)
Constants ¶
const ( WS_SIMUL_CONN_TOTAL_LIMIT_NAME = "ws/simul-connections" OPTION_DOES_NOT_EXIST_FMT = "option '%s' does not exist" )
const ( DEFAULT_WS_SERVER_HANDSHAKE_TIMEOUT = 3 * time.Second DEFAULT_WS_SERVER_READ_BUFFER_SIZE = 10_000 DEFAULT_WS_SERVER_WRITE_BUFFER_SIZE = 10_000 DEFAULT_MAX_WS_CONN_MSG_SIZE = 100_000 DEFAULT_MAX_IP_WS_CONNS = 10 WEBSOCKET_CLOSE_TASK_PER_GOROUTINE = 10 SERVER_SIDE_WEBSOCKET_CLOSE_TIMEOUT = 2 * time.Second WEBSOCKET_SERVER_CLOSE_TIMEOUT = 3 * time.Second DEFAULT_WS_MESSAGE_TIMEOUT = 10 * time.Second DEFAULT_WS_WAIT_MESSAGE_TIMEOUT = 30 * time.Second DEFAULT_WS_HANDSHAKE_TIMEOUT = 20 * time.Second )
Variables ¶
var ( ErrClosingOrClosedWebsocketConn = errors.New("closed or closing websocket connection") ErrAlreadyReadingAllMessages = errors.New("already reading all messages") )
var ( ErrClosedWebsocketServer = errors.New("closed websocket server") ErrTooManyWsConnectionsOnIp = errors.New("too many websocket connections on same ip") )
Functions ¶
func NewWebsocketNamespace ¶
Types ¶
type WebsocketConnectParams ¶
type WebsocketConnection ¶
type WebsocketConnection struct {
// contains filtered or unexported fields
}
func WebsocketConnect ¶
func WebsocketConnect(args WebsocketConnectParams) (*WebsocketConnection, error)
func (*WebsocketConnection) Close ¶
func (conn *WebsocketConnection) Close() error
func (*WebsocketConnection) GetGoMethod ¶
func (conn *WebsocketConnection) GetGoMethod(name string) (*core.GoFunction, bool)
func (*WebsocketConnection) IsClosedOrClosing ¶
func (conn *WebsocketConnection) IsClosedOrClosing() bool
func (*WebsocketConnection) IsMutable ¶
func (conn *WebsocketConnection) IsMutable() bool
func (*WebsocketConnection) PrettyPrint ¶
func (conn *WebsocketConnection) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)
func (*WebsocketConnection) PropertyNames ¶
func (*WebsocketConnection) PropertyNames(ctx *core.Context) []string
func (*WebsocketConnection) ReadMessage ¶
func (conn *WebsocketConnection) ReadMessage(ctx *core.Context) (messageType WebsocketMessageType, p []byte, err error)
func (*WebsocketConnection) RemoteAddrWithPort ¶
func (conn *WebsocketConnection) RemoteAddrWithPort() netaddr.RemoteAddrWithPort
func (*WebsocketConnection) SetPingHandler ¶
func (conn *WebsocketConnection) SetPingHandler(ctx *core.Context, handler func(data string) error)
func (*WebsocketConnection) StartReadingAllMessagesIntoChan ¶
func (conn *WebsocketConnection) StartReadingAllMessagesIntoChan(ctx *core.Context, channel chan WebsocketMessageChanItem) error
StartReadingAllMessagesIntoChan creates a goroutine that continuously calls ReadMessage() and puts results in channel. The goroutine stops when the context is done or the connection is closed or closing; the channel is closed. If the connection is already reading all messages ErrAlreadyReadingAllMessages is returned and the channel is not closed. If the connection is connection is closed ErrClosingOrClosedWebsocketConn is returned and the channel is not closed.
func (*WebsocketConnection) ToSymbolicValue ¶
func (*WebsocketConnection) WriteMessage ¶
func (conn *WebsocketConnection) WriteMessage(ctx *core.Context, messageType WebsocketMessageType, data []byte) error
type WebsocketMessageChanItem ¶
type WebsocketMessageChanItem struct { Error error Type WebsocketMessageType //nil if error Payload []byte //nil if error }
type WebsocketMessageType ¶
type WebsocketMessageType int
const ( WebsocketBinaryMessage WebsocketMessageType = websocket.BinaryMessage WebsocketTextMessage WebsocketMessageType = websocket.TextMessage WebsocketPingMessage WebsocketMessageType = websocket.PingMessage WebsocketPongMessage WebsocketMessageType = websocket.PongMessage WebsocketCloseMessage WebsocketMessageType = websocket.CloseMessage )
type WebsocketServer ¶
type WebsocketServer struct {
// contains filtered or unexported fields
}
WebsocketServer upgrades an HTTP connection to a Websocket connection, it implements Value.
func NewWebsocketServer ¶
func NewWebsocketServer(ctx *core.Context) (*WebsocketServer, error)
func (*WebsocketServer) GetGoMethod ¶
func (s *WebsocketServer) GetGoMethod(name string) (*core.GoFunction, bool)
func (*WebsocketServer) IsMutable ¶
func (s *WebsocketServer) IsMutable() bool
func (*WebsocketServer) PrettyPrint ¶
func (s *WebsocketServer) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)
func (*WebsocketServer) PropertyNames ¶
func (*WebsocketServer) PropertyNames(ctx *core.Context) []string
func (*WebsocketServer) ToSymbolicValue ¶
func (*WebsocketServer) Upgrade ¶
func (s *WebsocketServer) Upgrade(rw *http_ns.ResponseWriter, r *http_ns.Request) (*WebsocketConnection, error)
func (*WebsocketServer) UpgradeGoValues ¶
func (s *WebsocketServer) UpgradeGoValues( rw http.ResponseWriter, r *http.Request, allowConnectionFn func(remoteAddrPort netaddr.RemoteAddrWithPort, remoteAddr netaddr.RemoteIpAddr, currentConns []*WebsocketConnection) error, ) (*WebsocketConnection, error)
UpgradeGoValues first determines if the connection is allowed by calling allowConnectionFn, and then upgrades the HTTP server connection to the WebSocket protocol. If allowConnectionFn is nil the connection is accepted if the number of connections on the IP is less or equal to DEFAULT_MAX_IP_WS_CONNS. The execution of allowConnectionFn should be very quick because the server is locked during the UpgradeGoValues call.