Skip to content

Commit 50511fc

Browse files
committed
correct casts in messenger()
1 parent 120c517 commit 50511fc

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ In this respect, it may be used as a performant and lightweight method for makin
439439
440440
s <- stream(dial = "wss://demo.piesocket.com/v3/channel_1", textframes = TRUE)
441441
s
442-
s |> recv(keep.raw = FALSE)
442+
s |> recv()
443443
444444
```
445445

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ aio
379379
#> < recvAio >
380380
#> - $data for message data
381381
aio$data |> str()
382-
#> num [1:100000000] -0.0183 0.9349 -0.8196 0.0607 -0.1335 ...
382+
#> num [1:100000000] -1.072 1.447 0.962 -0.483 -0.843 ...
383383
```
384384

385385
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -516,11 +516,11 @@ ncurl("http://httpbin.org/headers")
516516
#> [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
517517
#> [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
518518
#> [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
519-
#> [76] 2d 36 32 36 35 39 30 34 32 2d 34 38 34 35 64 63 30 36 36 32 66 30 63 38 66
520-
#> [101] 30 32 31 33 63 35 63 63 32 22 0a 20 20 7d 0a 7d 0a
519+
#> [76] 2d 36 32 36 35 62 32 62 31 2d 33 33 30 61 30 30 30 37 32 33 61 32 61 39 63
520+
#> [101] 36 36 61 30 36 66 38 36 61 22 0a 20 20 7d 0a 7d 0a
521521
#>
522522
#> $data
523-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-62659042-4845dc0662f0c8f0213c5cc2\"\n }\n}\n"
523+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-6265b2b1-330a000723a2a9c66a06f86a\"\n }\n}\n"
524524
```
525525

526526
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -535,7 +535,7 @@ res
535535
#> - $raw for raw message
536536

537537
call_aio(res)$data
538-
#> [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-62659042-7ab689205d5bd45b62c030da\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
538+
#> [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-6265b2b1-09b62748201d88f5057952ab\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
539539
```
540540

541541
In this respect, it may be used as a performant and lightweight method
@@ -556,7 +556,12 @@ s
556556
#> - type: dialer
557557
#> - url: wss://demo.piesocket.com/v3/channel_1
558558
#> - textframes: TRUE
559-
s |> recv(keep.raw = FALSE)
559+
s |> recv()
560+
#> $raw
561+
#> [1] 7b 22 65 72 72 6f 72 22 3a 22 4d 69 73 73 69 6e 67 20 61 70 69 4b 65 79 22
562+
#> [26] 7d
563+
#>
564+
#> $data
560565
#> [1] "{\"error\":\"Missing apiKey\"}"
561566
```
562567

src/utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void thread_finalizer(SEXP xptr) {
480480
static void rnng_thread(void *arg) {
481481

482482
nng_socket *sock = (nng_socket *) arg;
483-
char *buf = NULL;
483+
unsigned char *buf;
484484
size_t sz;
485485
time_t now;
486486
struct tm *tms;
@@ -498,15 +498,15 @@ static void rnng_thread(void *arg) {
498498
break;
499499
}
500500

501-
if (!strncmp(buf, ":", 1)) {
502-
if (!strcmp(buf, ":c ")) {
501+
if (!strncmp((char *) buf, ":", 1)) {
502+
if (!strcmp((char *) buf, ":c ")) {
503503
REprintf("| <- peer connected: %d-%02d-%02d %02d:%02d:%02d\n",
504504
tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
505505
tms->tm_hour, tms->tm_min, tms->tm_sec);
506506
nng_free(buf, sz);
507507
continue;
508508
}
509-
if (!strcmp(buf, ":d ")) {
509+
if (!strcmp((char *) buf, ":d ")) {
510510
REprintf("| -> peer disconnected: %d-%02d-%02d %02d:%02d:%02d\n",
511511
tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday,
512512
tms->tm_hour, tms->tm_min, tms->tm_sec);

tests/tests.R

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ nanotest(inherits(n, "nanoObject"))
1010
nanotest(inherits(n$socket, "nanoSocket"))
1111
nanotest(inherits(n$socket, "nano"))
1212
nanotest(identical(is_nano(n), TRUE))
13+
n$newmethod <- "doesnotwork"
14+
nanotest(is.null(n$newmethod))
15+
1316
nanotest(is.integer(attr(n$socket, "id")))
1417
nanotest(n$socket$state == "opened")
1518
nanotest(n$socket$protocol == "pair")
@@ -46,18 +49,24 @@ nanotest(identical(is_nano(saio), FALSE))
4649
nanotestn(saio[["aio"]])
4750
nanotestn(saio$result)
4851
raio <- n1$recv_aio(timeout = 500)
49-
nanotest(identical(is_aio(raio), TRUE))
52+
raio$newfield <- "doesnotwork"
53+
nanotest(is.null(raio$newfield))
54+
nanotest(is_aio(raio) == TRUE)
5055
nanotestn(raio[["aio"]])
51-
nanotestn(raio$data)
5256
nanotestn(raio$raw)
57+
nanotestn(raio$data)
5358
saio <- n$send_aio(c(1.1, 2.2), mode = "raw", timeout = 500)
59+
saio$newfield <- "doesnotwork"
60+
nanotest(is.null(saio$newfield))
61+
nanotest(is_aio(saio) == TRUE)
5462
nanotest(is.logical(unresolved(saio)))
5563
msg <- n1$recv_aio(mode = "double", timeout = 500, keep.raw = FALSE)
5664
nanotest(is.null(stop_aio(msg)))
5765
nanotest(is.null(stop_aio(n)))
5866
nanotest(identical(call_aio(msg), msg))
67+
nanotestn(tryCatch(msg$data, error = function(e) 0L))
5968
nanotest(identical(call_aio(n), n))
60-
nanotest(identical(is_aio(n), FALSE))
69+
nanotest(is_aio(n) == FALSE)
6170

6271
xc <- n$dial(url = "inproc://two", autostart = TRUE)
6372
nanotest(is.integer(xc))
@@ -97,10 +106,11 @@ msg <- recv_aio(ctx1, mode = "serial", timeout = 400, keep.raw = FALSE)
97106
nanotest(is.logical(unresolved(msg)))
98107
nanotestn(call_aio(msg)$data)
99108
nanotest(unresolved(msg) == FALSE)
100-
nanotestwn(send(ctx, c(TRUE, FALSE, TRUE), block = 500))
101-
msg <- recv_aio(ctx1, mode = "logical", timeout = 500)
102-
nanotestn(call_aio(msg)$raw)
103-
nanotestwn(request(ctx, data.frame(), recv_mode = "complex", timeout = 100))
109+
nanotestwn(send(ctx, c(TRUE, FALSE, TRUE), block = 300))
110+
msg <- recv_aio(ctx1, mode = "logical", timeout = 300)
111+
nanotestn(msg$raw)
112+
nanotestwn(request(ctx, c(1+3i, 4+2i), recv_mode = "complex", timeout = 300))
113+
nanotestwn(reply(ctx1, execute = identity, send_mode = "raw", timeout = 300))
104114
nanotest(close(ctx) == 0L)
105115
nanotestw(close(ctx) > 0L)
106116
nanotest(ctx$state == "closed")
@@ -124,6 +134,7 @@ nanotest(survey_time(sock, time = 5000) == 0L)
124134
nanotest(close(sock) == 0L)
125135
nanotest(close(sock2) == 0L)
126136

137+
nanotestwn(ncurl("http://www.cam.ac.uk/"))
127138
nanotestwn(ncurl("http://httpbin.org/post", convert = FALSE, method = "POST", headers = c(`Content-Type` = "text/plain"), data = "test"))
128139
nanotestwn(ncurl("http://httpbin.org/post", convert = FALSE, method = "POST", headers = list(`Content-Type` = "text/plain")))
129140
nanotestwn(ncurl("http://httpbin.org/put", async = TRUE, method = "PUT", headers = c(Authorization = "Bearer token"), data = "test"))
@@ -135,6 +146,8 @@ nanotest(is.character(ver <- nng_version()) && length(ver) == 2L)
135146
nanotest(is.character(nng_error(0L)))
136147
nanotest(is_nul_byte(as.raw(0L)) && !is_nul_byte(NULL))
137148
nanotest(!is_error_value(1L))
149+
nanotestwn(messenger("invalidURL"))
150+
nanotestn(tryCatch(.mirai_scm(), error = function(e) 0L))
138151

139152
nanotest(inherits(bus <- socket(protocol = "bus"), "nanoSocket"))
140153
nanotest(inherits(push <- socket(protocol = "push"), "nanoSocket"))

0 commit comments

Comments
 (0)