fix android build + proxy work
This commit is contained in:
parent
6e9f27d63c
commit
16c6f08e2d
@ -107,7 +107,7 @@ elseif (WIN32)
|
|||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/windows/IXSetThreadName_windows.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/windows/IXSetThreadName_windows.cpp)
|
||||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/freebsd/IXSetThreadName_freebsd.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/freebsd/IXSetThreadName_freebsd.cpp)
|
||||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
else()
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/linux/IXSetThreadName_linux.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/linux/IXSetThreadName_linux.cpp)
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSelectInterruptEventFd.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSelectInterruptEventFd.cpp)
|
||||||
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSelectInterruptEventFd.h)
|
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSelectInterruptEventFd.h)
|
||||||
|
@ -1 +1 @@
|
|||||||
7.3.0
|
7.3.1
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "7.3.0"
|
#define IX_WEBSOCKET_VERSION "7.3.1"
|
||||||
|
@ -8,9 +8,8 @@
|
|||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <ixsentry/IXSentryClient.h>
|
#include <ixsentry/IXSentryClient.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace ix;
|
using namespace ix;
|
||||||
|
|
||||||
@ -21,7 +20,9 @@ namespace ix
|
|||||||
SECTION("Attempt to index nil")
|
SECTION("Attempt to index nil")
|
||||||
{
|
{
|
||||||
SentryClient sentryClient("");
|
SentryClient sentryClient("");
|
||||||
std::string stack = "Attempt to index nil[overlay]!\nstack traceback:\n\tfoo.lua:2661: in function 'getFoo'\n\tfoo.lua:1666: in function 'onUpdate'\n\tfoo.lua:1751: in function <foo.lua:1728>";
|
std::string stack = "Attempt to index nil[overlay]!\nstack traceback:\n\tfoo.lua:2661: "
|
||||||
|
"in function 'getFoo'\n\tfoo.lua:1666: in function "
|
||||||
|
"'onUpdate'\n\tfoo.lua:1751: in function <foo.lua:1728>";
|
||||||
auto frames = sentryClient.parseLuaStackTrace(stack);
|
auto frames = sentryClient.parseLuaStackTrace(stack);
|
||||||
|
|
||||||
REQUIRE(frames.size() == 3);
|
REQUIRE(frames.size() == 3);
|
||||||
@ -30,7 +31,8 @@ namespace ix
|
|||||||
SECTION("Attempt to perform nil")
|
SECTION("Attempt to perform nil")
|
||||||
{
|
{
|
||||||
SentryClient sentryClient("");
|
SentryClient sentryClient("");
|
||||||
std::string stack = "Attempt to perform nil - 1572111278.299\nstack traceback:\n\tfoo.lua:57: in function <foo.lua:53>";
|
std::string stack = "Attempt to perform nil - 1572111278.299\nstack "
|
||||||
|
"traceback:\n\tfoo.lua:57: in function <foo.lua:53>";
|
||||||
auto frames = sentryClient.parseLuaStackTrace(stack);
|
auto frames = sentryClient.parseLuaStackTrace(stack);
|
||||||
|
|
||||||
REQUIRE(frames.size() == 1);
|
REQUIRE(frames.size() == 1);
|
||||||
|
@ -128,23 +128,21 @@ namespace ix
|
|||||||
{
|
{
|
||||||
spdlog::info("Subscriber authenticated");
|
spdlog::info("Subscriber authenticated");
|
||||||
|
|
||||||
conn.subscribe(channel,
|
conn.subscribe(
|
||||||
filter,
|
channel,
|
||||||
[&msgPerSeconds,
|
filter,
|
||||||
&msgCount,
|
[&msgPerSeconds, &msgCount, &conditionVariableMutex, &condition, &queue](
|
||||||
&conditionVariableMutex,
|
const Json::Value& msg) {
|
||||||
&condition,
|
{
|
||||||
&queue](const Json::Value& msg) {
|
std::unique_lock<std::mutex> lock(conditionVariableMutex);
|
||||||
{
|
queue.push(msg);
|
||||||
std::unique_lock<std::mutex> lock(conditionVariableMutex);
|
}
|
||||||
queue.push(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
condition.notify_one();
|
condition.notify_one();
|
||||||
|
|
||||||
msgPerSeconds++;
|
msgPerSeconds++;
|
||||||
msgCount++;
|
msgCount++;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (eventType == ix::CobraConnection_EventType_Subscribed)
|
else if (eventType == ix::CobraConnection_EventType_Subscribed)
|
||||||
{
|
{
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ixsentry/IXSentryClient.h>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ixcobra/IXCobraConnection.h>
|
#include <ixcobra/IXCobraConnection.h>
|
||||||
|
#include <ixsentry/IXSentryClient.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
@ -13,13 +13,29 @@ namespace ix
|
|||||||
class ProxyConnectionState : public ix::ConnectionState
|
class ProxyConnectionState : public ix::ConnectionState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
ProxyConnectionState()
|
||||||
|
: _connected(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ix::WebSocket& webSocket()
|
ix::WebSocket& webSocket()
|
||||||
{
|
{
|
||||||
return _serverWebSocket;
|
return _serverWebSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isConnected()
|
||||||
|
{
|
||||||
|
return _connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConnected()
|
||||||
|
{
|
||||||
|
_connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ix::WebSocket _serverWebSocket;
|
ix::WebSocket _serverWebSocket;
|
||||||
|
bool _connected;
|
||||||
};
|
};
|
||||||
|
|
||||||
int ws_proxy_server_main(int port,
|
int ws_proxy_server_main(int port,
|
||||||
@ -38,101 +54,109 @@ namespace ix
|
|||||||
};
|
};
|
||||||
server.setConnectionStateFactory(factory);
|
server.setConnectionStateFactory(factory);
|
||||||
|
|
||||||
server.setOnConnectionCallback(
|
server.setOnConnectionCallback([remoteUrl,
|
||||||
[remoteUrl, verbose](std::shared_ptr<ix::WebSocket> webSocket,
|
verbose](std::shared_ptr<ix::WebSocket> webSocket,
|
||||||
std::shared_ptr<ConnectionState> connectionState) {
|
std::shared_ptr<ConnectionState> connectionState) {
|
||||||
auto state = std::dynamic_pointer_cast<ProxyConnectionState>(connectionState);
|
auto state = std::dynamic_pointer_cast<ProxyConnectionState>(connectionState);
|
||||||
|
|
||||||
// Server connection
|
// Server connection
|
||||||
state->webSocket().setOnMessageCallback(
|
state->webSocket().setOnMessageCallback([webSocket, state, verbose](
|
||||||
[webSocket, state, verbose](const WebSocketMessagePtr& msg) {
|
const WebSocketMessagePtr& msg) {
|
||||||
if (msg->type == ix::WebSocketMessageType::Open)
|
if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
std::cerr << "New connection" << std::endl;
|
std::cerr << "New connection" << std::endl;
|
||||||
std::cerr << "id: " << state->getId() << std::endl;
|
std::cerr << "id: " << state->getId() << std::endl;
|
||||||
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
|
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
|
||||||
std::cerr << "Headers:" << std::endl;
|
std::cerr << "Headers:" << std::endl;
|
||||||
for (auto it : msg->openInfo.headers)
|
for (auto it : msg->openInfo.headers)
|
||||||
{
|
{
|
||||||
std::cerr << it.first << ": " << it.second << std::endl;
|
std::cerr << it.first << ": " << it.second << std::endl;
|
||||||
}
|
}
|
||||||
}
|
state->setConnected();
|
||||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
}
|
||||||
{
|
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||||
std::cerr << "Closed connection"
|
{
|
||||||
<< " code " << msg->closeInfo.code << " reason "
|
std::cerr << "Closed connection"
|
||||||
<< msg->closeInfo.reason << std::endl;
|
<< " code " << msg->closeInfo.code << " reason "
|
||||||
}
|
<< msg->closeInfo.reason << std::endl;
|
||||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
}
|
||||||
{
|
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||||
std::stringstream ss;
|
{
|
||||||
ss << "Connection error: " << msg->errorInfo.reason << std::endl;
|
std::stringstream ss;
|
||||||
ss << "#retries: " << msg->errorInfo.retries << std::endl;
|
ss << "Connection error: " << msg->errorInfo.reason << std::endl;
|
||||||
ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl;
|
ss << "#retries: " << msg->errorInfo.retries << std::endl;
|
||||||
ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl;
|
ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl;
|
||||||
std::cerr << ss.str();
|
ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl;
|
||||||
webSocket->close(msg->closeInfo.code, msg->closeInfo.reason);
|
std::cerr << ss.str();
|
||||||
}
|
webSocket->close(msg->closeInfo.code, msg->closeInfo.reason);
|
||||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
}
|
||||||
{
|
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
std::cerr << "Received " << msg->wireSize << " bytes from server" << std::endl;
|
{
|
||||||
if (verbose)
|
std::cerr << "Received " << msg->wireSize << " bytes from server" << std::endl;
|
||||||
{
|
if (verbose)
|
||||||
std::cerr << "payload " << msg->str << std::endl;
|
{
|
||||||
}
|
std::cerr << "payload " << msg->str << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
webSocket->send(msg->str, msg->binary);
|
webSocket->send(msg->str, msg->binary);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Client connection
|
|
||||||
webSocket->setOnMessageCallback(
|
|
||||||
[state, remoteUrl, verbose](const WebSocketMessagePtr& msg) {
|
|
||||||
if (msg->type == ix::WebSocketMessageType::Open)
|
|
||||||
{
|
|
||||||
std::cerr << "New connection" << std::endl;
|
|
||||||
std::cerr << "id: " << state->getId() << std::endl;
|
|
||||||
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
|
|
||||||
std::cerr << "Headers:" << std::endl;
|
|
||||||
for (auto it : msg->openInfo.headers)
|
|
||||||
{
|
|
||||||
std::cerr << it.first << ": " << it.second << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to the 'real' server
|
|
||||||
std::string url(remoteUrl);
|
|
||||||
url += msg->openInfo.uri;
|
|
||||||
state->webSocket().setUrl(url);
|
|
||||||
state->webSocket().start();
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
|
||||||
{
|
|
||||||
std::cerr << "Closed connection"
|
|
||||||
<< " code " << msg->closeInfo.code << " reason "
|
|
||||||
<< msg->closeInfo.reason << std::endl;
|
|
||||||
state->webSocket().close(msg->closeInfo.code, msg->closeInfo.reason);
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "Connection error: " << msg->errorInfo.reason << std::endl;
|
|
||||||
ss << "#retries: " << msg->errorInfo.retries << std::endl;
|
|
||||||
ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl;
|
|
||||||
ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl;
|
|
||||||
std::cerr << ss.str();
|
|
||||||
}
|
|
||||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
|
||||||
{
|
|
||||||
std::cerr << "Received " << msg->wireSize << " bytes from client" << std::endl;
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cerr << "payload " << msg->str << std::endl;
|
|
||||||
}
|
|
||||||
state->webSocket().send(msg->str, msg->binary);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Client connection
|
||||||
|
webSocket->setOnMessageCallback([state, remoteUrl, verbose](
|
||||||
|
const WebSocketMessagePtr& msg) {
|
||||||
|
if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
|
{
|
||||||
|
std::cerr << "New connection" << std::endl;
|
||||||
|
std::cerr << "id: " << state->getId() << std::endl;
|
||||||
|
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
|
||||||
|
std::cerr << "Headers:" << std::endl;
|
||||||
|
for (auto it : msg->openInfo.headers)
|
||||||
|
{
|
||||||
|
std::cerr << it.first << ": " << it.second << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to the 'real' server
|
||||||
|
std::string url(remoteUrl);
|
||||||
|
url += msg->openInfo.uri;
|
||||||
|
state->webSocket().setUrl(url);
|
||||||
|
state->webSocket().start();
|
||||||
|
|
||||||
|
// we should sleep here for a bit until we've established the
|
||||||
|
// connection with the remote server
|
||||||
|
while (!state->isConnected())
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||||
|
{
|
||||||
|
std::cerr << "Closed connection"
|
||||||
|
<< " code " << msg->closeInfo.code << " reason "
|
||||||
|
<< msg->closeInfo.reason << std::endl;
|
||||||
|
state->webSocket().close(msg->closeInfo.code, msg->closeInfo.reason);
|
||||||
|
}
|
||||||
|
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Connection error: " << msg->errorInfo.reason << std::endl;
|
||||||
|
ss << "#retries: " << msg->errorInfo.retries << std::endl;
|
||||||
|
ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl;
|
||||||
|
ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl;
|
||||||
|
std::cerr << ss.str();
|
||||||
|
}
|
||||||
|
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
|
{
|
||||||
|
std::cerr << "Received " << msg->wireSize << " bytes from client" << std::endl;
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
std::cerr << "payload " << msg->str << std::endl;
|
||||||
|
}
|
||||||
|
state->webSocket().send(msg->str, msg->binary);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
auto res = server.listen();
|
auto res = server.listen();
|
||||||
if (!res.first)
|
if (!res.first)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user