project builds / gross hack to disable compression code path / ws connect -x works but test fails

This commit is contained in:
Benjamin Sergeant 2020-07-07 19:25:18 -07:00
parent fbe7b0b020
commit 7a4a84d6e0
7 changed files with 74 additions and 17 deletions

View File

@ -429,6 +429,16 @@ namespace ix
return (binary) ? sendBinary(data, onProgressCallback) : sendText(data, onProgressCallback);
}
WebSocketSendInfo WebSocket::sendBinary(const std::vector<uint8_t>& data,
const OnProgressCallback& onProgressCallback)
{
if (!isConnected()) return WebSocketSendInfo(false);
std::lock_guard<std::mutex> lock(_writeMutex);
auto webSocketSendInfo = _ws.sendBinary(data, onProgressCallback);
WebSocket::invokeTrafficTrackerCallback(webSocketSendInfo.wireSize, false);
return webSocketSendInfo;
}
WebSocketSendInfo WebSocket::sendBinary(const std::string& text,
const OnProgressCallback& onProgressCallback)
{

View File

@ -74,8 +74,11 @@ namespace ix
WebSocketSendInfo send(const std::string& data,
bool binary = false,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo sendBinary(const std::string& text,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo sendBinary(const std::vector<uint8_t>& data,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo sendText(const std::string& text,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo ping(const std::string& text);

View File

@ -25,9 +25,8 @@ namespace ix
bool compress(const std::vector<uint8_t>& in, std::string& out);
bool compress(const std::vector<uint8_t>& in, std::vector<uint8_t>& out);
template<typename T, typename S> bool compressData(const T& in, S& out);
private:
template<typename T, typename S> bool compressData(const T& in, S& out);
template<typename T> bool endsWithEmptyUnCompressedBlock(const T& value);
int _flush;

View File

@ -751,8 +751,25 @@ namespace ix
return static_cast<unsigned>(seconds);
}
template<class T>
WebSocketSendInfo WebSocketTransport::sendData(wsheader_type::opcode_type type,
const std::string& message,
bool compress,
const OnProgressCallback& onProgressCallback)
{
return sendRawData(type, message, compress, onProgressCallback);
}
WebSocketSendInfo WebSocketTransport::sendData(wsheader_type::opcode_type type,
const std::vector<uint8_t>& message,
bool compress,
const OnProgressCallback& onProgressCallback)
{
return sendRawData(type, message, compress, onProgressCallback);
}
template<class T>
WebSocketSendInfo WebSocketTransport::sendRawData(wsheader_type::opcode_type type,
const T& message,
bool compress,
const OnProgressCallback& onProgressCallback)
@ -769,9 +786,11 @@ namespace ix
auto message_begin = message.begin();
auto message_end = message.end();
#if 0
if (compress)
{
if (!_perMessageDeflate->compress(message, _compressedMessage))
T compressedMessage;
if (!_perMessageDeflate->compress(message, compressedMessage))
{
bool success = false;
compressionError = true;
@ -780,11 +799,12 @@ namespace ix
return WebSocketSendInfo(success, compressionError, payloadSize, wireSize);
}
compressionError = false;
wireSize = _compressedMessage.size();
wireSize = compressedMessage.size();
message_begin = _compressedMessage.begin();
message_end = _compressedMessage.end();
message_begin = compressedMessage.begin();
message_end = compressedMessage.end();
}
#endif
{
std::lock_guard<std::mutex> lock(_txbufMutex);
@ -810,8 +830,8 @@ namespace ix
//
auto steps = wireSize / kChunkSize;
std::string::const_iterator begin = message_begin;
std::string::const_iterator end = message_end;
auto begin = message_begin;
auto end = message_end;
for (uint64_t i = 0; i < steps; ++i)
{
@ -964,6 +984,14 @@ namespace ix
return info;
}
WebSocketSendInfo WebSocketTransport::sendBinary(const std::vector<uint8_t>& message,
const OnProgressCallback& onProgressCallback)
{
return sendData(
wsheader_type::BINARY_FRAME, message, _enablePerMessageDeflate, onProgressCallback);
}
WebSocketSendInfo WebSocketTransport::sendBinary(const std::string& message,
const OnProgressCallback& onProgressCallback)

View File

@ -86,6 +86,9 @@ namespace ix
WebSocketInitResult connectToSocket(std::unique_ptr<Socket> socket, int timeoutSecs);
PollResult poll();
WebSocketSendInfo sendBinary(const std::vector<uint8_t>& message,
const OnProgressCallback& onProgressCallback);
WebSocketSendInfo sendBinary(const std::string& message,
const OnProgressCallback& onProgressCallback);
WebSocketSendInfo sendText(const std::string& message,
@ -190,7 +193,7 @@ namespace ix
std::atomic<bool> _enablePerMessageDeflate;
std::string _decompressedMessage;
std::string _compressedMessage;
std::vector<uint8_t> _compressedMessage;
// Used to control TLS connection behavior
SocketTLSOptions _socketTLSOptions;
@ -239,8 +242,18 @@ namespace ix
bool sendOnSocket();
bool receiveFromSocket();
template<class T>
WebSocketSendInfo sendData(wsheader_type::opcode_type type,
const std::string& message,
bool compress,
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo sendData(wsheader_type::opcode_type type,
const std::vector<uint8_t>& message,
bool compress,
const OnProgressCallback& onProgressCallback = nullptr);
template<class T>
WebSocketSendInfo sendRawData(wsheader_type::opcode_type type,
const T& message,
bool compress,
const OnProgressCallback& onProgressCallback = nullptr);

View File

@ -100,6 +100,7 @@ namespace
}
_webSocket.setUrl(url);
_webSocket.disablePerMessageDeflate();
std::stringstream ss;
log(std::string("Connecting to url: ") + url);
@ -188,7 +189,9 @@ namespace
void WebSocketChat::sendMessage(const std::string& text)
{
_webSocket.sendBinary(encodeMessage(text));
auto msg = encodeMessage(text);
std::vector<uint8_t> data(text.begin(), text.end());
_webSocket.sendBinary(data);
}
bool startServer(ix::WebSocketServer& server)

View File

@ -216,7 +216,8 @@ namespace ix
{
if (_binaryMode)
{
_webSocket.sendBinary(text);
std::vector<uint8_t> data(text.begin(), text.end());
_webSocket.sendBinary(data);
}
else
{