Commit 043bc34b authored by Alex Hultman's avatar Alex Hultman

void *user -> WebSocketState<>, static_cast more and more

parent 88e2c794
......@@ -35,7 +35,7 @@ public:
template <bool isServer>
Group<isServer> &getDefaultGroup() {
return (Group<isServer> &) *this;
return static_cast<Group<isServer> &>(*this);
}
bool listen(int port, uS::TLS::Context sslContext = nullptr, int options = 0, Group<SERVER> *eh = nullptr);
......@@ -51,12 +51,12 @@ public:
#ifdef UWS_THREADSAFE
getLoop()->preCbData = nodeData;
getLoop()->preCb = [](void *nodeData) {
((uS::NodeData *) nodeData)->asyncMutex->lock();
static_cast<uS::NodeData *>(nodeData)->asyncMutex->lock();
};
getLoop()->postCbData = nodeData;
getLoop()->postCb = [](void *nodeData) {
((uS::NodeData *) nodeData)->asyncMutex->unlock();
static_cast<uS::NodeData *>(nodeData)->asyncMutex->unlock();
};
#endif
}
......@@ -88,8 +88,8 @@ public:
using Group<SERVER>::onHttpUpgrade;
using Group<SERVER>::onCancelledHttpRequest;
friend class WebSocket<true>;
friend class WebSocket<false>;
friend class WebSocket<SERVER>;
friend class WebSocket<CLIENT>;
};
}
......
......@@ -124,7 +124,7 @@ void WebSocket<isServer>::finalizeMessage(typename WebSocket<isServer>::Prepared
template <bool isServer>
uS::Socket *WebSocket<isServer>::onData(uS::Socket *s, char *data, size_t length) {
WebSocket<isServer> *webSocket = (WebSocket<isServer> *) s;
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(s);
webSocket->hasOutstandingPong = false;
if (!webSocket->isShuttingDown()) {
......@@ -177,7 +177,7 @@ void WebSocket<isServer>::close(int code, const char *message, size_t length) {
template <bool isServer>
void WebSocket<isServer>::onEnd(uS::Socket *s) {
WebSocket<isServer> *webSocket = (WebSocket<isServer> *) s;
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(s);
if (!webSocket->isShuttingDown()) {
getGroup<isServer>(webSocket)->removeWebSocket(webSocket);
......@@ -198,24 +198,23 @@ void WebSocket<isServer>::onEnd(uS::Socket *s) {
}
template <bool isServer>
bool WebSocket<isServer>::handleFragment(char *data, size_t length, unsigned int remainingBytes, int opCode, bool fin, void *user) {
WebSocket<isServer> *webSocket = (WebSocket<isServer> *) user;
bool WebSocket<isServer>::handleFragment(char *data, size_t length, unsigned int remainingBytes, int opCode, bool fin, WebSocketState<isServer> *webSocketState) {
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(webSocketState);
if (opCode < 3) {
if (!remainingBytes && fin && !webSocket->fragmentBuffer.length()) {
if (webSocket->compressionStatus == WebSocket<isServer>::CompressionStatus::COMPRESSED_FRAME) {
webSocket->compressionStatus = WebSocket<isServer>::CompressionStatus::ENABLED;
Hub *hub = ((Group<isServer> *) webSocket->nodeData)->hub;
data = hub->inflate(data, length);
if (!data) {
forceClose(user);
forceClose(webSocketState);
return true;
}
}
if (opCode == 1 && !WebSocketProtocol<isServer, WebSocket<isServer>>::isValidUtf8((unsigned char *) data, length)) {
forceClose(user);
forceClose(webSocketState);
return true;
}
......@@ -227,14 +226,13 @@ bool WebSocket<isServer>::handleFragment(char *data, size_t length, unsigned int
webSocket->fragmentBuffer.append(data, length);
if (!remainingBytes && fin) {
length = webSocket->fragmentBuffer.length();
if (webSocket->compressionStatus == WebSocket<isServer>::CompressionStatus::COMPRESSED_FRAME) {
webSocket->compressionStatus = WebSocket<isServer>::CompressionStatus::ENABLED;
Hub *hub = ((Group<isServer> *) webSocket->nodeData)->hub;
webSocket->fragmentBuffer.append("....");
data = hub->inflate((char *) webSocket->fragmentBuffer.data(), length);
if (!data) {
forceClose(user);
forceClose(webSocketState);
return true;
}
} else {
......@@ -242,7 +240,7 @@ bool WebSocket<isServer>::handleFragment(char *data, size_t length, unsigned int
}
if (opCode == 1 && !WebSocketProtocol<isServer, WebSocket<isServer>>::isValidUtf8((unsigned char *) data, length)) {
forceClose(user);
forceClose(webSocketState);
return true;
}
......
......@@ -31,12 +31,12 @@ protected:
static void onEnd(uS::Socket *s);
using uS::Socket::closeSocket;
static bool refusePayloadLength(void *user, uint64_t length) {
static bool refusePayloadLength(uint64_t length, WebSocketState<isServer> *webSocketState) {
return length > 16777216;
}
static bool setCompressed(void *user) {
WebSocket<isServer> *webSocket = (WebSocket<isServer> *) user;
static bool setCompressed(WebSocketState<isServer> *webSocketState) {
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(webSocketState);
if (webSocket->compressionStatus == WebSocket<isServer>::CompressionStatus::ENABLED) {
webSocket->compressionStatus = WebSocket<isServer>::CompressionStatus::COMPRESSED_FRAME;
......@@ -46,12 +46,12 @@ protected:
}
}
static void forceClose(void *user) {
WebSocket<isServer> *webSocket = (WebSocket<isServer> *) user;
static void forceClose(WebSocketState<isServer> *webSocketState) {
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(webSocketState);
webSocket->terminate();
}
static bool handleFragment(char *data, size_t length, unsigned int remainingBytes, int opCode, bool fin, void *user);
static bool handleFragment(char *data, size_t length, unsigned int remainingBytes, int opCode, bool fin, WebSocketState<isServer> *webSocketState);
public:
struct PreparedMessage {
......
......@@ -120,7 +120,7 @@ private:
}
wState->state.lastFin = isFin(src);
if (Impl::refusePayloadLength(wState, payLength)) {
if (Impl::refusePayloadLength(payLength, wState)) {
Impl::forceClose(wState);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment