ctrl: also listen on tcp
This commit is contained in:
parent
51e33b5159
commit
e159f62260
3 changed files with 34 additions and 42 deletions
|
@ -1,4 +1,6 @@
|
|||
#include <nng/nng.h>
|
||||
#include <nng/protocol/pubsub0/pub.h>
|
||||
#include <nng/protocol/pubsub0/sub.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
@ -834,8 +836,33 @@ int main(int argc, char *argv[])
|
|||
nng_set_resolve_thread_max(1);
|
||||
|
||||
ControllerContext ctx;
|
||||
ctx.pub = make_ctrl_pub(CtrlUrlIpc);
|
||||
ctx.sub = make_ctrl_sub(DoomUrlIpc);
|
||||
|
||||
// ctrl pub socket: ctrl -> dooms
|
||||
if (int res = nng_pub0_open(&ctx.pub))
|
||||
dp_nng_fatal("ctrl/nng_pub0_open", res);
|
||||
|
||||
if (int res = nng_listen(ctx.pub, CtrlUrlIpc, nullptr, 0))
|
||||
dp_nng_fatal("ctrl/nng_listen/ipc", res);
|
||||
|
||||
if (int res = nng_listen(ctx.pub, CtrlUrlTcp, nullptr, 0))
|
||||
dp_nng_fatal("ctrl/nng_listen/tcp4", res);
|
||||
|
||||
// ctrl sub socket: dooms -> ctrl
|
||||
if (int res = nng_sub0_open(&ctx.sub))
|
||||
dp_nng_fatal("ctrl/nng_sub0_open", res);
|
||||
|
||||
if (int res = nng_setopt(ctx.sub, NNG_OPT_SUB_SUBSCRIBE, "", 0))
|
||||
dp_nng_fatal("ctrl/subscribe", res);
|
||||
|
||||
if (int res = nng_socket_set_ms(ctx.sub, NNG_OPT_RECVTIMEO, 100))
|
||||
dp_nng_fatal("ctrl/recvtimeo", res);
|
||||
|
||||
if (int res = nng_listen(ctx.sub, DoomUrlIpc, NULL, 0))
|
||||
dp_nng_fatal("make_ctrl_sub/nng_listen", res);
|
||||
|
||||
if (int res = nng_listen(ctx.sub, DoomUrlTcp, nullptr, 0))
|
||||
dp_nng_fatal("ctrl/nng_listen/tcp4", res);
|
||||
|
||||
ctx.window = window;
|
||||
ctx.renderer = renderer;
|
||||
ctx.inputs.head.msgType = DP_MT_Inputs;
|
||||
|
|
|
@ -28,41 +28,6 @@ void dp_nng_init_limits(int ncpu_max, int pool_thread_limit_max, int resolv_thre
|
|||
nng_set_resolve_thread_max(resolv_thread_limit);
|
||||
}
|
||||
|
||||
nng_socket make_ctrl_pub(const char *url)
|
||||
{
|
||||
nng_socket sock;
|
||||
int res = 0;
|
||||
|
||||
if ((res = nng_pub0_open(&sock)))
|
||||
dp_nng_fatal("make_ctrl_pub/nng_pub0_open", res);
|
||||
|
||||
if ((res = nng_listen(sock, url, NULL, 0)))
|
||||
dp_nng_fatal("make_ctrl_pub/nng_listen", res);
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
nng_socket make_ctrl_sub(const char *url)
|
||||
{
|
||||
nng_socket sock;
|
||||
int res = 0;
|
||||
|
||||
if ((res = nng_sub0_open(&sock)))
|
||||
dp_nng_fatal("make_ctrl_sub/nng_sub0_open", res);
|
||||
|
||||
if ((res = nng_setopt(sock, NNG_OPT_SUB_SUBSCRIBE, "", 0)))
|
||||
dp_nng_fatal("make_ctrl_sub/subscribe", res);
|
||||
|
||||
if ((res = nng_socket_set_ms(sock, NNG_OPT_RECVTIMEO, 100)))
|
||||
dp_nng_fatal("make_ctrl_sub/recvtimeo", res);
|
||||
|
||||
|
||||
if ((res = nng_listen(sock, url, NULL, 0)))
|
||||
dp_nng_fatal("make_ctrl_sub/nng_listen", res);
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
nng_socket make_doom_pub(const char *url)
|
||||
{
|
||||
nng_socket sock;
|
||||
|
|
|
@ -116,14 +116,14 @@ static inline bool dp_nng_is_timeout(int res)
|
|||
return res == NNG_ETIMEDOUT || res == NNG_EAGAIN;
|
||||
}
|
||||
|
||||
// Controller listens, Dooms dial.
|
||||
// Controller listens, dooms dial.
|
||||
static const char *const CtrlUrlIpc = "ipc://666_ctrl.socket"; // controller publishes here
|
||||
static const char *const DoomUrlIpc = "ipc://666_doom.socket"; // dooms publish here
|
||||
static const char *const CtrlUrlTcp = "tcp4://:42666"; // controller publishes here
|
||||
static const char *const DoomUrlTcp = "tcp4://:42667"; // dooms publish here
|
||||
static const char *const CtrlUrlTcp = "tcp://:42666"; // controller publishes here
|
||||
static const char *const DoomUrlTcp = "tcp://:42667"; // dooms publish here
|
||||
static const int CtrlPort = 42666; // controller publishes on this port
|
||||
static const int DoomPort = 42667; // dooms publish here
|
||||
|
||||
nng_socket make_ctrl_pub(const char *url);
|
||||
nng_socket make_ctrl_sub(const char *url);
|
||||
nng_socket make_doom_pub(const char *url);
|
||||
nng_socket make_doom_sub(const char *url);
|
||||
|
||||
|
|
Loading…
Reference in a new issue