wip / compile but unittest failures
This commit is contained in:
@@ -30,16 +30,16 @@ namespace ix
|
||||
, _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs)
|
||||
, _enablePong(kDefaultEnablePong)
|
||||
, _pingIntervalSecs(kDefaultPingIntervalSecs)
|
||||
, _webSocketMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Message))
|
||||
, _webSocketErrorMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Error))
|
||||
, _webSocketOpenMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Open))
|
||||
, _webSocketCloseMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Close))
|
||||
{
|
||||
_ws.setOnCloseCallback(
|
||||
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) {
|
||||
_onMessageCallback(
|
||||
std::make_unique<WebSocketMessage>(WebSocketMessageType::Close,
|
||||
"",
|
||||
wireSize,
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo(code, reason, remote)));
|
||||
_webSocketCloseMessage->wireSize = wireSize;
|
||||
_webSocketCloseMessage->closeInfo = WebSocketCloseInfo(code, reason, remote);
|
||||
_onMessageCallback(_webSocketCloseMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,13 +193,8 @@ namespace ix
|
||||
return status;
|
||||
}
|
||||
|
||||
_onMessageCallback(std::make_unique<WebSocketMessage>(
|
||||
WebSocketMessageType::Open,
|
||||
"",
|
||||
0,
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo(status.uri, status.headers, status.protocol),
|
||||
WebSocketCloseInfo()));
|
||||
_webSocketOpenMessage->openInfo = WebSocketOpenInfo(status.uri, status.headers, status.protocol),
|
||||
_onMessageCallback(_webSocketOpenMessage);
|
||||
|
||||
if (_pingIntervalSecs > 0)
|
||||
{
|
||||
@@ -224,13 +219,8 @@ namespace ix
|
||||
return status;
|
||||
}
|
||||
|
||||
_onMessageCallback(
|
||||
std::make_unique<WebSocketMessage>(WebSocketMessageType::Open,
|
||||
"",
|
||||
0,
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo(status.uri, status.headers),
|
||||
WebSocketCloseInfo()));
|
||||
_webSocketOpenMessage->openInfo = WebSocketOpenInfo(status.uri, status.headers);
|
||||
_onMessageCallback(_webSocketOpenMessage);
|
||||
|
||||
if (_pingIntervalSecs > 0)
|
||||
{
|
||||
@@ -310,12 +300,8 @@ namespace ix
|
||||
connectErr.reason = status.errorStr;
|
||||
connectErr.http_status = status.http_status;
|
||||
|
||||
_onMessageCallback(std::make_unique<WebSocketMessage>(WebSocketMessageType::Error,
|
||||
"",
|
||||
0,
|
||||
connectErr,
|
||||
WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo()));
|
||||
_webSocketErrorMessage->errorInfo = connectErr;
|
||||
_onMessageCallback(_webSocketErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,18 +367,15 @@ namespace ix
|
||||
break;
|
||||
}
|
||||
|
||||
WebSocketErrorInfo webSocketErrorInfo;
|
||||
webSocketErrorInfo.decompressionError = decompressionError;
|
||||
|
||||
bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY;
|
||||
|
||||
_onMessageCallback(std::make_unique<WebSocketMessage>(webSocketMessageType,
|
||||
msg,
|
||||
wireSize,
|
||||
webSocketErrorInfo,
|
||||
WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo(),
|
||||
binary));
|
||||
_webSocketMessage->type = webSocketMessageType;
|
||||
_webSocketMessage->str = msg;
|
||||
_webSocketMessage->wireSize = wireSize;
|
||||
_webSocketMessage->errorInfo.decompressionError = decompressionError;
|
||||
_webSocketMessage->binary = binary;
|
||||
|
||||
_onMessageCallback(_webSocketMessage);
|
||||
|
||||
WebSocket::invokeTrafficTrackerCallback(wireSize, true);
|
||||
});
|
||||
|
@@ -155,6 +155,12 @@ namespace ix
|
||||
static const int kDefaultPingIntervalSecs;
|
||||
static const int kDefaultPingTimeoutSecs;
|
||||
|
||||
// One message ptr for each message kinds
|
||||
WebSocketMessagePtr _webSocketMessage;
|
||||
WebSocketMessagePtr _webSocketErrorMessage;
|
||||
WebSocketMessagePtr _webSocketOpenMessage;
|
||||
WebSocketMessagePtr _webSocketCloseMessage;
|
||||
|
||||
// Subprotocols
|
||||
std::vector<std::string> _subProtocols;
|
||||
|
||||
|
@@ -6,6 +6,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
struct WebSocketCloseInfo
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
@@ -17,5 +18,10 @@ namespace ix
|
||||
int http_status = 0;
|
||||
std::string reason;
|
||||
bool decompressionError = false;
|
||||
|
||||
WebSocketErrorInfo()
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
} // namespace ix
|
||||
|
12
ixwebsocket/IXWebSocketMessage.cpp
Normal file
12
ixwebsocket/IXWebSocketMessage.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* IXWebSocketMessage.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "IXWebSocketMessage.h"
|
||||
|
||||
namespace ix
|
||||
{
|
||||
std::string WebSocketMessage::kStr("foo");
|
||||
}
|
@@ -19,22 +19,23 @@ namespace ix
|
||||
struct WebSocketMessage
|
||||
{
|
||||
WebSocketMessageType type;
|
||||
const std::string& str;
|
||||
std::string& str;
|
||||
size_t wireSize;
|
||||
WebSocketErrorInfo errorInfo;
|
||||
WebSocketOpenInfo openInfo;
|
||||
WebSocketCloseInfo closeInfo;
|
||||
bool binary;
|
||||
|
||||
static std::string kStr;
|
||||
|
||||
WebSocketMessage(WebSocketMessageType t,
|
||||
const std::string& s,
|
||||
size_t w,
|
||||
WebSocketErrorInfo e,
|
||||
WebSocketOpenInfo o,
|
||||
WebSocketCloseInfo c,
|
||||
size_t w = 0,
|
||||
WebSocketErrorInfo e = WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo o = WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo c = WebSocketCloseInfo(),
|
||||
bool b = false)
|
||||
: type(t)
|
||||
, str(s)
|
||||
, str(WebSocketMessage::kStr)
|
||||
, wireSize(w)
|
||||
, errorInfo(e)
|
||||
, openInfo(o)
|
||||
@@ -43,6 +44,11 @@ namespace ix
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
// void setStr(const std::string& s)
|
||||
// {
|
||||
// str = std::move(s);
|
||||
// }
|
||||
};
|
||||
|
||||
using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>;
|
||||
|
@@ -6,6 +6,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "IXWebSocketHttpHeaders.h"
|
||||
|
||||
namespace ix
|
||||
{
|
||||
struct WebSocketOpenInfo
|
||||
|
@@ -515,8 +515,10 @@ namespace ix
|
||||
//
|
||||
if (ws.fin && _chunks.empty())
|
||||
{
|
||||
emitMessage(
|
||||
_fragmentedMessageKind, frameData, _receivedMessageCompressed, onMessageCallback);
|
||||
emitMessage(_fragmentedMessageKind,
|
||||
frameData,
|
||||
_receivedMessageCompressed,
|
||||
onMessageCallback);
|
||||
|
||||
_receivedMessageCompressed = false;
|
||||
}
|
||||
|
@@ -6,4 +6,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define IX_WEBSOCKET_VERSION "9.2.5"
|
||||
#define IX_WEBSOCKET_VERSION "9.2.6"
|
||||
|
Reference in New Issue
Block a user