clang-format
This commit is contained in:
@ -61,7 +61,7 @@ namespace ix
|
||||
|
||||
// Server connection
|
||||
state->webSocket().setOnMessageCallback([webSocket, state, verbose](
|
||||
const WebSocketMessagePtr& msg) {
|
||||
const WebSocketMessagePtr& msg) {
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
spdlog::info("New connection to remote server");
|
||||
@ -101,61 +101,61 @@ namespace ix
|
||||
});
|
||||
|
||||
// Client connection
|
||||
webSocket->setOnMessageCallback([state, remoteUrl, verbose](
|
||||
const WebSocketMessagePtr& msg) {
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
spdlog::info("New connection from client");
|
||||
spdlog::info("id: {}", state->getId());
|
||||
spdlog::info("Uri: {}", msg->openInfo.uri);
|
||||
spdlog::info("Headers:");
|
||||
for (auto it : msg->openInfo.headers)
|
||||
webSocket->setOnMessageCallback(
|
||||
[state, remoteUrl, verbose](const WebSocketMessagePtr& msg) {
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
spdlog::info("{}: {}", it.first, it.second);
|
||||
spdlog::info("New connection from client");
|
||||
spdlog::info("id: {}", state->getId());
|
||||
spdlog::info("Uri: {}", msg->openInfo.uri);
|
||||
spdlog::info("Headers:");
|
||||
for (auto it : msg->openInfo.headers)
|
||||
{
|
||||
spdlog::info("{}: {}", it.first, it.second);
|
||||
}
|
||||
|
||||
// Connect to the 'real' server
|
||||
std::string url(remoteUrl);
|
||||
url += msg->openInfo.uri;
|
||||
state->webSocket().setUrl(url);
|
||||
state->webSocket().disableAutomaticReconnection();
|
||||
state->webSocket().start();
|
||||
|
||||
// we should sleep here for a bit until we've established the
|
||||
// connection with the remote server
|
||||
while (state->webSocket().getReadyState() != ReadyState::Open)
|
||||
{
|
||||
spdlog::info("waiting for server connection establishment");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
spdlog::info("server connection established");
|
||||
}
|
||||
|
||||
// Connect to the 'real' server
|
||||
std::string url(remoteUrl);
|
||||
url += msg->openInfo.uri;
|
||||
state->webSocket().setUrl(url);
|
||||
state->webSocket().disableAutomaticReconnection();
|
||||
state->webSocket().start();
|
||||
|
||||
// we should sleep here for a bit until we've established the
|
||||
// connection with the remote server
|
||||
while (state->webSocket().getReadyState() != ReadyState::Open)
|
||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
spdlog::info("waiting for server connection establishment");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
spdlog::info("Closed client connection: client id {} code {} reason {}",
|
||||
state->getId(),
|
||||
msg->closeInfo.code,
|
||||
msg->closeInfo.reason);
|
||||
state->webSocket().close(msg->closeInfo.code, msg->closeInfo.reason);
|
||||
}
|
||||
spdlog::info("server connection established");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
spdlog::info("Closed client connection: client id {} code {} reason {}",
|
||||
state->getId(),
|
||||
msg->closeInfo.code,
|
||||
msg->closeInfo.reason);
|
||||
state->webSocket().close(msg->closeInfo.code, msg->closeInfo.reason);
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||
{
|
||||
spdlog::error("Connection error: {}", msg->errorInfo.reason);
|
||||
spdlog::error("#retries: {}", msg->errorInfo.retries);
|
||||
spdlog::error("Wait time(ms): {}", msg->errorInfo.wait_time);
|
||||
spdlog::error("HTTP Status: {}", msg->errorInfo.http_status);
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
spdlog::info("Received {} bytes from client", msg->wireSize);
|
||||
if (verbose)
|
||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||
{
|
||||
spdlog::info("payload {}", msg->str);
|
||||
spdlog::error("Connection error: {}", msg->errorInfo.reason);
|
||||
spdlog::error("#retries: {}", msg->errorInfo.retries);
|
||||
spdlog::error("Wait time(ms): {}", msg->errorInfo.wait_time);
|
||||
spdlog::error("HTTP Status: {}", msg->errorInfo.http_status);
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
spdlog::info("Received {} bytes from client", msg->wireSize);
|
||||
if (verbose)
|
||||
{
|
||||
spdlog::info("payload {}", msg->str);
|
||||
}
|
||||
|
||||
state->webSocket().send(msg->str, msg->binary);
|
||||
}
|
||||
});
|
||||
state->webSocket().send(msg->str, msg->binary);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
auto res = server.listen();
|
||||
|
Reference in New Issue
Block a user