Skip to content

Commit 485561a

Browse files
committed
ensure aio send functions return errorValues
1 parent 0a2cb1c commit 485561a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ aio
384384
#> < recvAio >
385385
#> - $data for message data
386386
aio$data |> str()
387-
#> num [1:100000000] -0.4007 -0.5114 1.4174 0.0758 0.2671 ...
387+
#> num [1:100000000] -1.07171 -1.2844 0.69956 -0.00593 0.55111 ...
388388
```
389389

390390
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -540,11 +540,11 @@ ncurl("https://httpbin.org/headers")
540540
#> [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
541541
#> [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
542542
#> [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
543-
#> [76] 2d 36 33 31 30 63 62 64 31 2d 36 37 66 66 32 64 31 30 30 66 39 64 33 66 66
544-
#> [101] 61 37 32 62 33 61 63 35 37 22 0a 20 20 7d 0a 7d 0a
543+
#> [76] 2d 36 33 31 30 64 30 34 38 2d 37 30 63 39 65 34 30 38 30 62 61 63 38 62 35
544+
#> [101] 31 36 64 32 30 62 34 30 31 22 0a 20 20 7d 0a 7d 0a
545545
#>
546546
#> $data
547-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6310cbd1-67ff2d100f9d3ffa72b3ac57\"\n }\n}\n"
547+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6310d048-70c9e4080bac8b516d20b401\"\n }\n}\n"
548548
```
549549

550550
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -560,7 +560,7 @@ res
560560
#> - $data for message data
561561

562562
call_aio(res)$data
563-
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6310cbd2-332f7efa1a782b527ba19a00\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.133\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
563+
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6310d048-43a6602f3a64cf211e9e8636\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.133\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
564564
```
565565

566566
In this respect, it may be used as a performant and lightweight method
@@ -603,10 +603,10 @@ s |> send('{"action": "subscribe", "symbols": "EURUSD"}')
603603
#> [26] 73 79 6d 62 6f 6c 73 22 3a 20 22 45 55 52 55 53 44 22 7d 00
604604

605605
s |> recv(keep.raw = FALSE)
606-
#> [1] "{\"s\":\"EURUSD\",\"a\":0.99382,\"b\":0.99375,\"dc\":\"-1.0032\",\"dd\":\"-0.0100\",\"ppms\":false,\"t\":1662045139000}"
606+
#> [1] "{\"s\":\"EURUSD\",\"a\":0.9944,\"b\":0.9941,\"dc\":\"-0.9443\",\"dd\":\"-0.0094\",\"ppms\":false,\"t\":1662046284000}"
607607

608608
s |> recv(keep.raw = FALSE)
609-
#> [1] "{\"s\":\"EURUSD\",\"a\":0.99377,\"b\":0.99375,\"dc\":\"-1.0083\",\"dd\":\"-0.0100\",\"ppms\":false,\"t\":1662045139000}"
609+
#> [1] "{\"s\":\"EURUSD\",\"a\":0.99413,\"b\":0.99411,\"dc\":\"-0.9717\",\"dd\":\"-0.0097\",\"ppms\":false,\"t\":1662046284000}"
610610

611611
close(s)
612612
```

src/aio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,19 @@ SEXP rnng_send_aio(SEXP socket, SEXP data, SEXP timeout) {
420420
xc = nng_msg_alloc(&msg, 0);
421421
if (xc) {
422422
R_Free(saio);
423-
return Rf_ScalarInteger(xc);
423+
return mk_error(xc);
424424
}
425425
xc = nng_msg_append(msg, dp, xlen);
426426
if (xc) {
427427
nng_msg_free(msg);
428428
R_Free(saio);
429-
return Rf_ScalarInteger(xc);
429+
return mk_error(xc);
430430
}
431431
xc = nng_aio_alloc(&saio->aio, saio_complete, saio);
432432
if (xc) {
433433
nng_msg_free(msg);
434434
R_Free(saio);
435-
return Rf_ScalarInteger(xc);
435+
return mk_error(xc);
436436
}
437437

438438
nng_aio_set_msg(saio->aio, msg);
@@ -466,20 +466,20 @@ SEXP rnng_ctx_send_aio(SEXP context, SEXP data, SEXP timeout) {
466466
xc = nng_msg_alloc(&msg, 0);
467467
if (xc) {
468468
R_Free(saio);
469-
return Rf_ScalarInteger(xc);
469+
return mk_error(xc);
470470
}
471471

472472
xc = nng_msg_append(msg, dp, xlen);
473473
if (xc) {
474474
nng_msg_free(msg);
475475
R_Free(saio);
476-
return Rf_ScalarInteger(xc);
476+
return mk_error(xc);
477477
}
478478
xc = nng_aio_alloc(&saio->aio, saio_complete, saio);
479479
if (xc) {
480480
nng_msg_free(msg);
481481
R_Free(saio);
482-
return Rf_ScalarInteger(xc);
482+
return mk_error(xc);
483483
}
484484

485485
nng_aio_set_msg(saio->aio, msg);
@@ -518,15 +518,15 @@ SEXP rnng_stream_send_aio(SEXP stream, SEXP data, SEXP timeout) {
518518
if (xc) {
519519
R_Free(iov);
520520
R_Free(iaio);
521-
return Rf_ScalarInteger(xc);
521+
return mk_error(xc);
522522
}
523523

524524
xc = nng_aio_set_iov(iaio->aio, 1u, iov);
525525
if (xc) {
526526
nng_aio_free(iaio->aio);
527527
R_Free(iov);
528528
R_Free(iaio);
529-
return Rf_ScalarInteger(xc);
529+
return mk_error(xc);
530530
}
531531

532532
nng_aio_set_timeout(iaio->aio, dur);

0 commit comments

Comments
 (0)