Skip to content

Commit 4d8b45f

Browse files
committed
complete C level refactor
1 parent ebacbc1 commit 4d8b45f

File tree

16 files changed

+504
-464
lines changed

16 files changed

+504
-464
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#### Updates
1010

11-
* Behavioural change: messages have been upgraded to warnings across the package to allow for enhanced reporting of the originating call e.g. via `warnings()`. Note that warnings are only printed when execution returns to the top level, e.g. at the end of a function or loop. If timely printing to stderr is required e.g. for logging, that should be written into your error handler within the function/loop etc.
11+
* Behavioural change: messages have been upgraded to warnings across the package to allow for enhanced reporting of the originating call e.g. via `warnings()` and flexibility in handling by setting the value of 'warn' using `options()`. `options(warn = 1)` is set upon package load for immediate printing of warnings (and reverted upon unload).
1212
* Unified `send()` and `recv()` functions, and their asynchronous counterparts `send_aio()` and `recv_aio()`, are now S3 generics and can be used across Sockets, Contexts and Streams.
1313
* Revised 'block' argument for `send()` and `recv()` now allows an integer value for setting a timeout.
1414
* `send_ctx()` and `recv_ctx()` are deprecated and will be removed in a future package version - the methods for `send()` and `recv()` should be used instead.

R/messenger.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
#'
2020
#' \code{:q} is the command to quit.
2121
#'
22-
#' NOTE: This is an experimental feature that is currently undergoing
23-
#' testing.
22+
#' NOTE: This is a proof of concept meant for use within friendly internal
23+
#' networks. Currently no measures are taken to verify the identity of
24+
#' endpoints, hence should not be used to transmit sensitive information.
2425
#'
2526
#' @export
2627
#'

R/nano.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nano <- function(protocol = c("pair", "bus", "push", "pull", "req", "rep",
6161

6262
nano <- `class<-`(new.env(hash = FALSE), "nanoObject")
6363
socket <- socket(protocol)
64-
makeActiveBinding("socket", function(x) socket, nano)
64+
makeActiveBinding(sym = "socket", fun = function(x) socket, env = nano)
6565

6666
if (!missing(dial)) {
6767
dial(nano, url = dial, autostart = autostart)

R/nanonext-package.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,16 @@ NULL
128128
info = TRUE,
129129
FALSE)
130130
.logging. <<- .logging.
131+
.warn. <- getOption("warn")
132+
.warn. <<- .warn.
133+
options(warn = 1L)
131134
invisible()
132135
}
133136

137+
.onUnload <- function(libpath) {
138+
options(warn = .warn.)
139+
invisible()
140+
}
141+
142+
.warn. <- NULL
134143
.logging. <- FALSE

R/utils.R

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,25 @@ nng_version <- function() .Call(rnng_version)
2424
#'
2525
#' Translate integer exit code to human readable form. All package functions
2626
#' return an integer exit code on error rather than the expected return
27-
#' value.
27+
#' value. These are classed 'errorValue' and may be checked by the function
28+
#' \code{\link{is_error_value}}.
2829
#'
2930
#' @param xc integer exit code to translate.
3031
#'
3132
#' @return A character vector.
3233
#'
34+
#' @section Warnings:
35+
#'
36+
#' A warning is generated every time an 'errorValue' is returned. The package
37+
#' changes the behaviour of warnings by setting \code{options(warn = 1)}
38+
#' upon package load. This prints the warning to the console as soon as it
39+
#' occurs, rather than the default of waiting for the top–level function to
40+
#' return.
41+
#'
42+
#' See \code{\link{warning}} or the entry for 'warn' in \code{\link{options}}
43+
#' for further details. The original option value for 'warn' is reverted upon
44+
#' package unload.
45+
#'
3346
#' @examples
3447
#' nng_error(1L)
3548
#'
@@ -60,14 +73,26 @@ is_nul_byte <- function(x) identical(x, as.raw(0L))
6073

6174
#' Is Error Value
6275
#'
63-
#' Is the object an error value generated by NNG. All receive functions class
64-
#' integer error codes as 'errorValue' to be easily distinguishable from
65-
#' integer message values.
76+
#' Is the object an error value generated by NNG. All returned integer error
77+
#' codes are classed as 'errorValue' to be distinguishable from integer
78+
#' message values.
6679
#'
6780
#' @param x an object.
6881
#'
6982
#' @return Logical value TRUE if 'x' is of class 'errorValue', FALSE otherwise.
7083
#'
84+
#' @section Warnings:
85+
#'
86+
#' A warning is generated every time an 'errorValue' is returned. The package
87+
#' changes the behaviour of warnings by setting \code{options(warn = 1)}
88+
#' upon package load. This prints the warning to the console as soon as it
89+
#' occurs, rather than the default of waiting for the top–level function to
90+
#' return.
91+
#'
92+
#' See \code{\link{warning}} or the entry for 'warn' in \code{\link{options}}
93+
#' for further details. The original option value for 'warn' is reverted upon
94+
#' package unload.
95+
#'
7196
#' @examples
7297
#' is_error_value(1L)
7398
#'

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ aio
370370
#> < recvAio >
371371
#> - $data for message data
372372
aio$data |> str()
373-
#> num [1:100000000] -0.526 1.488 1.712 0.296 -0.703 ...
373+
#> num [1:100000000] -0.257 -0.142 -0.473 0.718 -1.426 ...
374374
```
375375

376376
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -505,11 +505,11 @@ ncurl("http://httpbin.org/headers")
505505
#> [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
506506
#> [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
507507
#> [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
508-
#> [76] 2d 36 32 34 64 36 33 32 33 2d 35 65 30 62 33 30 34 66 37 38 65 39 35 38 35
509-
#> [101] 34 36 33 37 63 62 31 66 30 22 0a 20 20 7d 0a 7d 0a
508+
#> [76] 2d 36 32 34 65 30 30 36 64 2d 37 38 30 37 36 62 37 63 31 35 65 64 66 37 65
509+
#> [101] 37 31 64 36 62 32 34 63 35 22 0a 20 20 7d 0a 7d 0a
510510
#>
511511
#> $data
512-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624d6323-5e0b304f78e95854637cb1f0\"\n }\n}\n"
512+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-624e006d-78076b7c15edf7e71d6b24c5\"\n }\n}\n"
513513
```
514514

515515
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -524,7 +524,7 @@ res
524524
#> - $raw for raw message
525525

526526
call_aio(res)$data
527-
#> [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-624d6323-7d89bacc230330e3541fdb6a\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
527+
#> [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-624e006d-06173bcd5b43d5622303afe5\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
528528
```
529529

530530
In this respect, it may be used as a performant and lightweight method

man/is_error_value.Rd

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

man/messenger.Rd

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

man/nng_error.Rd

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

0 commit comments

Comments
 (0)