abla/websocket/event
Generated from source.
Import with import "abla/websocket/event".
Source: abla/websocket/event/entry.ab
WebSocketEventReply (class)
class WebSocketEventReply(
val kind: string,
val payload: string,
val close: bool
)
Describes the reply payload, frame kind and whether to close after sending it.
WebSocketEventRoute (class)
class WebSocketEventRoute(
val pattern: string,
val handler: (string, string, string) -> WebSocketEventReply
)
Pairs a path pattern with a message callback.
WebSocketEventRouter (class)
class WebSocketEventRouter(val routes: array<WebSocketEventRoute>)
Stores ordered path routes for event-driven WebSocket connections.
WebSocketEventOptions (class)
class WebSocketEventOptions(
val maximumConnections: int,
val maximumHeaderBytes: int,
val maximumMessageBytes: int,
val maximumPendingBytes: int,
val drainTimeoutMilliseconds: int
)
Configures connection, buffer and shutdown limits for an event server.
WebSocketEventServer (class)
resource class WebSocketEventServer(
val router: WebSocketEventRouter,
val listener: TcpListener,
val poller: SocketPoller,
val options: WebSocketEventOptions,
val descriptors: array<int>,
val inputs: array<string>,
val outputs: array<string>,
val outputOffsets: array<int>,
val upgraded: array<bool>,
val paths: array<string>,
val routeIndexes: array<int>,
val fragmentedOpcodes: array<int>,
val fragmentedPayloads: array<string>,
val closing: array<bool>,
var draining: bool,
var drainDeadlineMilliseconds: int,
var stopped: bool
)
Owns the listening socket, poller and state of each connected client.
WebSocketEventServer.drop (method)
fun drop(): void
Closes all active client sockets, the poller and the listener.
webSocketEventReply (fun)
fun webSocketEventReply(
payload: string,
kind: string = "text",
close: bool = false
): WebSocketEventReply
Creates a reply with a text frame and an open connection by default.
webSocketEventRouter (fun)
fun webSocketEventRouter(): WebSocketEventRouter
Creates a router with no registered routes.
WebSocketEventRouter.route (extension fun)
fun WebSocketEventRouter.route(
pattern: string,
handler: (string, string, string) -> WebSocketEventReply
): WebSocketEventRouter
Appends a route and returns the router.
WebSocketEventRouter.find (extension fun)
fun WebSocketEventRouter.find(path: string): int
Returns the first matching route index, or -1 when no pattern matches.
webSocketEventServer (fun)
fun webSocketEventServer(
router: WebSocketEventRouter,
address: Ipv4SocketAddress,
options: WebSocketEventOptions = webSocketEventOptions()
): WebSocketEventServer
Starts a nonblocking listener and returns the event server, whose listenError reports any setup failure.
WebSocketEventServer.activeConnections (extension fun)
fun WebSocketEventServer.activeConnections(): int
Returns the number of slots with an open socket.
WebSocketEventServer.findDescriptor (extension fun)
fun WebSocketEventServer.findDescriptor(descriptor: int): int
Returns the first slot containing the descriptor, or -1 if no slot contains it.
WebSocketEventServer.allocateSlot (extension fun)
fun WebSocketEventServer.allocateSlot(descriptor: int): int
Initializes a free or new slot for the descriptor and returns its index.
WebSocketEventServer.closeSlot (extension fun)
fun WebSocketEventServer.closeSlot(slot: int): void
Unwatches and closes an active slot, ignoring slots outside the table.
WebSocketEventServer.queue (extension fun)
fun WebSocketEventServer.queue(slot: int, bytes: string): bool
Queues bytes and enables write notifications, returning false when the slot is inactive or its output limit would be exceeded.
WebSocketEventServer.processHandshake (extension fun)
fun WebSocketEventServer.processHandshake(slot: int): void
Completes a buffered HTTP upgrade and closes the connection if the handshake or route is invalid.
WebSocketEventServer.handleMessage (extension fun)
fun WebSocketEventServer.handleMessage(
slot: int,
opcode: int,
payload: string
): void
Queues the matched handler's reply for a valid message or starts closing the client on invalid input.
WebSocketEventServer.processFrames (extension fun)
fun WebSocketEventServer.processFrames(slot: int): void
Consumes complete frames, handles fragmentation and control frames, and closes or queues a close for invalid input.
WebSocketEventServer.acceptReady (extension fun)
fun WebSocketEventServer.acceptReady(): void
Accepts ready clients until accept fails, the connection limit is reached or the server is draining.
WebSocketEventServer.readReady (extension fun)
fun WebSocketEventServer.readReady(slot: int): void
Reads and processes buffered input, closing on EOF, hard read errors or the configured input limit.
WebSocketEventServer.writeReady (extension fun)
fun WebSocketEventServer.writeReady(slot: int): void
Flushes queued bytes, retaining partial writes and closing on a hard error or completion of a closing reply.
WebSocketEventServer.step (extension fun)
fun WebSocketEventServer.step(timeoutMilliseconds: int = 1000): int
Waits for socket events for up to the given timeout and returns the number handled.
WebSocketEventServer.listenError (extension fun)
fun WebSocketEventServer.listenError(): int
0 while the server listens; otherwise the errno of the failed bind or listen (98 is an address already in use, 13 no permission, 22 an invalid address), or of the failed poller. A server like that never accepts: run() returns 1 at once.
WebSocketEventServer.run (extension fun)
fun WebSocketEventServer.run(): int
Services connections until shutdown, returning one if it cannot start listening and zero after stopping.
WebSocketEventServer.stop (extension fun)
fun WebSocketEventServer.stop(): void
Starts a graceful shutdown without waiting for clients to finish.
WebSocketEventServer.beginDrain (extension fun)
fun WebSocketEventServer.beginDrain(): void
Stops accepting, queues close frames and sets the drain deadline.
WebSocketEventServer.forceStop (extension fun)
fun WebSocketEventServer.forceStop(): void
Closes all active clients and marks the server stopped.
WebSocketEventServer.drain (extension fun)
fun WebSocketEventServer.drain(): int
Services closing connections until they finish or the deadline passes, then closes the remaining clients and returns zero.
WebSocketEventServer.stopNow (extension fun)
fun WebSocketEventServer.stopNow(): void
Closes active clients immediately and marks the server stopped.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.