From 23cf4bd59b4ca17cb368d77ff05702a6f005a58b Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 9 Jun 2019 10:10:33 -0700 Subject: [PATCH] Add explicite WebSocket::sendBinary New headers + WebSocketMessage class to hold message data, still not used across the board --- ixwebsocket/IXWebSocket.h | 43 ++------------------------- ixwebsocket/IXWebSocketCloseInfo.h | 25 ++++++++++++++++ ixwebsocket/IXWebSocketMessage.h | 31 +++++++++++++++++++ ixwebsocket/IXWebSocketMessageQueue.h | 16 ++-------- ixwebsocket/IXWebSocketMessageType.h | 21 +++++++++++++ ixwebsocket/IXWebSocketOpenInfo.h | 24 +++++++++++++++ 6 files changed, 105 insertions(+), 55 deletions(-) create mode 100644 ixwebsocket/IXWebSocketCloseInfo.h create mode 100644 ixwebsocket/IXWebSocketMessage.h create mode 100644 ixwebsocket/IXWebSocketMessageType.h create mode 100644 ixwebsocket/IXWebSocketOpenInfo.h diff --git a/ixwebsocket/IXWebSocket.h b/ixwebsocket/IXWebSocket.h index 6e9cd2f4..221b9ffa 100644 --- a/ixwebsocket/IXWebSocket.h +++ b/ixwebsocket/IXWebSocket.h @@ -16,6 +16,7 @@ #include "IXWebSocketPerMessageDeflateOptions.h" #include "IXWebSocketSendInfo.h" #include "IXWebSocketTransport.h" +#include "IXWebSocketMessage.h" #include #include #include @@ -32,46 +33,6 @@ namespace ix Closed = 3 }; - enum class WebSocketMessageType - { - Message = 0, - Open = 1, - Close = 2, - Error = 3, - Ping = 4, - Pong = 5, - Fragment = 6 - }; - - struct WebSocketOpenInfo - { - std::string uri; - WebSocketHttpHeaders headers; - - WebSocketOpenInfo(const std::string& u = std::string(), - const WebSocketHttpHeaders& h = WebSocketHttpHeaders()) - : uri(u) - , headers(h) - { - ; - } - }; - - struct WebSocketCloseInfo - { - uint16_t code; - std::string reason; - bool remote; - - WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string(), bool rem = false) - : code(c) - , reason(r) - , remote(rem) - { - ; - } - }; - using OnMessageCallback = std::function +#include +#include + +namespace ix +{ + struct WebSocketMessage + { + WebSocketMessageType type; + std::string str; + size_t wireSize; + WebSocketErrorInfo errorInfo; + WebSocketOpenInfo openInfo; + WebSocketCloseInfo closeInfo; + bool binary; + }; + + using WebSocketMessagePtr = std::shared_ptr; +} // namespace ix diff --git a/ixwebsocket/IXWebSocketMessageQueue.h b/ixwebsocket/IXWebSocketMessageQueue.h index d2e7dbc1..962b78d0 100644 --- a/ixwebsocket/IXWebSocketMessageQueue.h +++ b/ixwebsocket/IXWebSocketMessageQueue.h @@ -30,24 +30,12 @@ namespace ix void poll(int count = 512); protected: - struct Message - { - WebSocketMessageType type; - std::string str; - size_t wireSize; - WebSocketErrorInfo errorInfo; - WebSocketOpenInfo openInfo; - WebSocketCloseInfo closeInfo; - }; - - using MessagePtr = std::shared_ptr; - - MessagePtr popMessage(); + WebSocketMessagePtr popMessage(); private: WebSocket* _websocket = nullptr; OnMessageCallback _onMessageUserCallback; std::mutex _messagesMutex; - std::list _messages; + std::list _messages; }; } // namespace ix diff --git a/ixwebsocket/IXWebSocketMessageType.h b/ixwebsocket/IXWebSocketMessageType.h new file mode 100644 index 00000000..c7ee45d9 --- /dev/null +++ b/ixwebsocket/IXWebSocketMessageType.h @@ -0,0 +1,21 @@ +/* + * IXWebSocketMessageType.h + * Author: Benjamin Sergeant + * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. + */ + +#pragma once + +namespace ix +{ + enum class WebSocketMessageType + { + Message = 0, + Open = 1, + Close = 2, + Error = 3, + Ping = 4, + Pong = 5, + Fragment = 6 + }; +} diff --git a/ixwebsocket/IXWebSocketOpenInfo.h b/ixwebsocket/IXWebSocketOpenInfo.h new file mode 100644 index 00000000..d05897cd --- /dev/null +++ b/ixwebsocket/IXWebSocketOpenInfo.h @@ -0,0 +1,24 @@ +/* + * IXWebSocketOpenInfo.h + * Author: Benjamin Sergeant + * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. + */ + +#pragma once + +namespace ix +{ + struct WebSocketOpenInfo + { + std::string uri; + WebSocketHttpHeaders headers; + + WebSocketOpenInfo(const std::string& u = std::string(), + const WebSocketHttpHeaders& h = WebSocketHttpHeaders()) + : uri(u) + , headers(h) + { + ; + } + }; +}