Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^compile_commands\.json$
^\.cache$
^cran-comments\.md$
^CLAUDE.md$
18 changes: 8 additions & 10 deletions src/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,13 @@ SEXP rnng_recv(SEXP con, SEXP mode, SEXP block, SEXP bytes) {

const int mod = nano_matcharg(mode);
nng_socket *sock = (nng_socket *) NANO_PTR(con);
nng_msg *msgp = NULL;

if (flags <= 0) {

if ((xc = nng_recv(*sock, &buf, &sz, NNG_FLAG_ALLOC + (flags < 0 || NANO_INTEGER(block) != 1) * NNG_FLAG_NONBLOCK)))
if ((xc = nng_recvmsg(*sock, &msgp, (flags < 0 || NANO_INTEGER(block) != 1) * NNG_FLAG_NONBLOCK)))
goto fail;

res = nano_decode(buf, sz, mod, NANO_PROT(con));
nng_free(buf, sz);


} else {

nng_aio *aiop = NULL;
Expand All @@ -474,13 +472,13 @@ SEXP rnng_recv(SEXP con, SEXP mode, SEXP block, SEXP bytes) {
nng_aio_free(aiop);
goto fail;
}
nng_msg *msgp = nng_aio_get_msg(aiop);
msgp = nng_aio_get_msg(aiop);
nng_aio_free(aiop);
buf = nng_msg_body(msgp);
sz = nng_msg_len(msgp);
res = nano_decode(buf, sz, mod, NANO_PROT(con));
nng_msg_free(msgp);
}
buf = nng_msg_body(msgp);
sz = nng_msg_len(msgp);
res = nano_decode(buf, sz, mod, NANO_PROT(con));
nng_msg_free(msgp);

} else if (!NANO_PTR_CHECK(con, nano_ContextSymbol)) {

Expand Down
12 changes: 8 additions & 4 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ static void rnng_messenger_thread(void *args) {
SEXP socket = CADR(plist);
SEXP key = CADDR(plist);
nng_socket *sock = (nng_socket *) NANO_PTR(socket);
nng_msg *msgp = NULL;
unsigned char *buf;
size_t sz;
time_t now;
struct tm *tms;
int xc;

while (1) {
xc = nng_recv(*sock, &buf, &sz, NNG_FLAG_ALLOC);
xc = nng_recvmsg(*sock, &msgp, 0);
time(&now);
tms = localtime(&now);

Expand All @@ -91,13 +92,16 @@ static void rnng_messenger_thread(void *args) {
break;
}

buf = nng_msg_body(msgp);
sz = nng_msg_len(msgp);

if (!strncmp((char *) buf, ":", 1)) {
if (!strncmp((char *) buf, ":c ", 3)) {
nano_printf(1,
"| <- peer connected: %d-%02d-%02d %02d:%02d:%02d\n",
tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
tms->tm_hour, tms->tm_min, tms->tm_sec);
nng_free(buf, sz);
nng_msg_free(msgp);
nano_buf enc;
nano_encode(&enc, key);
xc = nng_send(*sock, enc.buf, enc.cur, NNG_FLAG_NONBLOCK);
Expand All @@ -115,7 +119,7 @@ static void rnng_messenger_thread(void *args) {
"| -> peer disconnected: %d-%02d-%02d %02d:%02d:%02d\n",
tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
tms->tm_hour, tms->tm_min, tms->tm_sec);
nng_free(buf, sz);
nng_msg_free(msgp);
continue;
}
}
Expand All @@ -125,7 +129,7 @@ static void rnng_messenger_thread(void *args) {
(char *) buf, (int) sz, "",
tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
tms->tm_hour, tms->tm_min, tms->tm_sec);
nng_free(buf, sz);
nng_msg_free(msgp);

}

Expand Down
Loading