1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-17 19:59:57 +00:00

fix cmake compile error with websockets

This commit is contained in:
Jeff Becker 2017-05-21 08:18:16 -04:00
parent e4cd1a465c
commit 8a3bb50143
2 changed files with 16 additions and 16 deletions

View File

@ -110,7 +110,7 @@ set (CLIENT_SRC
) )
if(WITH_WEBSOCKETS) if(WITH_WEBSOCKETS)
list (APPEND CLIENT_SRC "${LIBI2PD_SRC_DIR}/Websocket.cpp") list (APPEND CLIENT_SRC "${LIBI2PD_CLIENT_SRC_DIR}/Websocket.cpp")
endif () endif ()
add_library(i2pdclient ${CLIENT_SRC}) add_library(i2pdclient ${CLIENT_SRC})

View File

@ -1,4 +1,4 @@
#ifdef USE_EVENTS #ifdef WITH_EVENTS
#include "Websocket.h" #include "Websocket.h"
#include "Log.h" #include "Log.h"
@ -22,7 +22,7 @@ namespace i2p
typedef websocketpp::server<websocketpp::config::asio> ServerImpl; typedef websocketpp::server<websocketpp::config::asio> ServerImpl;
typedef websocketpp::connection_hdl ServerConn; typedef websocketpp::connection_hdl ServerConn;
class WebsocketServerImpl : public EventListener class WebsocketServerImpl : public EventListener
{ {
private: private:
@ -39,20 +39,20 @@ namespace i2p
m_server.set_open_handler(std::bind(&WebsocketServerImpl::ConnOpened, this, std::placeholders::_1)); m_server.set_open_handler(std::bind(&WebsocketServerImpl::ConnOpened, this, std::placeholders::_1));
m_server.set_close_handler(std::bind(&WebsocketServerImpl::ConnClosed, this, std::placeholders::_1)); m_server.set_close_handler(std::bind(&WebsocketServerImpl::ConnClosed, this, std::placeholders::_1));
m_server.set_message_handler(std::bind(&WebsocketServerImpl::OnConnMessage, this, std::placeholders::_1, std::placeholders::_2)); m_server.set_message_handler(std::bind(&WebsocketServerImpl::OnConnMessage, this, std::placeholders::_1, std::placeholders::_2));
m_server.listen(boost::asio::ip::address::from_string(addr), port); m_server.listen(boost::asio::ip::address::from_string(addr), port);
} }
~WebsocketServerImpl() ~WebsocketServerImpl()
{ {
} }
void Start() { void Start() {
m_run = true; m_run = true;
m_server.start_accept(); m_server.start_accept();
m_ws_thread = new std::thread([&] () { m_ws_thread = new std::thread([&] () {
while(m_run) { while(m_run) {
try { try {
m_server.run(); m_server.run();
} catch (std::exception & e ) { } catch (std::exception & e ) {
LogPrint(eLogError, "Websocket server: ", e.what()); LogPrint(eLogError, "Websocket server: ", e.what());
@ -61,7 +61,7 @@ namespace i2p
}); });
m_ev_thread = new std::thread([&] () { m_ev_thread = new std::thread([&] () {
while(m_run) { while(m_run) {
try { try {
m_Service.run(); m_Service.run();
break; break;
} catch (std::exception & e ) { } catch (std::exception & e ) {
@ -82,7 +82,7 @@ namespace i2p
delete m_ev_thread; delete m_ev_thread;
} }
m_ev_thread = nullptr; m_ev_thread = nullptr;
if(m_ws_thread) { if(m_ws_thread) {
m_ws_thread->join(); m_ws_thread->join();
delete m_ws_thread; delete m_ws_thread;
@ -95,7 +95,7 @@ namespace i2p
std::lock_guard<std::mutex> lock(m_connsMutex); std::lock_guard<std::mutex> lock(m_connsMutex);
m_conns.insert(c); m_conns.insert(c);
} }
void ConnClosed(ServerConn c) void ConnClosed(ServerConn c)
{ {
std::lock_guard<std::mutex> lock(m_connsMutex); std::lock_guard<std::mutex> lock(m_connsMutex);
@ -123,20 +123,20 @@ namespace i2p
LogPrint(eLogDebug, "Websocket schedule tick"); LogPrint(eLogDebug, "Websocket schedule tick");
boost::posix_time::seconds dlt(1); boost::posix_time::seconds dlt(1);
m_WebsocketTicker.expires_from_now(dlt); m_WebsocketTicker.expires_from_now(dlt);
m_WebsocketTicker.async_wait(std::bind(&WebsocketServerImpl::HandleTick, this, std::placeholders::_1)); m_WebsocketTicker.async_wait(std::bind(&WebsocketServerImpl::HandleTick, this, std::placeholders::_1));
} }
/** @brief called from m_ev_thread */ /** @brief called from m_ev_thread */
void HandlePumpEvent(const EventType & ev, const uint64_t & val) void HandlePumpEvent(const EventType & ev, const uint64_t & val)
{ {
EventType e; EventType e;
for (const auto & i : ev) for (const auto & i : ev)
e[i.first] = i.second; e[i.first] = i.second;
e["number"] = std::to_string(val); e["number"] = std::to_string(val);
HandleEvent(e); HandleEvent(e);
} }
/** @brief called from m_ws_thread */ /** @brief called from m_ws_thread */
void HandleEvent(const EventType & ev) void HandleEvent(const EventType & ev)
{ {
@ -155,7 +155,7 @@ namespace i2p
con->send(s); con->send(s);
} }
} }
private: private:
typedef std::set<ServerConn, std::owner_less<ServerConn> > ConnList; typedef std::set<ServerConn, std::owner_less<ServerConn> > ConnList;
bool m_run; bool m_run;
@ -175,7 +175,7 @@ namespace i2p
delete m_impl; delete m_impl;
} }
void WebsocketServer::Start() void WebsocketServer::Start()
{ {
m_impl->Start(); m_impl->Start();
@ -185,7 +185,7 @@ namespace i2p
{ {
m_impl->Stop(); m_impl->Stop();
} }
EventListener * WebsocketServer::ToListener() EventListener * WebsocketServer::ToListener()
{ {
return m_impl; return m_impl;