cleanup
This commit is contained in:
@ -188,6 +188,7 @@ namespace ix {
|
||||
_ws.dispatch(
|
||||
[this](const std::string& msg,
|
||||
size_t wireSize,
|
||||
bool decompressionError,
|
||||
WebSocketTransport::MessageKind messageKind)
|
||||
{
|
||||
WebSocketMessageType webSocketMessageType;
|
||||
@ -209,8 +210,11 @@ namespace ix {
|
||||
} break;
|
||||
}
|
||||
|
||||
WebSocketErrorInfo webSocketErrorInfo;
|
||||
webSocketErrorInfo.decompressionError = decompressionError;
|
||||
|
||||
_onMessageCallback(webSocketMessageType, msg, wireSize,
|
||||
WebSocketErrorInfo(), WebSocketCloseInfo(),
|
||||
webSocketErrorInfo, WebSocketCloseInfo(),
|
||||
WebSocketHttpHeaders());
|
||||
|
||||
WebSocket::invokeTrafficTrackerCallback(msg.size(), true);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#include "IXWebSocketTransport.h"
|
||||
#include "IXWebSocketErrorInfo.h"
|
||||
#include "IXWebSocketSendInfo.h"
|
||||
#include "IXWebSocketPerMessageDeflateOptions.h"
|
||||
#include "IXWebSocketHttpHeaders.h"
|
||||
@ -40,30 +41,17 @@ namespace ix
|
||||
WebSocket_MessageType_Pong = 5
|
||||
};
|
||||
|
||||
struct WebSocketErrorInfo
|
||||
{
|
||||
uint64_t retries;
|
||||
double wait_time;
|
||||
int http_status;
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
struct WebSocketCloseInfo
|
||||
{
|
||||
uint16_t code;
|
||||
std::string reason;
|
||||
|
||||
WebSocketCloseInfo(uint64_t c, const std::string& r)
|
||||
WebSocketCloseInfo(uint64_t c = 0,
|
||||
const std::string& r = std::string())
|
||||
{
|
||||
code = c;
|
||||
reason = r;
|
||||
}
|
||||
|
||||
WebSocketCloseInfo()
|
||||
{
|
||||
code = 0;
|
||||
reason = "";
|
||||
}
|
||||
};
|
||||
|
||||
using OnMessageCallback = std::function<void(WebSocketMessageType,
|
||||
|
21
ixwebsocket/IXWebSocketErrorInfo.h
Normal file
21
ixwebsocket/IXWebSocketErrorInfo.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* IXWebSocketErrorInfo.h
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
struct WebSocketErrorInfo
|
||||
{
|
||||
uint64_t retries;
|
||||
double wait_time;
|
||||
int http_status;
|
||||
std::string reason;
|
||||
bool decompressionError;
|
||||
};
|
||||
}
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "zlib.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
|
@ -7,18 +7,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
struct WebSocketSendInfo
|
||||
{
|
||||
bool success;
|
||||
bool compressionError;
|
||||
size_t payloadSize;
|
||||
size_t wireSize;
|
||||
|
||||
WebSocketSendInfo(bool s = false, size_t p = -1, size_t w = -1)
|
||||
WebSocketSendInfo(bool s = false, bool c = false,
|
||||
size_t p = 0, size_t w = 0)
|
||||
{
|
||||
success = s;
|
||||
compressionError = c;
|
||||
payloadSize = p;
|
||||
wireSize = w;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ namespace ix
|
||||
|
||||
}
|
||||
|
||||
char line[512];
|
||||
char line[256];
|
||||
int i;
|
||||
for (i = 0; i < 2 || (i < 255 && line[i-2] != '\r' && line[i-1] != '\n'); ++i)
|
||||
{
|
||||
@ -634,18 +634,12 @@ namespace ix
|
||||
if (_enablePerMessageDeflate && ws.rsv1)
|
||||
{
|
||||
std::string decompressedMessage;
|
||||
if (_perMessageDeflate.decompress(message, decompressedMessage))
|
||||
{
|
||||
onMessageCallback(decompressedMessage, wireSize, messageKind);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "error decompressing msg !"<< std::endl;
|
||||
}
|
||||
bool success = _perMessageDeflate.decompress(message, decompressedMessage);
|
||||
onMessageCallback(decompressedMessage, wireSize, not success, messageKind);
|
||||
}
|
||||
else
|
||||
{
|
||||
onMessageCallback(message, wireSize, messageKind);
|
||||
onMessageCallback(message, wireSize, false, messageKind);
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,13 +664,15 @@ namespace ix
|
||||
size_t payloadSize = message.size();
|
||||
size_t wireSize = message.size();
|
||||
std::string compressedMessage;
|
||||
bool compressionError = false;
|
||||
|
||||
std::string::const_iterator message_begin = message.begin();
|
||||
std::string::const_iterator message_end = message.end();
|
||||
|
||||
if (compress)
|
||||
{
|
||||
_perMessageDeflate.compress(message, compressedMessage);
|
||||
bool success = _perMessageDeflate.compress(message, compressedMessage);
|
||||
compressionError = !success;
|
||||
wireSize = compressedMessage.size();
|
||||
|
||||
message_begin = compressedMessage.begin();
|
||||
@ -749,7 +745,7 @@ namespace ix
|
||||
// Now actually send this data
|
||||
sendOnSocket();
|
||||
|
||||
return WebSocketSendInfo(true, payloadSize, wireSize);
|
||||
return WebSocketSendInfo(true, compressionError, payloadSize, wireSize);
|
||||
}
|
||||
|
||||
WebSocketSendInfo WebSocketTransport::sendPing(const std::string& message)
|
||||
@ -776,7 +772,7 @@ namespace ix
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (ret <= 0)
|
||||
else if (ret <= 0)
|
||||
{
|
||||
_socket->close();
|
||||
|
||||
@ -801,7 +797,7 @@ namespace ix
|
||||
// >>> struct.pack('!H', 1000)
|
||||
// b'\x03\xe8'
|
||||
//
|
||||
const std::string normalClosure = std::string("\x03\xe9");
|
||||
const std::string normalClosure = std::string("\x03\xe8");
|
||||
bool compress = false;
|
||||
sendData(wsheader_type::CLOSE, normalClosure, compress);
|
||||
setReadyState(CLOSING);
|
||||
|
@ -33,9 +33,9 @@ namespace ix
|
||||
std::string errorStr;
|
||||
WebSocketHttpHeaders headers;
|
||||
|
||||
WebSocketInitResult(bool s,
|
||||
int status,
|
||||
const std::string& e,
|
||||
WebSocketInitResult(bool s = false,
|
||||
int status = 0,
|
||||
const std::string& e = std::string(),
|
||||
WebSocketHttpHeaders h = WebSocketHttpHeaders())
|
||||
{
|
||||
success = s;
|
||||
@ -43,15 +43,6 @@ namespace ix
|
||||
errorStr = e;
|
||||
headers = h;
|
||||
}
|
||||
|
||||
// need to define a default
|
||||
WebSocketInitResult()
|
||||
{
|
||||
success = false;
|
||||
http_status = 0;
|
||||
errorStr = "";
|
||||
headers.clear();
|
||||
}
|
||||
};
|
||||
|
||||
class WebSocketTransport
|
||||
@ -74,6 +65,7 @@ namespace ix
|
||||
|
||||
using OnMessageCallback = std::function<void(const std::string&,
|
||||
size_t,
|
||||
bool,
|
||||
MessageKind)>;
|
||||
using OnCloseCallback = std::function<void(uint16_t,
|
||||
const std::string&,
|
||||
|
Reference in New Issue
Block a user