23#include <nng/protocol/reqrep0/rep.h>
31static const wxChar
TraceNng[] = wxT(
"KINNG" );
35 m_socketUrl( aSocketUrl ),
68 std::lock_guard<std::mutex> lock(
m_mutex );
79 std::lock_guard<std::mutex> lock(
m_mutex );
88 nng_listener listener;
91 wxLogTrace(
TraceNng, wxS(
"KINNG_REQUEST_SERVER starting" ) );
93 retCode = nng_rep0_open( &socket );
98 wxString::Format( wxS(
"Got error code %d from nng_rep0_open!" ), retCode ) );
102 retCode = nng_listener_create( &listener, socket,
m_socketUrl.c_str() );
107 wxString::Format( wxS(
"Got error code %d from nng_listener_create!" ),
112 nng_socket_set_ms( socket, NNG_OPT_RECVTIMEO, 500 );
114 nng_listener_start( listener, 0 );
116 wxLogTrace(
TraceNng, wxS(
"KINNG_REQUEST_SERVER listener has started" ) );
124 retCode = nng_recv( socket, &buf, &sz, NNG_FLAG_ALLOC );
126 if( retCode == NNG_ETIMEDOUT )
133 wxString::Format( wxS(
"Got error code %d from nngc_recv!" ), retCode ) );
137 std::string message( buf, sz );
142 std::unique_lock<std::mutex> lock(
m_mutex );
145 retCode = nng_send( socket,
const_cast<std::string::value_type*
>(
m_pendingReply.c_str() ),
151 wxString::Format( wxS(
"Got error code %d from nng_send!" ), retCode ) );
157 wxLogTrace(
TraceNng, wxS(
"KINNG_REQUEST_SERVER shutting down" ) );
std::string m_pendingReply
KINNG_REQUEST_SERVER(const std::string &aSocketUrl)
void Reply(const std::string &aReply)
std::function< void(std::string *)> m_callback
std::atomic< bool > m_shutdown
std::condition_variable m_replyReady
static const wxChar TraceNng[]
Trace nng server debug output.