|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef IZ_WSSERVER_H
- #define IZ_WSSERVER_H
-
- #include <sys/stat.h>
- #include "libwebsockets.h"
- #include <string.h>
- #include "../../IZ_common.h"
- #include "../../IZ_config.h"
- #include "../core/IZ_websocket.h"
-
- #ifndef S_ISDIR
- #define S_ISDIR(s) s & S_IFDIR
- #endif
-
- /* one of these is created for each client connecting to us */
- typedef struct IZ_WSServerSessionData {
- struct IZ_WSServerSessionData* pss_list;
- struct lws* wsi;
- u32 tail;
- u8 culled: 1;
- } IZ_WSServerSessionData;
-
- /* one of these is created for each vhost our protocol is used with */
- typedef struct {
- struct lws_context *context;
- struct lws_vhost *vhost;
- const struct lws_protocols *protocol;
- IZ_WSServerSessionData *pss_list; /* linked-list of live pss*/
- struct lws_ring *ring; /* ringbuffer holding unsent messages */
- u16* port;
- const void* app;
- } IZ_WSServerVHostData;
-
- typedef struct {
- u16 port;
- char server_name[64];
- } IZ_WSServerInitializeParams;
-
- typedef struct {
- IZ_WSServerInitializeParams config;
- void* userdata;
- IZ_Websocket ws;
- } IZ_WSServerState;
-
- static IZ_WSServerState IZ_DEFAULT_STATE = {
- .config = {
- .port = 42069,
- .server_name = NULL,
- },
- .userdata = NULL,
- .ws = {
- .interrupted = false,
- .context = NULL,
- },
- };
-
- IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState*, void*, const char*, u8, const char**);
-
- IZ_ProcedureResult IZ_WSServerHandle(IZ_WSServerState*);
-
- void IZ_WSServerTeardown(IZ_WSServerState*);
-
- void IZ_WSServerCancelService(IZ_WSServerState*);
-
- IZ_ProcedureResult IZ_WSServerProtocolInitialize(struct lws*, void*);
-
- void IZ_WSServerProtocolTeardown(struct lws*);
-
- IZ_ProcedureResult IZ_WSServerWritable(struct lws*, IZ_WSServerSessionData*);
-
- IZ_ProcedureResult IZ_WSServerOnReceive(struct lws*, void*, size_t);
-
- void IZ_WSServerOnOpen(struct lws*, IZ_WSServerSessionData*);
-
- void IZ_WSServerOnClose(struct lws*, IZ_WSServerSessionData*);
-
- #endif
|