Skip to content

Commit 0026477

Browse files
committed
move all NNG errors to C level and upgrade to warnings
1 parent a48dd12 commit 0026477

File tree

20 files changed

+259
-299
lines changed

20 files changed

+259
-299
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* 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.
1212
* Revised 'block' argument for `send()` and `recv()` now allows an integer value for setting a timeout.
1313
* `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.
14+
* Returned NNG error codes are now all classed 'errorValue' and messages have been upgraded to warnings across the package.
1415
* Logging is deprecated and in the process of being phased out. Logging can still be set via 'NANONEXT_LOG' prior to package load but `logging()` can no longer be used. Logging will be removed entirely in a future package version.
1516

1617
# nanonext 0.3.0

R/aio.R

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ send_aio.nanoSocket <- function(con, data, mode = c("serial", "raw"), timeout) {
5353
force(data)
5454
data <- encode(data = data, mode = mode)
5555
aio <- .Call(rnng_send_aio, con, data, timeout)
56-
is.integer(aio) && {
57-
logerror(aio)
58-
return(invisible(aio))
59-
}
56+
is.integer(aio) && return(invisible(aio))
57+
6058
env <- new.env(hash = FALSE)
6159
result <- NULL
6260
unresolv <- TRUE
6361
makeActiveBinding(sym = "result", fun = function(x) {
6462
if (unresolv) {
6563
res <- .Call(rnng_aio_result, aio)
6664
missing(res) && return(.Call(rnng_aio_unresolv))
67-
if (res) logerror(res)
6865
result <<- res
6966
aio <<- env[["aio"]] <<- NULL
7067
unresolv <<- FALSE
@@ -86,18 +83,15 @@ send_aio.nanoContext <- function(con, data, mode = c("serial", "raw"), timeout)
8683
force(data)
8784
data <- encode(data = data, mode = mode)
8885
aio <- .Call(rnng_ctx_send_aio, con, data, timeout)
89-
is.integer(aio) && {
90-
logerror(aio)
91-
return(invisible(aio))
92-
}
86+
is.integer(aio) && return(invisible(aio))
87+
9388
env <- new.env(hash = FALSE)
9489
result <- NULL
9590
unresolv <- TRUE
9691
makeActiveBinding(sym = "result", fun = function(x) {
9792
if (unresolv) {
9893
res <- .Call(rnng_aio_result, aio)
9994
missing(res) && return(.Call(rnng_aio_unresolv))
100-
if (res) logerror(res)
10195
result <<- res
10296
aio <<- env[["aio"]] <<- NULL
10397
unresolv <<- FALSE
@@ -118,18 +112,15 @@ send_aio.nanoStream <- function(con, data, mode = "raw", timeout) {
118112
data <- encode(data = data, mode = "raw")
119113
if (missing(timeout)) timeout <- -2L
120114
aio <- .Call(rnng_stream_send_aio, con, data, timeout)
121-
is.integer(aio) && {
122-
logerror(aio)
123-
return(invisible(aio))
124-
}
115+
is.integer(aio) && return(invisible(aio))
116+
125117
env <- new.env(hash = FALSE)
126118
result <- NULL
127119
unresolv <- TRUE
128120
makeActiveBinding(sym = "result", fun = function(x) {
129121
if (unresolv) {
130122
res <- .Call(rnng_aio_result, aio)
131123
missing(res) && return(.Call(rnng_aio_unresolv))
132-
if (res) logerror(res)
133124
result <<- res
134125
aio <<- env[["aio"]] <<- NULL
135126
unresolv <<- FALSE
@@ -219,10 +210,8 @@ recv_aio.nanoSocket <- function(con,
219210
keep.raw <- missing(keep.raw) || isTRUE(keep.raw)
220211
if (missing(timeout)) timeout <- -2L
221212
aio <- .Call(rnng_recv_aio, con, timeout)
222-
is.integer(aio) && {
223-
logerror(aio)
224-
return(invisible(aio))
225-
}
213+
is.integer(aio) && return(invisible(aio))
214+
226215
env <- new.env(hash = FALSE)
227216
data <- raw <- NULL
228217
unresolv <- TRUE
@@ -235,8 +224,7 @@ recv_aio.nanoSocket <- function(con,
235224
data <<- raw <<- res
236225
aio <<- env[["aio"]] <<- NULL
237226
unresolv <<- FALSE
238-
logerror(res)
239-
return(invisible(data))
227+
return(invisible(res))
240228
}
241229
on.exit(expr = {
242230
raw <<- res
@@ -262,8 +250,7 @@ recv_aio.nanoSocket <- function(con,
262250
data <<- raw <<- res
263251
aio <<- env[["aio"]] <<- NULL
264252
unresolv <<- FALSE
265-
logerror(res)
266-
return(invisible(data))
253+
return(invisible(res))
267254
}
268255
on.exit(expr = {
269256
data <<- res
@@ -299,10 +286,8 @@ recv_aio.nanoContext <- function(con,
299286
keep.raw <- missing(keep.raw) || isTRUE(keep.raw)
300287
if (missing(timeout)) timeout <- -2L
301288
aio <- .Call(rnng_ctx_recv_aio, con, timeout)
302-
is.integer(aio) && {
303-
logerror(aio)
304-
return(invisible(aio))
305-
}
289+
is.integer(aio) && return(invisible(aio))
290+
306291
env <- new.env(hash = FALSE)
307292
data <- raw <- NULL
308293
unresolv <- TRUE
@@ -315,8 +300,7 @@ recv_aio.nanoContext <- function(con,
315300
data <<- raw <<- res
316301
aio <<- env[["aio"]] <<- NULL
317302
unresolv <<- FALSE
318-
logerror(res)
319-
return(invisible(data))
303+
return(invisible(res))
320304
}
321305
on.exit(expr = {
322306
raw <<- res
@@ -342,8 +326,7 @@ recv_aio.nanoContext <- function(con,
342326
data <<- raw <<- res
343327
aio <<- env[["aio"]] <<- NULL
344328
unresolv <<- FALSE
345-
logerror(res)
346-
return(invisible(data))
329+
return(invisible(res))
347330
}
348331
on.exit(expr = {
349332
data <<- res
@@ -380,10 +363,8 @@ recv_aio.nanoStream <- function(con,
380363
keep.raw <- missing(keep.raw) || isTRUE(keep.raw)
381364
if (missing(timeout)) timeout <- -2L
382365
aio <- .Call(rnng_stream_recv_aio, con, n, timeout)
383-
is.integer(aio) && {
384-
logerror(aio)
385-
return(invisible(aio))
386-
}
366+
is.integer(aio) && return(invisible(aio))
367+
387368
env <- new.env(hash = FALSE)
388369
data <- raw <- NULL
389370
unresolv <- TRUE
@@ -396,8 +377,7 @@ recv_aio.nanoStream <- function(con,
396377
data <<- raw <<- res
397378
aio <<- env[["aio"]] <<- NULL
398379
unresolv <<- FALSE
399-
logerror(res)
400-
return(invisible(data))
380+
return(invisible(res))
401381
}
402382
on.exit(expr = {
403383
raw <<- res
@@ -423,8 +403,7 @@ recv_aio.nanoStream <- function(con,
423403
data <<- raw <<- res
424404
aio <<- env[["aio"]] <<- NULL
425405
unresolv <<- FALSE
426-
logerror(res)
427-
return(invisible(data))
406+
return(invisible(res))
428407
}
429408
on.exit(expr = {
430409
data <<- res

R/context.R

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@
4444
context <- function(socket) {
4545

4646
if (is.environment(socket)) socket <- .subset2(socket, "socket")
47-
res <- .Call(rnng_ctx_open, socket)
48-
is.integer(res) && {
49-
logerror(res)
50-
return(invisible(res))
51-
}
52-
res
47+
.Call(rnng_ctx_open, socket)
5348

5449
}
5550

@@ -123,20 +118,14 @@ reply <- function(context,
123118
send_mode <- match.arg(send_mode)
124119
if (missing(timeout)) timeout <- -2L
125120
res <- .Call(rnng_ctx_recv, context, timeout)
126-
is.integer(res) && {
127-
logerror(res)
128-
return(invisible(res))
129-
}
121+
is.integer(res) && return(invisible(res))
130122
on.exit(expr = send_aio(context, as.raw(0L), mode = send_mode))
131123
data <- decode(con = res, mode = recv_mode)
132124
data <- execute(data, ...)
133125
data <- encode(data = data, mode = send_mode)
134126
on.exit()
135127
res <- .Call(rnng_ctx_send, context, data, timeout)
136-
is.integer(res) && {
137-
logerror(res)
138-
return(invisible(res))
139-
}
128+
is.integer(res) && return(invisible(res))
140129
invisible(0L)
141130

142131
}
@@ -202,16 +191,11 @@ request <- function(context,
202191
force(data)
203192
data <- encode(data = data, mode = send_mode)
204193
res <- .Call(rnng_ctx_send_aio, context, data, -2L)
205-
is.integer(res) && {
206-
logerror(res)
207-
return(invisible(res))
208-
}
194+
is.integer(res) && return(invisible(res))
209195

210196
aio <- .Call(rnng_ctx_recv_aio, context, timeout)
211-
is.integer(aio) && {
212-
logerror(aio)
213-
return(invisible(aio))
214-
}
197+
is.integer(aio) && return(invisible(aio))
198+
215199
env <- new.env(hash = FALSE)
216200
data <- raw <- NULL
217201
unresolv <- TRUE
@@ -224,8 +208,7 @@ request <- function(context,
224208
data <<- raw <<- res
225209
aio <<- env[["aio"]] <<- NULL
226210
unresolv <<- FALSE
227-
logerror(res)
228-
return(invisible(data))
211+
return(invisible(res))
229212
}
230213
on.exit(expr = {
231214
raw <<- res
@@ -251,8 +234,7 @@ request <- function(context,
251234
data <<- raw <<- res
252235
aio <<- env[["aio"]] <<- NULL
253236
unresolv <<- FALSE
254-
logerror(res)
255-
return(invisible(data))
237+
return(invisible(res))
256238
}
257239
on.exit(expr = {
258240
data <<- res
@@ -301,10 +283,7 @@ send_ctx <- function(context, data, mode = c("serial", "raw"), timeout, echo = T
301283
force(data)
302284
data <- encode(data = data, mode = mode)
303285
res <- .Call(rnng_ctx_send, context, data, timeout)
304-
is.integer(res) && {
305-
logerror(res)
306-
return(invisible(res))
307-
}
286+
is.integer(res) && return(invisible(res))
308287
if (missing(echo) || isTRUE(echo)) res else invisible(0L)
309288

310289
}
@@ -345,10 +324,7 @@ recv_ctx <- function(context,
345324
mode <- match.arg(mode)
346325
if (missing(timeout)) timeout <- -2L
347326
res <- .Call(rnng_ctx_recv, context, timeout)
348-
is.integer(res) && {
349-
logerror(res)
350-
return(invisible(`class<-`(res, "errorValue")))
351-
}
327+
is.integer(res) && return(invisible(res))
352328
on.exit(expr = return(res))
353329
data <- decode(con = res, mode = mode)
354330
on.exit()

R/listdial.R

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,14 @@ dial <- function(socket,
7777

7878
if (missing(autostart) || isTRUE(autostart)) {
7979
res <- .Call(rnng_dial, socket, url)
80-
is.integer(res) && {
81-
logerror(res)
82-
return(invisible(res))
83-
}
80+
is.integer(res) && return(invisible(res))
8481
if (.logging.) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
8582
skey = "url", sval = url)
83+
8684
} else {
8785
res <- .Call(rnng_dialer_create, socket, url)
88-
is.integer(res) && {
89-
logerror(res)
90-
return(invisible(res))
91-
}
86+
is.integer(res) && return(invisible(res))
87+
9288
}
9389

9490
if (is.environment(socket)) {
@@ -191,18 +187,14 @@ listen <- function(socket,
191187

192188
if (missing(autostart) || isTRUE(autostart)) {
193189
res <- .Call(rnng_listen, socket, url)
194-
is.integer(res) && {
195-
logerror(res)
196-
return(invisible(res))
197-
}
190+
is.integer(res) && return(invisible(res))
198191
if (.logging.) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
199192
skey = "url", sval = url)
193+
200194
} else {
201195
res <- .Call(rnng_listener_create, socket, url)
202-
is.integer(res) && {
203-
logerror(res)
204-
return(invisible(res))
205-
}
196+
is.integer(res) && return(invisible(res))
197+
206198
}
207199

208200
if (is.environment(socket)) {

R/messenger.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ messenger <- function(url) {
2727

2828
is.character(url) || stop("the url must be supplied as a character string")
2929
sock <- .Call(rnng_messenger, url)
30-
is.integer(sock) && {
31-
logerror(sock)
32-
return(invisible(sock))
33-
}
30+
is.integer(sock) && return(invisible(sock))
3431
on.exit(expr = {
35-
s <- .Call(rnng_send, sock, writeBin(":d ", raw()), 0L)
32+
s <- suppressWarnings(.Call(rnng_send, sock, writeBin(":d ", raw()), 0L))
3633
.Call(rnng_close, sock)
3734
invisible()
3835
})
36+
3937
cat("\n", file = stdout())
4038
intro <- unlist(strsplit("nanonext messenger", ""))
4139
for (i in seq_along(intro)) {
@@ -44,19 +42,20 @@ messenger <- function(url) {
4442
}
4543
cat(sprintf("\n| url: %s\n", url), file = stdout())
4644
cat("| connecting... ", file = stderr())
47-
s <- .Call(rnng_send, sock, writeBin(":c ", raw()), 1000L)
45+
s <- suppressWarnings(.Call(rnng_send, sock, writeBin(":c ", raw()), 1000L))
4846
if (is.integer(s)) {
4947
cat(sprintf("\r| peer offline: %s\n", format.POSIXct(Sys.time())), file = stderr())
5048
} else {
5149
cat(sprintf("\r| peer online: %s\n", format.POSIXct(Sys.time())), file = stderr())
5250
}
5351
cat("type your message:\n", file = stdout())
52+
5453
repeat {
5554
data <- readline()
5655
if (identical(data, ":q")) break
5756
if (identical(data, "")) next
5857
rdata <- writeBin(object = data, con = raw())
59-
s <- .Call(rnng_send, sock, rdata, 0L)
58+
s <- suppressWarnings(.Call(rnng_send, sock, rdata, 0L))
6059
if (is.integer(s)) {
6160
cat(sprintf("%*s > not sent: peer offline: %s\n", nchar(data), "", format.POSIXct(Sys.time())),
6261
file = stderr())

0 commit comments

Comments
 (0)