diff options
author | Dmitry Ilyin <dima@doty.ru> | 2022-09-12 22:16:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-12 22:16:56 +0300 |
commit | e8313084f9e8b064433cb10eb9a79bf87407fab6 (patch) | |
tree | 9a98db8cb69dc07017512e0f28f9eb9bfe3b3a5c /http-internal.h | |
parent | bb41229ff4dbd62084994c6b0b2052a321fd0ccf (diff) | |
download | libevent-e8313084f9e8b064433cb10eb9a79bf87407fab6.tar.gz |
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.
Implementation was inspired by modified Libevent source code in ipush project
[1].
[1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable
Also, WebSocket-based chat server was added as a sample.
Diffstat (limited to 'http-internal.h')
-rw-r--r-- | http-internal.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/http-internal.h b/http-internal.h index 705daba2..976a1198 100644 --- a/http-internal.h +++ b/http-internal.h @@ -124,6 +124,9 @@ struct evhttp_cb { /* both the http server as well as the rpc system need to queue connections */ TAILQ_HEAD(evconq, evhttp_connection); +/* WebSockets connections */ +TAILQ_HEAD(evwsq, evws_connection); + /* each bound socket is stored in one of these */ struct evhttp_bound_socket { TAILQ_ENTRY(evhttp_bound_socket) next; @@ -151,8 +154,10 @@ struct evhttp { TAILQ_HEAD(httpcbq, evhttp_cb) callbacks; - /* All live connections on this host. */ + /* All live HTTP connections on this host. */ struct evconq connections; + /* All live WebSockets sessions on this host. */ + struct evwsq ws_sessions; int connection_max; int connection_cnt; @@ -221,6 +226,8 @@ void evhttp_start_write_(struct evhttp_connection *); void evhttp_response_code_(struct evhttp_request *, int, const char *); void evhttp_send_page_(struct evhttp_request *, struct evbuffer *); +struct bufferevent * evhttp_start_ws_(struct evhttp_request *req); + /* [] has been stripped */ #define _EVHTTP_URI_HOST_HAS_BRACKETS 0x02 |