Refactor using new uSockets API

This commit is contained in:
Alex Hultman
2019-01-25 14:15:40 +01:00
parent e14461e253
commit d331ec3e45
10 changed files with 107 additions and 198 deletions
+5 -8
View File
@@ -31,19 +31,16 @@ struct WebSocket : AsyncSocket<SSL> {
template <bool> friend struct TemplatedApp;
private:
typedef AsyncSocket<SSL> Super;
using SOCKET_TYPE = typename StaticDispatch<SSL>::SOCKET_TYPE;
using SOCKET_CONTEXT_TYPE = typename StaticDispatch<SSL>::SOCKET_CONTEXT_TYPE;
using StaticDispatch<SSL>::static_dispatch;
void *init(bool perMessageDeflate, bool slidingCompression, std::string &&backpressure) {
new (static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this)) WebSocketData(perMessageDeflate, slidingCompression, std::move(backpressure));
new (us_new_socket_ext(SSL, (us_new_socket_t *) this)) WebSocketData(perMessageDeflate, slidingCompression, std::move(backpressure));
return this;
}
public:
/* Returns pointer to the per socket user data */
void *getUserData() {
WebSocketData *webSocketData = (WebSocketData *) static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this);
WebSocketData *webSocketData = (WebSocketData *) us_new_socket_ext(SSL, (us_new_socket_t *) this);
/* We just have it overallocated by sizeof type */
return (webSocketData + 1);
}
@@ -92,7 +89,7 @@ public:
/* Send websocket close frame, emit close event, send FIN if successful */
void close(int code, std::string_view message = {}) {
/* Check if we already called this one */
WebSocketData *webSocketData = (WebSocketData *) static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this);
WebSocketData *webSocketData = (WebSocketData *) us_new_socket_ext(SSL, (us_new_socket_t *) this);
if (webSocketData->isShuttingDown) {
return;
}
@@ -118,8 +115,8 @@ public:
}
/* Emit close event */
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) static_dispatch(us_ssl_socket_context_ext, us_socket_context_ext)(
(SOCKET_CONTEXT_TYPE *) static_dispatch(us_ssl_socket_get_context, us_socket_get_context)((SOCKET_TYPE *) this)
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_new_socket_context_ext(SSL,
(us_new_socket_context_t *) us_new_socket_context(SSL, (us_new_socket_t *) this)
);
if (webSocketContextData->closeHandler) {
webSocketContextData->closeHandler(this, code, message);