This library is built off of the socket library and provides some generic support for socket servers. The current implementation is asycronous, single-threaded and is select-based and does not use the poll() function.
: OnClose! ( xt -- )
This word stores a new closure behavior for the socket connection.
: OnRead! ( xt -- )
This word stores a new read behavior for the socket connection.
: OnWrite! ( xt -- )
This word stores a new write behavior for the socket connection.
: OnConnect! ( xt -- )
This word stores a new connection behavior for the socket.
: servdata ( -- addr )
Returns a pointer to the user-defined data area associated with every request. The size of this user area is specified by the server.
: servsock ( -- sock )
Returns the socket that the event has been triggered on.
: close-client ( -- )
Closes the current socket at frees up the memory from the server.
: serv-vecselect ( server -- )
Selects the server for vector behavior. Directly after this word is called, default behaviors for the entire server can be specified.
: sockserver ( datasize p <name> -- )
This word defines a socket server on port "p" and the size of the user-defined data area per client.
: serv-init ( server -- )
Initializes the server and starts listening for requests.
: serv-close ( server -- )
Closes the server - open requests are still able to execute, though.
: serv-poll ( server -- )
The meat-and-potatoes function of the socket server. This word will deal with all incoming socket requests, poll through and process existing socket requests, and cleanup after closed requests.
256 8000 sockserver test test serv-vecselect :noname servdata 256 servsock sock-read servdata swap type ; onread! test serv-init : demo begin test serv-poll 10 ms key? until ;