use C++11 enums (#67)

* use C++11 enums

* small rename

* update tests

* update tests

* update ws

* update ws

* update README.md
This commit is contained in:
Dimon4eg 2019-05-12 00:22:06 +03:00 committed by Benjamin Sergeant
parent 80226cb7d3
commit 99a3bbc4f9
26 changed files with 238 additions and 238 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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<int, // status

View File

@ -51,7 +51,7 @@ namespace ix
_ws.setOnCloseCallback(
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote)
{
_onMessageCallback(WebSocket_MessageType_Close, "", wireSize,
_onMessageCallback(WebSocketMessageType::Close, "", wireSize,
WebSocketErrorInfo(), WebSocketOpenInfo(),
WebSocketCloseInfo(code, reason, remote));
}
@ -172,7 +172,7 @@ namespace ix
return status;
}
_onMessageCallback(WebSocket_MessageType_Open, "", 0,
_onMessageCallback(WebSocketMessageType::Open, "", 0,
WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers),
WebSocketCloseInfo());
@ -195,7 +195,7 @@ namespace ix
return status;
}
_onMessageCallback(WebSocket_MessageType_Open, "", 0,
_onMessageCallback(WebSocketMessageType::Open, "", 0,
WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers),
WebSocketCloseInfo());
@ -204,12 +204,12 @@ namespace ix
bool WebSocket::isConnected() const
{
return getReadyState() == WebSocket_ReadyState_Open;
return getReadyState() == ReadyState::Open;
}
bool WebSocket::isClosing() const
{
return getReadyState() == WebSocket_ReadyState_Closing;
return getReadyState() == ReadyState::Closing;
}
void WebSocket::close()
@ -266,7 +266,7 @@ namespace ix
connectErr.reason = status.errorStr;
connectErr.http_status = status.http_status;
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
_onMessageCallback(WebSocketMessageType::Error, "", 0,
connectErr, WebSocketOpenInfo(),
WebSocketCloseInfo());
}
@ -287,17 +287,17 @@ namespace ix
firstConnectionAttempt = false;
// if here we are closed then checkConnection was not able to connect
if (getReadyState() == WebSocket_ReadyState_Closed)
if (getReadyState() == ReadyState::Closed)
{
break;
}
// 2. Poll to see if there's any new data available
WebSocketTransport::PollPostTreatment pollPostTreatment = _ws.poll();
WebSocketTransport::PollResult pollResult = _ws.poll();
// 3. Dispatch the incoming messages
_ws.dispatch(
pollPostTreatment,
pollResult,
[this](const std::string& msg,
size_t wireSize,
bool decompressionError,
@ -307,24 +307,24 @@ namespace ix
switch (messageKind)
{
default:
case WebSocketTransport::MSG:
case WebSocketTransport::MessageKind::MSG:
{
webSocketMessageType = WebSocket_MessageType_Message;
webSocketMessageType = WebSocketMessageType::Message;
} break;
case WebSocketTransport::PING:
case WebSocketTransport::MessageKind::PING:
{
webSocketMessageType = WebSocket_MessageType_Ping;
webSocketMessageType = WebSocketMessageType::Ping;
} break;
case WebSocketTransport::PONG:
case WebSocketTransport::MessageKind::PONG:
{
webSocketMessageType = WebSocket_MessageType_Pong;
webSocketMessageType = WebSocketMessageType::Pong;
} break;
case WebSocketTransport::FRAGMENT:
case WebSocketTransport::MessageKind::FRAGMENT:
{
webSocketMessageType = WebSocket_MessageType_Fragment;
webSocketMessageType = WebSocketMessageType::Fragment;
} break;
}
@ -429,11 +429,11 @@ namespace ix
{
switch (_ws.getReadyState())
{
case ix::WebSocketTransport::OPEN: return WebSocket_ReadyState_Open;
case ix::WebSocketTransport::CONNECTING: return WebSocket_ReadyState_Connecting;
case ix::WebSocketTransport::CLOSING: return WebSocket_ReadyState_Closing;
case ix::WebSocketTransport::CLOSED: return WebSocket_ReadyState_Closed;
default: return WebSocket_ReadyState_Closed;
case ix::WebSocketTransport::ReadyState::OPEN : return ReadyState::Open;
case ix::WebSocketTransport::ReadyState::CONNECTING: return ReadyState::Connecting;
case ix::WebSocketTransport::ReadyState::CLOSING : return ReadyState::Closing;
case ix::WebSocketTransport::ReadyState::CLOSED : return ReadyState::Closed;
default: return ReadyState::Closed;
}
}
@ -441,11 +441,11 @@ namespace ix
{
switch (readyState)
{
case WebSocket_ReadyState_Open: return "OPEN";
case WebSocket_ReadyState_Connecting: return "CONNECTING";
case WebSocket_ReadyState_Closing: return "CLOSING";
case WebSocket_ReadyState_Closed: return "CLOSED";
default: return "CLOSED";
case ReadyState::Open : return "OPEN";
case ReadyState::Connecting: return "CONNECTING";
case ReadyState::Closing : return "CLOSING";
case ReadyState::Closed : return "CLOSED";
default: return "UNKNOWN";
}
}

View File

@ -24,23 +24,23 @@
namespace ix
{
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Ready_state_constants
enum ReadyState
enum class ReadyState
{
WebSocket_ReadyState_Connecting = 0,
WebSocket_ReadyState_Open = 1,
WebSocket_ReadyState_Closing = 2,
WebSocket_ReadyState_Closed = 3
Connecting = 0,
Open = 1,
Closing = 2,
Closed = 3
};
enum WebSocketMessageType
enum class WebSocketMessageType
{
WebSocket_MessageType_Message = 0,
WebSocket_MessageType_Open = 1,
WebSocket_MessageType_Close = 2,
WebSocket_MessageType_Error = 3,
WebSocket_MessageType_Ping = 4,
WebSocket_MessageType_Pong = 5,
WebSocket_MessageType_Fragment = 6
Message = 0,
Open = 1,
Close = 2,
Error = 3,
Ping = 4,
Pong = 5,
Fragment = 6
};
struct WebSocketOpenInfo
@ -119,6 +119,8 @@ namespace ix
static void resetTrafficTrackerCallback();
ReadyState getReadyState() const;
static std::string readyStateToString(ReadyState readyState);
const std::string& getUrl() const;
const WebSocketPerMessageDeflateOptions& getPerMessageDeflateOptions() const;
int getHeartBeatPeriod() const;
@ -138,7 +140,6 @@ namespace ix
bool isConnected() const;
bool isClosing() const;
void checkConnection(bool firstConnectionAttempt);
std::string readyStateToString(ReadyState readyState);
static void invokeTrafficTrackerCallback(size_t size, bool incoming);
// Server

View File

@ -23,7 +23,6 @@ namespace ix
WebSocketPerMessageDeflateOptions(std::string extension);
std::string generateHeader();
std::string parseHeader();
bool enabled() const;
bool getClientNoContextTakeover() const;
bool getServerNoContextTakeover() const;

View File

@ -86,7 +86,7 @@ namespace ix
WebSocketTransport::WebSocketTransport() :
_useMask(true),
_readyState(CLOSED),
_readyState(ReadyState::CLOSED),
_closeCode(kInternalErrorCode),
_closeReason(kInternalErrorMessage),
_closeWireSize(0),
@ -173,7 +173,7 @@ namespace ix
timeoutSecs);
if (result.success)
{
setReadyState(OPEN);
setReadyState(ReadyState::OPEN);
}
return result;
}
@ -201,22 +201,22 @@ namespace ix
auto result = webSocketHandshake.serverHandshake(fd, timeoutSecs);
if (result.success)
{
setReadyState(OPEN);
setReadyState(ReadyState::OPEN);
}
return result;
}
WebSocketTransport::ReadyStateValues WebSocketTransport::getReadyState() const
WebSocketTransport::ReadyState WebSocketTransport::getReadyState() const
{
return _readyState;
}
void WebSocketTransport::setReadyState(ReadyStateValues readyStateValue)
void WebSocketTransport::setReadyState(ReadyState readyState)
{
// No state change, return
if (_readyState == readyStateValue) return;
if (_readyState == readyState) return;
if (readyStateValue == CLOSED)
if (readyState == ReadyState::CLOSED)
{
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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);

View File

@ -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<void(const std::string&,
@ -84,7 +84,7 @@ namespace ix
WebSocketInitResult connectToSocket(int fd, // Server
int timeoutSecs);
PollPostTreatment poll();
PollResult poll();
WebSocketSendInfo sendBinary(const std::string& message,
const OnProgressCallback& onProgressCallback);
WebSocketSendInfo sendText(const std::string& message,
@ -96,10 +96,10 @@ namespace ix
size_t closeWireSize = 0,
bool remote = false);
ReadyStateValues getReadyState() const;
void setReadyState(ReadyStateValues readyStateValue);
ReadyState getReadyState() const;
void setReadyState(ReadyState readyState);
void setOnCloseCallback(const OnCloseCallback& onCloseCallback);
void dispatch(PollPostTreatment pollPostTreatment,
void dispatch(PollResult pollResult,
const OnMessageCallback& onMessageCallback);
size_t bufferedAmount() const;
@ -153,7 +153,7 @@ namespace ix
std::shared_ptr<Socket> _socket;
// Hold the state of the connection (OPEN, CLOSED, etc...)
std::atomic<ReadyStateValues> _readyState;
std::atomic<ReadyState> _readyState;
OnCloseCallback _onCloseCallback;
uint16_t _closeCode;

View File

@ -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())

View File

@ -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++;

View File

@ -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())
{

View File

@ -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.!");
}

View File

@ -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())
{

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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"

View File

@ -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())
{

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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())