From 1cb0fc6ab3f05e37f8c4c0bf5549b320c8b89078 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 29 Jan 2018 00:47:50 -0800 Subject: Changes related to debugging an issue. It may not have had as much to do with low-level protocol details, and a lot of this can be reverted, but I can't revert it right now. I'll look it over later in the week. --- src/unstable/protocolwebsocket.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/unstable/protocolwebsocket.cpp') diff --git a/src/unstable/protocolwebsocket.cpp b/src/unstable/protocolwebsocket.cpp index 9200904..576249c 100644 --- a/src/unstable/protocolwebsocket.cpp +++ b/src/unstable/protocolwebsocket.cpp @@ -9,6 +9,7 @@ #include "bu/protocolwebsocket.h" #include "bu/sio.h" +#include "bu/fmt.h" #include "bu/client.h" #include "bu/membuf.h" @@ -16,6 +17,8 @@ #include "bu/sha1.h" #include "bu/json.h" +#include "bu/mutexlocker.h" + #include Bu::ProtocolWebSocket::ProtocolWebSocket() : @@ -25,11 +28,17 @@ Bu::ProtocolWebSocket::ProtocolWebSocket() : Bu::ProtocolWebSocket::~ProtocolWebSocket() { + mClient.lock(); + printf("ProtocolWebSocket::~ProtocolWebSocket(): Clearing pClient (%p)\n", (void *)this->pClient ); + this->pClient = NULL; + mClient.unlock(); } void Bu::ProtocolWebSocket::onNewConnection( Bu::Client *pClient ) { + mClient.lock(); this->pClient = pClient; + mClient.unlock(); } void Bu::ProtocolWebSocket::onNewData( Bu::Client * /*pClient*/ ) @@ -95,6 +104,9 @@ void Bu::ProtocolWebSocket::writeMessage( const Bu::String &sData, } Bu::println(""); */ + Bu::MutexLocker l( mClient ); + if( pClient == NULL ) + return; pClient->write( cHeader, idx ); pClient->write( sData ); } @@ -108,18 +120,21 @@ bool Bu::ProtocolWebSocket::stateProtoId() Bu::StringList lChunks = sLine.split(' '); if( lChunks.getSize() != 3 ) { + Bu::MutexLocker l( mClient ); pClient->disconnect(); return false; } Bu::StringList::iterator i = lChunks.begin(); if( *i != "GET" ) { + Bu::MutexLocker l( mClient ); pClient->disconnect(); return false; } sPath = *(++i); if( *(++i) != "HTTP/1.1" ) { + Bu::MutexLocker l( mClient ); pClient->disconnect(); return false; } @@ -147,6 +162,7 @@ bool Bu::ProtocolWebSocket::stateHandshake() int iPos = sLine.findIdx(':'); if( iPos < 0 ) { + Bu::MutexLocker l( mClient ); pClient->disconnect(); return false; } @@ -183,6 +199,7 @@ bool Bu::ProtocolWebSocket::readHttpHdrLine( Bu::String &sLine ) bool Bu::ProtocolWebSocket::processHeaders() { + Bu::MutexLocker l( mClient ); if( !headerMatch("Connection", "Upgrade") || !headerMatch("Upgrade", "websocket") || !headerMatch("Sec-WebSocket-Version", "13") ) @@ -209,7 +226,7 @@ bool Bu::ProtocolWebSocket::processHeaders() sum.writeResult( bOut ); bOut.stop(); - Bu::println("accept: %1").arg( mbOut.getString() ); +// Bu::println("accept: %1").arg( mbOut.getString() ); pClient->write("HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" @@ -290,8 +307,8 @@ bool Bu::ProtocolWebSocket::parseMessage() } } - Bu::println(""); - Bu::println("Data: >>%1<<").arg( sData ); +// Bu::println(""); +// Bu::println("Data: >>%1<<").arg( sData ); onNewMessage( sData, eOp ); -- cgit v1.2.3