Skip to content

Commit b4d3b44

Browse files
committed
request() msgid -> id
1 parent 1f91dec commit b4d3b44

File tree

7 files changed

+19
-27
lines changed

7 files changed

+19
-27
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Adds `pipe_id()` for returning the integer pipe ID for a resolved 'recvAio'.
88
* Adds `write_stdout()` which performs a non-buffered write to `stdout`, to avoid interleaved messages when used concurrently by different processes.
99
* Adds `read_stdin()` which performs a read from `stdin` on a background thread, relayed via an 'inproc' socket so that it may be consumed via `recv()` or `recv_aio()`.
10-
* `request()` gains integer argument `msgid`. This may be specified to have a special payload sent asynchronously upon timeout (to communicate with the connected party).
10+
* `request()` gains integer argument `id`. This may be specified to have a special payload sent asynchronously upon timeout (to communicate with the connected party).
1111

1212
#### Updates
1313

R/context.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ reply <- function(
180180
#' @param cv (optional) a 'conditionVariable' to signal when the async receive
181181
#' is complete, or NULL. If any other value is supplied, this will cause the
182182
#' pipe connection to be dropped when the async receive is complete.
183-
#' @param msgid (optional) integer message ID to send a special payload to the
183+
#' @param id (optional) integer message ID to send a special payload to the
184184
#' context upon timeout (asynchronously) consisting of an integer zero,
185-
#' followed by the value of `msgid` supplied.
185+
#' followed by the value of `id` supplied.
186186
#'
187187
#' @return A 'recvAio' (object of class 'mirai' and 'recvAio') (invisibly).
188188
#'
@@ -230,6 +230,6 @@ request <- function(
230230
recv_mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric", "raw", "string"),
231231
timeout = NULL,
232232
cv = NULL,
233-
msgid = NULL
233+
id = NULL
234234
)
235-
data <- .Call(rnng_request, context, data, send_mode, recv_mode, timeout, cv, msgid, environment())
235+
data <- .Call(rnng_request, context, data, send_mode, recv_mode, timeout, cv, id, environment())

man/request.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ SEXP nano_HeadersSymbol;
1414
SEXP nano_IdSymbol;
1515
SEXP nano_ListenerSymbol;
1616
SEXP nano_MonitorSymbol;
17-
SEXP nano_MsgidSymbol;
1817
SEXP nano_ProtocolSymbol;
1918
SEXP nano_ResolveSymbol;
2019
SEXP nano_ResponseSymbol;
@@ -49,7 +48,6 @@ static void RegisterSymbols(void) {
4948
nano_IdSymbol = Rf_install("id");
5049
nano_ListenerSymbol = Rf_install("listener");
5150
nano_MonitorSymbol = Rf_install("monitor");
52-
nano_MsgidSymbol = Rf_install("msgid");
5351
nano_ProtocolSymbol = Rf_install("protocol");
5452
nano_ResolveSymbol = Rf_install("resolve");
5553
nano_ResponseSymbol = Rf_install("response");

src/nanonext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ typedef struct nano_saio_s {
189189
nng_ctx *ctx;
190190
nng_aio *aio;
191191
void *cb;
192-
int msgid;
192+
int id;
193193
} nano_saio;
194194

195195
typedef struct nano_cv_s {
@@ -255,7 +255,6 @@ extern SEXP nano_HeadersSymbol;
255255
extern SEXP nano_IdSymbol;
256256
extern SEXP nano_ListenerSymbol;
257257
extern SEXP nano_MonitorSymbol;
258-
extern SEXP nano_MsgidSymbol;
259258
extern SEXP nano_ProtocolSymbol;
260259
extern SEXP nano_ResolveSymbol;
261260
extern SEXP nano_ResponseSymbol;

src/sync.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ static void request_complete(void *arg) {
3636
raio->data = msg;
3737
nng_pipe p = nng_msg_get_pipe(msg);
3838
res = - (int) p.id;
39-
} else if (res == 5) {
40-
const int id = saio->msgid;
41-
if (id) {
42-
nng_msg *msg = NULL;
43-
if (nng_msg_alloc(&msg, 0) == 0) {
44-
if (nng_msg_append_u32(msg, 0) ||
45-
nng_msg_append(msg, &id, sizeof(id)) ||
46-
nng_ctx_sendmsg(*saio->ctx, msg, 0)) {
47-
nng_msg_free(msg);
48-
}
39+
} else if (res == 5 && saio->id) {
40+
nng_msg *msg = NULL;
41+
if (nng_msg_alloc(&msg, 0) == 0) {
42+
if (nng_msg_append_u32(msg, 0) ||
43+
nng_msg_append(msg, &saio->id, sizeof(int)) ||
44+
nng_ctx_sendmsg(*saio->ctx, msg, 0)) {
45+
nng_msg_free(msg);
4946
}
5047
}
5148
}
@@ -447,7 +444,7 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
447444
nano_cv *ncv = signal ? (nano_cv *) NANO_PTR(cvar) : NULL;
448445

449446
saio->ctx = ctx;
450-
saio->msgid = id;
447+
saio->id = id;
451448

452449
if ((xc = nng_msg_alloc(&msg, 0)) ||
453450
(xc = nng_msg_append(msg, buf.buf, buf.cur)) ||
@@ -474,7 +471,7 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
474471
PROTECT(aio = R_MakeExternalPtr(raio, nano_AioSymbol, NANO_PROT(con)));
475472
R_RegisterCFinalizerEx(aio, request_finalizer, TRUE);
476473
Rf_setAttrib(aio, nano_ContextSymbol, con);
477-
Rf_setAttrib(aio, nano_MsgidSymbol, Rf_ScalarInteger(id));
474+
Rf_setAttrib(aio, nano_IdSymbol, Rf_ScalarInteger(id));
478475

479476
PROTECT(env = R_NewEnv(R_NilValue, 0, 0));
480477
Rf_classgets(env, nano_reqAio);

tests/tests.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ test_class("recvAio", cs <- request(.context(req$socket), data = TRUE, cv = NA))
298298
test_notnull(cs$data)
299299
test_true(recv(ctxn, block = 500))
300300
test_zero(send(ctxn, TRUE, mode = 1L, block = 500))
301-
test_class("recvAio", cs <- request(.context(req$socket), data = TRUE, timeout = 5, msgid = 12L))
301+
test_class("recvAio", cs <- request(.context(req$socket), data = TRUE, timeout = 5, id = 12L))
302302
test_equal(5L, cs[])
303303
test_identical(c(0L, 12L), recv(ctxn, mode = 5L, block = 500))
304304
test_zero(reap(ctxn))
@@ -388,8 +388,6 @@ test_class("nanoSocket", poly1 <- socket(protocol = "poly"))
388388
test_class("nanoSocket", poly2 <- socket(protocol = "poly"))
389389
test_class("nanoMonitor", m <- monitor(poly, cv))
390390
test_print(m)
391-
test_class("sendAio", send_aio(poly, "one", timeout = 50))
392-
test_null(msleep(55))
393391
test_zero(listen(poly))
394392
test_null(read_monitor(m))
395393
test_zero(dial(poly1))

0 commit comments

Comments
 (0)