diff --git a/README.md b/README.md index a1927c21..c529100b 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ webSocket.setOnMessageCallback( const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Message) + if (messageType == ix::WebSocketMessageType::Message) { std::cout << str << std::endl; } @@ -77,7 +77,7 @@ server.setOnConnectionCallback( const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; @@ -96,7 +96,7 @@ server.setOnConnectionCallback( std::cerr << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { // For an echo server, we just send back to the client whatever was received by the server // All connected clients are available in an std::set. See the broadcast cpp example. @@ -301,10 +301,10 @@ If the connection was closed and sending failed, the return value will be set to `getReadyState()` returns the state of the connection. There are 4 possible states. -1. WebSocket_ReadyState_Connecting - The connection is not yet open. -2. WebSocket_ReadyState_Open - The connection is open and ready to communicate. -3. WebSocket_ReadyState_Closing - The connection is in the process of closing. -4. WebSocket_MessageType_Close - The connection is closed or could not be opened. +1. ReadyState::Connecting - The connection is not yet open. +2. ReadyState::Open - The connection is open and ready to communicate. +3. ReadyState::Closing - The connection is in the process of closing. +4. ReadyState::Closed - The connection is closed or could not be opened. ### Open and Close notifications @@ -319,7 +319,7 @@ webSocket.setOnMessageCallback( const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cout << "send greetings" << std::endl; @@ -330,7 +330,7 @@ webSocket.setOnMessageCallback( std::cout << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { std::cout << "disconnected" << std::endl; @@ -345,7 +345,7 @@ webSocket.setOnMessageCallback( ### Error notification -A message will be fired when there is an error with the connection. The message type will be `ix::WebSocket_MessageType_Error`. Multiple fields will be available on the event to describe the error. +A message will be fired when there is an error with the connection. The message type will be `ix::WebSocketMessageType::Error`. Multiple fields will be available on the event to describe the error. ``` webSocket.setOnMessageCallback( @@ -356,7 +356,7 @@ webSocket.setOnMessageCallback( const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Error) + if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Error: " << error.reason << std::endl; @@ -396,8 +396,8 @@ webSocket.setOnMessageCallback( const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Ping || - messageType == ix::WebSocket_MessageType_Pong) + if (messageType == ix::WebSocketMessageType::Ping || + messageType == ix::WebSocketMessageType::Pong) { std::cout << "pong data: " << str << std::endl; } diff --git a/ixwebsocket/IXHttpClient.cpp b/ixwebsocket/IXHttpClient.cpp index ed612218..5a295489 100644 --- a/ixwebsocket/IXHttpClient.cpp +++ b/ixwebsocket/IXHttpClient.cpp @@ -52,7 +52,7 @@ namespace ix { std::stringstream ss; ss << "Cannot parse url: " << url; - return std::make_tuple(code, HttpErrorCode_UrlMalformed, + return std::make_tuple(code, HttpErrorCode::UrlMalformed, headers, payload, ss.str(), uploadSize, downloadSize); } @@ -63,7 +63,7 @@ namespace ix if (!_socket) { - return std::make_tuple(code, HttpErrorCode_CannotCreateSocket, + return std::make_tuple(code, HttpErrorCode::CannotCreateSocket, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -116,7 +116,7 @@ namespace ix { std::stringstream ss; ss << "Cannot connect to url: " << url; - return std::make_tuple(code, HttpErrorCode_CannotConnect, + return std::make_tuple(code, HttpErrorCode::CannotConnect, headers, payload, ss.str(), uploadSize, downloadSize); } @@ -142,7 +142,7 @@ namespace ix if (!_socket->writeBytes(req, isCancellationRequested)) { std::string errorMsg("Cannot send request"); - return std::make_tuple(code, HttpErrorCode_SendError, + return std::make_tuple(code, HttpErrorCode::SendError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -156,7 +156,7 @@ namespace ix if (!lineValid) { std::string errorMsg("Cannot retrieve status line"); - return std::make_tuple(code, HttpErrorCode_CannotReadStatusLine, + return std::make_tuple(code, HttpErrorCode::CannotReadStatusLine, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -171,7 +171,7 @@ namespace ix if (sscanf(line.c_str(), "HTTP/1.1 %d", &code) != 1) { std::string errorMsg("Cannot parse response code from status line"); - return std::make_tuple(code, HttpErrorCode_MissingStatus, + return std::make_tuple(code, HttpErrorCode::MissingStatus, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -183,7 +183,7 @@ namespace ix if (!headersValid) { std::string errorMsg("Cannot parse http headers"); - return std::make_tuple(code, HttpErrorCode_HeaderParsingError, + return std::make_tuple(code, HttpErrorCode::HeaderParsingError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -194,7 +194,7 @@ namespace ix if (headers.find("Location") == headers.end()) { std::string errorMsg("Missing location header for redirect"); - return std::make_tuple(code, HttpErrorCode_MissingLocation, + return std::make_tuple(code, HttpErrorCode::MissingLocation, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -203,7 +203,7 @@ namespace ix { std::stringstream ss; ss << "Too many redirects: " << redirects; - return std::make_tuple(code, HttpErrorCode_TooManyRedirects, + return std::make_tuple(code, HttpErrorCode::TooManyRedirects, headers, payload, ss.str(), uploadSize, downloadSize); } @@ -215,7 +215,7 @@ namespace ix if (verb == "HEAD") { - return std::make_tuple(code, HttpErrorCode_Ok, + return std::make_tuple(code, HttpErrorCode::Ok, headers, payload, std::string(), uploadSize, downloadSize); } @@ -236,7 +236,7 @@ namespace ix if (!chunkResult.first) { errorMsg = "Cannot read chunk"; - return std::make_tuple(code, HttpErrorCode_ChunkReadError, + return std::make_tuple(code, HttpErrorCode::ChunkReadError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -254,7 +254,7 @@ namespace ix if (!lineResult.first) { - return std::make_tuple(code, HttpErrorCode_ChunkReadError, + return std::make_tuple(code, HttpErrorCode::ChunkReadError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -281,7 +281,7 @@ namespace ix if (!chunkResult.first) { errorMsg = "Cannot read chunk"; - return std::make_tuple(code, HttpErrorCode_ChunkReadError, + return std::make_tuple(code, HttpErrorCode::ChunkReadError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -292,7 +292,7 @@ namespace ix if (!lineResult.first) { - return std::make_tuple(code, HttpErrorCode_ChunkReadError, + return std::make_tuple(code, HttpErrorCode::ChunkReadError, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -307,7 +307,7 @@ namespace ix else { std::string errorMsg("Cannot read http body"); - return std::make_tuple(code, HttpErrorCode_CannotReadBody, + return std::make_tuple(code, HttpErrorCode::CannotReadBody, headers, payload, errorMsg, uploadSize, downloadSize); } @@ -321,14 +321,14 @@ namespace ix if (!gzipInflate(payload, decompressedPayload)) { std::string errorMsg("Error decompressing payload"); - return std::make_tuple(code, HttpErrorCode_Gzip, + return std::make_tuple(code, HttpErrorCode::Gzip, headers, payload, errorMsg, uploadSize, downloadSize); } payload = decompressedPayload; } - return std::make_tuple(code, HttpErrorCode_Ok, + return std::make_tuple(code, HttpErrorCode::Ok, headers, payload, std::string(), uploadSize, downloadSize); } diff --git a/ixwebsocket/IXHttpClient.h b/ixwebsocket/IXHttpClient.h index 191893c1..66f621cb 100644 --- a/ixwebsocket/IXHttpClient.h +++ b/ixwebsocket/IXHttpClient.h @@ -19,23 +19,23 @@ namespace ix { - enum HttpErrorCode + enum class HttpErrorCode { - HttpErrorCode_Ok = 0, - HttpErrorCode_CannotConnect = 1, - HttpErrorCode_Timeout = 2, - HttpErrorCode_Gzip = 3, - HttpErrorCode_UrlMalformed = 4, - HttpErrorCode_CannotCreateSocket = 5, - HttpErrorCode_SendError = 6, - HttpErrorCode_ReadError = 7, - HttpErrorCode_CannotReadStatusLine = 8, - HttpErrorCode_MissingStatus = 9, - HttpErrorCode_HeaderParsingError = 10, - HttpErrorCode_MissingLocation = 11, - HttpErrorCode_TooManyRedirects = 12, - HttpErrorCode_ChunkReadError = 13, - HttpErrorCode_CannotReadBody = 14 + Ok = 0, + CannotConnect = 1, + Timeout = 2, + Gzip = 3, + UrlMalformed = 4, + CannotCreateSocket = 5, + SendError = 6, + ReadError = 7, + CannotReadStatusLine = 8, + MissingStatus = 9, + HeaderParsingError = 10, + MissingLocation = 11, + TooManyRedirects = 12, + ChunkReadError = 13, + CannotReadBody = 14 }; using HttpResponse = std::tuple lock(_closeDataMutex); _onCloseCallback(_closeCode, _closeReason, _closeWireSize, _closeRemote); @@ -226,7 +226,7 @@ namespace ix _closeRemote = false; } - _readyState = readyStateValue; + _readyState = readyState; } void WebSocketTransport::setOnCloseCallback(const OnCloseCallback& onCloseCallback) @@ -262,9 +262,9 @@ namespace ix return now - _closingTimePoint > std::chrono::milliseconds(kClosingMaximumWaitingDelayInMs); } - WebSocketTransport::PollPostTreatment WebSocketTransport::poll() + WebSocketTransport::PollResult WebSocketTransport::poll() { - if (_readyState == OPEN) + if (_readyState == ReadyState::OPEN) { // if (1) ping timeout is enabled and (2) duration since last received // ping response (PONG) exceeds the maximum delay, then close the connection @@ -284,7 +284,7 @@ namespace ix // No timeout if state is not OPEN, otherwise computed // pingIntervalOrTimeoutGCD (equals to -1 if no ping and no ping timeout are set) - int lastingTimeoutDelayInMs = (_readyState != OPEN) ? 0 : _pingIntervalOrTimeoutGCDSecs; + int lastingTimeoutDelayInMs = (_readyState != ReadyState::OPEN) ? 0 : _pingIntervalOrTimeoutGCDSecs; if (_pingIntervalOrTimeoutGCDSecs > 0) { @@ -319,7 +319,7 @@ namespace ix if (result == PollResultType::Error) { _socket->close(); - setReadyState(CLOSED); + setReadyState(ReadyState::CLOSED); break; } else if (result == PollResultType::ReadyForWrite) @@ -345,7 +345,7 @@ namespace ix _socket->close(); - return CHECK_OR_RAISE_ABNORMAL_CLOSE_AFTER_DISPATCH; + return PollResult::AbnormalClose; } else { @@ -364,15 +364,15 @@ namespace ix _socket->close(); } - if (_readyState == CLOSING && closingDelayExceeded()) + if (_readyState == ReadyState::CLOSING && closingDelayExceeded()) { _rxbuf.clear(); // close code and reason were set when calling close() _socket->close(); - setReadyState(CLOSED); + setReadyState(ReadyState::CLOSED); } - return NONE; + return PollResult::Succeeded; } bool WebSocketTransport::isSendBufferEmpty() const @@ -434,7 +434,7 @@ namespace ix // | Payload Data continued ... | // +---------------------------------------------------------------+ // - void WebSocketTransport::dispatch(WebSocketTransport::PollPostTreatment pollPostTreatment, + void WebSocketTransport::dispatch(WebSocketTransport::PollResult pollResult, const OnMessageCallback& onMessageCallback) { while (true) @@ -521,7 +521,7 @@ namespace ix // if (ws.fin && _chunks.empty()) { - emitMessage(MSG, + emitMessage(MessageKind::MSG, std::string(_rxbuf.begin()+ws.header_size, _rxbuf.begin()+ws.header_size+(size_t) ws.N), ws, @@ -541,12 +541,12 @@ namespace ix _rxbuf.begin()+ws.header_size+(size_t)ws.N)); if (ws.fin) { - emitMessage(MSG, getMergedChunks(), ws, onMessageCallback); + emitMessage(MessageKind::MSG, getMergedChunks(), ws, onMessageCallback); _chunks.clear(); } else { - emitMessage(FRAGMENT, std::string(), ws, onMessageCallback); + emitMessage(MessageKind::FRAGMENT, std::string(), ws, onMessageCallback); } } } @@ -564,7 +564,7 @@ namespace ix sendData(wsheader_type::PONG, pingData, compress); } - emitMessage(PING, pingData, ws, onMessageCallback); + emitMessage(MessageKind::PING, pingData, ws, onMessageCallback); } else if (ws.opcode == wsheader_type::PONG) { @@ -575,7 +575,7 @@ namespace ix std::lock_guard lck(_lastReceivePongTimePointMutex); _lastReceivePongTimePoint = std::chrono::steady_clock::now(); - emitMessage(PONG, pongData, ws, onMessageCallback); + emitMessage(MessageKind::PONG, pongData, ws, onMessageCallback); } else if (ws.opcode == wsheader_type::CLOSE) { @@ -605,7 +605,7 @@ namespace ix } // We receive a CLOSE frame from remote and are NOT the ones who triggered the close - if (_readyState != CLOSING) + if (_readyState != ReadyState::CLOSING) { // send back the CLOSE frame sendCloseFrame(code, reason); @@ -646,18 +646,18 @@ namespace ix // if an abnormal closure was raised in poll, and nothing else triggered a CLOSED state in // the received and processed data then close the connection - if (pollPostTreatment == CHECK_OR_RAISE_ABNORMAL_CLOSE_AFTER_DISPATCH) + if (pollResult == PollResult::AbnormalClose) { _rxbuf.clear(); // if we previously closed the connection (CLOSING state), then set state to CLOSED (code/reason were set before) - if (_readyState == CLOSING) + if (_readyState == ReadyState::CLOSING) { _socket->close(); - setReadyState(CLOSED); + setReadyState(ReadyState::CLOSED); } // if we weren't closing, then close using abnormal close code and message - else if (_readyState != CLOSED) + else if (_readyState != ReadyState::CLOSED) { closeSocketAndSwitchToClosedState(kAbnormalCloseCode, kAbnormalCloseMessage, 0, false); } @@ -692,7 +692,7 @@ namespace ix size_t wireSize = message.size(); // When the RSV1 bit is 1 it means the message is compressed - if (_enablePerMessageDeflate && ws.rsv1 && messageKind != FRAGMENT) + if (_enablePerMessageDeflate && ws.rsv1 && messageKind != MessageKind::FRAGMENT) { std::string decompressedMessage; bool success = _perMessageDeflate.decompress(message, decompressedMessage); @@ -719,7 +719,7 @@ namespace ix bool compress, const OnProgressCallback& onProgressCallback) { - if (_readyState != OPEN) + if (_readyState != ReadyState::OPEN) { return WebSocketSendInfo(); } @@ -945,7 +945,7 @@ namespace ix { _socket->close(); - setReadyState(CLOSED); + setReadyState(ReadyState::CLOSED); break; } else @@ -988,14 +988,14 @@ namespace ix _closeWireSize = closeWireSize; _closeRemote = remote; } - setReadyState(CLOSED); + setReadyState(ReadyState::CLOSED); } void WebSocketTransport::close(uint16_t code, const std::string& reason, size_t closeWireSize, bool remote) { _requestInitCancellation = true; - if (_readyState == CLOSING || _readyState == CLOSED) return; + if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return; sendCloseFrame(code, reason); { @@ -1009,7 +1009,7 @@ namespace ix std::lock_guard lock(_closingTimePointMutex); _closingTimePoint = std::chrono::steady_clock::now(); } - setReadyState(CLOSING); + setReadyState(ReadyState::CLOSING); // wake up the poll, but do not close yet _socket->wakeUpFromPoll(Socket::kSendRequest); diff --git a/ixwebsocket/IXWebSocketTransport.h b/ixwebsocket/IXWebSocketTransport.h index c732a803..db569967 100644 --- a/ixwebsocket/IXWebSocketTransport.h +++ b/ixwebsocket/IXWebSocketTransport.h @@ -40,7 +40,7 @@ namespace ix class WebSocketTransport { public: - enum ReadyStateValues + enum class ReadyState { CLOSING, CLOSED, @@ -48,7 +48,7 @@ namespace ix OPEN }; - enum MessageKind + enum class MessageKind { MSG, PING, @@ -56,10 +56,10 @@ namespace ix FRAGMENT }; - enum PollPostTreatment + enum class PollResult { - NONE, - CHECK_OR_RAISE_ABNORMAL_CLOSE_AFTER_DISPATCH + Succeeded, + AbnormalClose }; using OnMessageCallback = std::function _socket; // Hold the state of the connection (OPEN, CLOSED, etc...) - std::atomic _readyState; + std::atomic _readyState; OnCloseCallback _onCloseCallback; uint16_t _closeCode; diff --git a/test/IXWebSocketPingTest.cpp b/test/IXWebSocketPingTest.cpp index 0dc55f66..c30a99bd 100644 --- a/test/IXWebSocketPingTest.cpp +++ b/test/IXWebSocketPingTest.cpp @@ -43,7 +43,7 @@ namespace bool WebSocketClient::isReady() const { - return _webSocket.getReadyState() == ix::WebSocket_ReadyState_Open; + return _webSocket.getReadyState() == ix::ReadyState::Open; } void WebSocketClient::stop() @@ -88,30 +88,30 @@ namespace const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("client connected"); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("client disconnected"); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "Error ! " << error.reason; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { ss << "Received pong message " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { ss << "Received ping message " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { // too many messages to log } @@ -145,7 +145,7 @@ namespace const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { Logger() << "New server connection"; Logger() << "id: " << connectionState->getId(); @@ -156,16 +156,16 @@ namespace Logger() << it.first << ": " << it.second; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("Server closed connection"); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { log("Server received a ping"); receivedPingMessages++; } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { // to many messages to log for(auto client: server.getClients()) diff --git a/test/IXWebSocketPingTimeoutTest.cpp b/test/IXWebSocketPingTimeoutTest.cpp index 80174e35..4b744b20 100644 --- a/test/IXWebSocketPingTimeoutTest.cpp +++ b/test/IXWebSocketPingTimeoutTest.cpp @@ -52,12 +52,12 @@ namespace bool WebSocketClient::isReady() const { - return _webSocket.getReadyState() == ix::WebSocket_ReadyState_Open; + return _webSocket.getReadyState() == ix::ReadyState::Open; } bool WebSocketClient::isClosed() const { - return _webSocket.getReadyState() == ix::WebSocket_ReadyState_Closed; + return _webSocket.getReadyState() == ix::ReadyState::Closed; } void WebSocketClient::stop() @@ -97,12 +97,12 @@ namespace const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("client connected"); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("client disconnected"); @@ -112,24 +112,24 @@ namespace } } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "Error ! " << error.reason; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { _receivedPongMessages++; ss << "Received pong message " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { ss << "Received ping message " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { ss << "Received message " << str; log(ss.str()); @@ -174,7 +174,7 @@ namespace const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { Logger() << "New server connection"; Logger() << "id: " << connectionState->getId(); @@ -185,11 +185,11 @@ namespace Logger() << it.first << ": " << it.second; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("Server closed connection"); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { log("Server received a ping"); receivedPingMessages++; diff --git a/test/IXWebSocketServerTest.cpp b/test/IXWebSocketServerTest.cpp index 8a2c2adb..9f1acaed 100644 --- a/test/IXWebSocketServerTest.cpp +++ b/test/IXWebSocketServerTest.cpp @@ -50,7 +50,7 @@ namespace ix const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { Logger() << "New connection"; connectionState->computeId(); @@ -64,11 +64,11 @@ namespace ix connectionId = connectionState->getId(); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { Logger() << "Closed connection"; } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { for (auto&& client : server.getClients()) { diff --git a/test/IXWebSocketTestConnectionDisconnection.cpp b/test/IXWebSocketTestConnectionDisconnection.cpp index c9bc0d64..003f60d0 100644 --- a/test/IXWebSocketTestConnectionDisconnection.cpp +++ b/test/IXWebSocketTestConnectionDisconnection.cpp @@ -60,33 +60,33 @@ namespace const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("cmd_websocket_satori_chat: connected !"); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("cmd_websocket_satori_chat: disconnected !"); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "cmd_websocket_satori_chat: Error! "; ss << error.reason; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { log("cmd_websocket_satori_chat: received message.!"); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { log("cmd_websocket_satori_chat: received ping message.!"); } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { log("cmd_websocket_satori_chat: received pong message.!"); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { log("cmd_websocket_satori_chat: received fragment.!"); } diff --git a/test/cmd_websocket_chat.cpp b/test/cmd_websocket_chat.cpp index 86890832..2b68e529 100644 --- a/test/cmd_websocket_chat.cpp +++ b/test/cmd_websocket_chat.cpp @@ -87,7 +87,7 @@ namespace bool WebSocketChat::isReady() const { - return _webSocket.getReadyState() == ix::WebSocket_ReadyState_Open; + return _webSocket.getReadyState() == ix::ReadyState::Open; } void WebSocketChat::stop() @@ -122,21 +122,21 @@ namespace const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { ss << "cmd_websocket_chat: user " << _user << " Connected !"; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "cmd_websocket_chat: user " << _user << " disconnected !"; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { auto result = decodeMessage(str); @@ -159,20 +159,20 @@ namespace << _user << " > "; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "cmd_websocket_chat: Error ! " << error.reason; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { log("cmd_websocket_chat: received ping message"); } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { log("cmd_websocket_chat: received pong message"); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { log("cmd_websocket_chat: received message fragment"); } @@ -228,7 +228,7 @@ namespace const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { Logger() << "New connection"; Logger() << "id: " << connectionState->getId(); @@ -239,11 +239,11 @@ namespace Logger() << it.first << ": " << it.second; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { log("Closed connection"); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { for (auto&& client : server.getClients()) { diff --git a/ws/IXSentryClient.cpp b/ws/IXSentryClient.cpp index 5b26abf9..d89d0b0f 100644 --- a/ws/IXSentryClient.cpp +++ b/ws/IXSentryClient.cpp @@ -162,7 +162,7 @@ namespace ix std::cerr << "Download size: " << downloadSize << std::endl; std::cerr << "Status: " << statusCode << std::endl; - if (errorCode != HttpErrorCode_Ok) + if (errorCode != HttpErrorCode::Ok) { std::cerr << "error message: " << errorMsg << std::endl; } diff --git a/ws/ixcobra/IXCobraConnection.cpp b/ws/ixcobra/IXCobraConnection.cpp index dc5523c0..f2ac81d4 100644 --- a/ws/ixcobra/IXCobraConnection.cpp +++ b/ws/ixcobra/IXCobraConnection.cpp @@ -100,14 +100,14 @@ namespace ix CobraConnection::invokeTrafficTrackerCallback(wireSize, true); std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { invokeEventCallback(ix::CobraConnection_EventType_Open, std::string(), openInfo.headers); sendHandshakeMessage(); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { _authenticated = false; @@ -117,7 +117,7 @@ namespace ix invokeEventCallback(ix::CobraConnection_EventType_Closed, ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { Json::Value data; Json::Reader reader; @@ -187,7 +187,7 @@ namespace ix invokeErrorCallback("Un-handled message type", str); } } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Connection error: " << error.reason << std::endl; @@ -384,7 +384,7 @@ namespace ix bool CobraConnection::isConnected() const { - return _webSocket->getReadyState() == ix::WebSocket_ReadyState_Open; + return _webSocket->getReadyState() == ix::ReadyState::Open; } bool CobraConnection::isAuthenticated() const diff --git a/ws/snake/IXSnakeServer.cpp b/ws/snake/IXSnakeServer.cpp index 93c514e5..a0783f30 100644 --- a/ws/snake/IXSnakeServer.cpp +++ b/ws/snake/IXSnakeServer.cpp @@ -65,7 +65,7 @@ namespace snake const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; std::cerr << "id: " << state->getId() << std::endl; @@ -86,13 +86,13 @@ namespace snake std::cerr << "Cannot connect to redis host" << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { std::cerr << "Closed connection" << " code " << closeInfo.code << " reason " << closeInfo.reason << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Connection error: " << error.reason << std::endl; @@ -101,11 +101,11 @@ namespace snake ss << "HTTP Status: " << error.http_status << std::endl; std::cerr << ss.str(); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { std::cerr << "Received message fragment" << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { std::cerr << "Received " << wireSize << " bytes" << std::endl; processCobraMessage(state, webSocket, _appConfig, str); diff --git a/ws/ws_broadcast_server.cpp b/ws/ws_broadcast_server.cpp index 5473c376..fb7338f6 100644 --- a/ws/ws_broadcast_server.cpp +++ b/ws/ws_broadcast_server.cpp @@ -28,7 +28,7 @@ namespace ix const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; std::cerr << "id: " << connectionState->getId() << std::endl; @@ -39,13 +39,13 @@ namespace ix std::cerr << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { std::cerr << "Closed connection" << " code " << closeInfo.code << " reason " << closeInfo.reason << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Connection error: " << error.reason << std::endl; @@ -54,11 +54,11 @@ namespace ix ss << "HTTP Status: " << error.http_status << std::endl; std::cerr << ss.str(); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { std::cerr << "Received message fragment" << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { std::cerr << "Received " << wireSize << " bytes" << std::endl; diff --git a/ws/ws_chat.cpp b/ws/ws_chat.cpp index 934b50df..9c3df9d9 100644 --- a/ws/ws_chat.cpp +++ b/ws/ws_chat.cpp @@ -68,7 +68,7 @@ namespace ix bool WebSocketChat::isReady() const { - return _webSocket.getReadyState() == ix::WebSocket_ReadyState_Open; + return _webSocket.getReadyState() == ix::ReadyState::Open; } void WebSocketChat::stop() @@ -92,7 +92,7 @@ namespace ix const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("ws chat: connected"); std::cout << "Uri: " << openInfo.uri << std::endl; @@ -107,7 +107,7 @@ namespace ix << " Connected !"; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "ws chat: user " << _user @@ -116,7 +116,7 @@ namespace ix << " reason " << closeInfo.reason; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { auto result = decodeMessage(str); @@ -132,7 +132,7 @@ namespace ix << _user << " > "; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "Connection error: " << error.reason << std::endl; ss << "#retries: " << error.retries << std::endl; diff --git a/ws/ws_connect.cpp b/ws/ws_connect.cpp index c1ca8e20..7a3f6af1 100644 --- a/ws/ws_connect.cpp +++ b/ws/ws_connect.cpp @@ -70,7 +70,7 @@ namespace ix const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("ws_connect: connected"); std::cout << "Uri: " << openInfo.uri << std::endl; @@ -80,14 +80,14 @@ namespace ix std::cout << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "ws_connect: connection closed:"; ss << " code " << closeInfo.code; ss << " reason " << closeInfo.reason << std::endl; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { std::cerr << "Received " << wireSize << " bytes" << std::endl; @@ -95,7 +95,7 @@ namespace ix << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "Connection error: " << error.reason << std::endl; ss << "#retries: " << error.retries << std::endl; @@ -103,15 +103,15 @@ namespace ix ss << "HTTP Status: " << error.http_status << std::endl; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { std::cerr << "Received message fragment" << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { std::cerr << "Received ping" << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { std::cerr << "Received pong" << std::endl; } diff --git a/ws/ws_echo_server.cpp b/ws/ws_echo_server.cpp index 4ab0add4..ef77bbbc 100644 --- a/ws/ws_echo_server.cpp +++ b/ws/ws_echo_server.cpp @@ -28,7 +28,7 @@ namespace ix const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; std::cerr << "id: " << connectionState->getId() << std::endl; @@ -39,13 +39,13 @@ namespace ix std::cerr << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { std::cerr << "Closed connection" << " code " << closeInfo.code << " reason " << closeInfo.reason << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Connection error: " << error.reason << std::endl; @@ -54,7 +54,7 @@ namespace ix ss << "HTTP Status: " << error.http_status << std::endl; std::cerr << ss.str(); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { std::cerr << "Received " << wireSize << " bytes" diff --git a/ws/ws_http_client.cpp b/ws/ws_http_client.cpp index 5ad42a01..5b7cec2c 100644 --- a/ws/ws_http_client.cpp +++ b/ws/ws_http_client.cpp @@ -150,12 +150,12 @@ namespace ix std::cerr << "Download size: " << downloadSize << std::endl; std::cerr << "Status: " << statusCode << std::endl; - if (errorCode != HttpErrorCode_Ok) + if (errorCode != HttpErrorCode::Ok) { std::cerr << "error message: " << errorMsg << std::endl; } - if (!headersOnly && errorCode == HttpErrorCode_Ok) + if (!headersOnly && errorCode == HttpErrorCode::Ok) { if (save || !output.empty()) { diff --git a/ws/ws_ping_pong.cpp b/ws/ws_ping_pong.cpp index 025bb87e..8d1afa6a 100644 --- a/ws/ws_ping_pong.cpp +++ b/ws/ws_ping_pong.cpp @@ -64,7 +64,7 @@ namespace ix std::cerr << "Received " << wireSize << " bytes" << std::endl; std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { log("ping_pong: connected"); @@ -75,7 +75,7 @@ namespace ix std::cout << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "ping_pong: disconnected:" << " code " << closeInfo.code @@ -83,25 +83,25 @@ namespace ix << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { ss << "ping_pong: received message: " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Ping) + else if (messageType == ix::WebSocketMessageType::Ping) { ss << "ping_pong: received ping message: " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Pong) + else if (messageType == ix::WebSocketMessageType::Pong) { ss << "ping_pong: received pong message: " << str; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "Connection error: " << error.reason << std::endl; ss << "#retries: " << error.retries << std::endl; diff --git a/ws/ws_receive.cpp b/ws/ws_receive.cpp index 6f270c52..81012dbf 100644 --- a/ws/ws_receive.cpp +++ b/ws/ws_receive.cpp @@ -191,7 +191,7 @@ namespace ix const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { _condition.notify_one(); @@ -203,21 +203,21 @@ namespace ix std::cout << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "ws_receive: connection closed:"; ss << " code " << closeInfo.code; ss << " reason " << closeInfo.reason << std::endl; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { ss << "ws_receive: transfered " << wireSize << " bytes"; log(ss.str()); handleMessage(str); _condition.notify_one(); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { ss << "ws_receive: received fragment " << _receivedFragmentCounter++; log(ss.str()); @@ -229,7 +229,7 @@ namespace ix std::this_thread::sleep_for(duration); } } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "ws_receive "; ss << "Connection error: " << error.reason << std::endl; diff --git a/ws/ws_send.cpp b/ws/ws_send.cpp index 566787f8..586472f2 100644 --- a/ws/ws_send.cpp +++ b/ws/ws_send.cpp @@ -120,7 +120,7 @@ namespace ix const ix::WebSocketCloseInfo& closeInfo) { std::stringstream ss; - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { _condition.notify_one(); @@ -132,14 +132,14 @@ namespace ix std::cout << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { ss << "ws_send: connection closed:"; ss << " code " << closeInfo.code; ss << " reason " << closeInfo.reason << std::endl; log(ss.str()); } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { _condition.notify_one(); @@ -160,7 +160,7 @@ namespace ix std::cerr << "Invalid id" << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { ss << "ws_send "; ss << "Connection error: " << error.reason << std::endl; diff --git a/ws/ws_transfer.cpp b/ws/ws_transfer.cpp index 58646010..a3fc0c97 100644 --- a/ws/ws_transfer.cpp +++ b/ws/ws_transfer.cpp @@ -28,7 +28,7 @@ namespace ix const ix::WebSocketOpenInfo& openInfo, const ix::WebSocketCloseInfo& closeInfo) { - if (messageType == ix::WebSocket_MessageType_Open) + if (messageType == ix::WebSocketMessageType::Open) { std::cerr << "New connection" << std::endl; std::cerr << "id: " << connectionState->getId() << std::endl; @@ -39,13 +39,13 @@ namespace ix std::cerr << it.first << ": " << it.second << std::endl; } } - else if (messageType == ix::WebSocket_MessageType_Close) + else if (messageType == ix::WebSocketMessageType::Close) { std::cerr << "Closed connection" << " code " << closeInfo.code << " reason " << closeInfo.reason << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Error) + else if (messageType == ix::WebSocketMessageType::Error) { std::stringstream ss; ss << "Connection error: " << error.reason << std::endl; @@ -54,12 +54,12 @@ namespace ix ss << "HTTP Status: " << error.http_status << std::endl; std::cerr << ss.str(); } - else if (messageType == ix::WebSocket_MessageType_Fragment) + else if (messageType == ix::WebSocketMessageType::Fragment) { std::cerr << "Received message fragment " << std::endl; } - else if (messageType == ix::WebSocket_MessageType_Message) + else if (messageType == ix::WebSocketMessageType::Message) { std::cerr << "Received " << wireSize << " bytes" << std::endl; for (auto&& client : server.getClients())