Skip to content

Commit 365d45f

Browse files
committed
more efficient errorValue and call_aio
1 parent b681b3f commit 365d45f

File tree

8 files changed

+112
-77
lines changed

8 files changed

+112
-77
lines changed

R/aio.R

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ recv_aio.nanoSocket <- function(con,
218218
aio <- .Call(rnng_recv_aio, con, timeout)
219219
is.integer(aio) && {
220220
logerror(aio)
221-
return(invisible(`class<-`(aio, "errorValue")))
221+
return(invisible(aio))
222222
}
223223
env <- `class<-`(new.env(), "recvAio")
224224
data <- raw <- NULL
@@ -229,7 +229,7 @@ recv_aio.nanoSocket <- function(con,
229229
res <- .Call(rnng_aio_get_msg, aio)
230230
missing(res) && return(.Call(rnng_aio_unresolv))
231231
is.integer(res) && {
232-
data <<- raw <<- `class<-`(res, "errorValue")
232+
data <<- raw <<- res
233233
unresolv <<- FALSE
234234
logerror(res)
235235
return(invisible(data))
@@ -253,7 +253,7 @@ recv_aio.nanoSocket <- function(con,
253253
res <- .Call(rnng_aio_get_msg, aio)
254254
missing(res) && return(.Call(rnng_aio_unresolv))
255255
is.integer(res) && {
256-
data <<- raw <<- `class<-`(res, "errorValue")
256+
data <<- raw <<- res
257257
unresolv <<- FALSE
258258
logerror(res)
259259
return(invisible(data))
@@ -292,7 +292,7 @@ recv_aio.nanoContext <- function(con,
292292
aio <- .Call(rnng_ctx_recv_aio, con, timeout)
293293
is.integer(aio) && {
294294
logerror(aio)
295-
return(invisible(`class<-`(aio, "errorValue")))
295+
return(invisible(aio))
296296
}
297297
env <- `class<-`(new.env(), "recvAio")
298298
data <- raw <- NULL
@@ -303,7 +303,7 @@ recv_aio.nanoContext <- function(con,
303303
res <- .Call(rnng_aio_get_msg, aio)
304304
missing(res) && return(.Call(rnng_aio_unresolv))
305305
is.integer(res) && {
306-
data <<- raw <<- `class<-`(res, "errorValue")
306+
data <<- raw <<- res
307307
unresolv <<- FALSE
308308
logerror(res)
309309
return(invisible(data))
@@ -327,7 +327,7 @@ recv_aio.nanoContext <- function(con,
327327
res <- .Call(rnng_aio_get_msg, aio)
328328
missing(res) && return(.Call(rnng_aio_unresolv))
329329
is.integer(res) && {
330-
data <<- raw <<- `class<-`(res, "errorValue")
330+
data <<- raw <<- res
331331
unresolv <<- FALSE
332332
logerror(res)
333333
return(invisible(data))
@@ -367,7 +367,7 @@ recv_aio.nanoStream <- function(con,
367367
aio <- .Call(rnng_stream_recv_aio, con, n, timeout)
368368
is.integer(aio) && {
369369
logerror(aio)
370-
return(invisible(`class<-`(aio, "errorValue")))
370+
return(invisible(aio))
371371
}
372372
env <- `class<-`(new.env(), "recvAio")
373373
data <- raw <- NULL
@@ -378,7 +378,7 @@ recv_aio.nanoStream <- function(con,
378378
res <- .Call(rnng_aio_stream_in, aio)
379379
missing(res) && return(.Call(rnng_aio_unresolv))
380380
is.integer(res) && {
381-
data <<- raw <<- `class<-`(res, "errorValue")
381+
data <<- raw <<- res
382382
unresolv <<- FALSE
383383
logerror(res)
384384
return(invisible(data))
@@ -402,7 +402,7 @@ recv_aio.nanoStream <- function(con,
402402
res <- .Call(rnng_aio_stream_in, aio)
403403
missing(res) && return(.Call(rnng_aio_unresolv))
404404
is.integer(res) && {
405-
data <<- raw <<- `class<-`(res, "errorValue")
405+
data <<- raw <<- res
406406
unresolv <<- FALSE
407407
logerror(res)
408408
return(invisible(data))
@@ -483,13 +483,7 @@ recv_aio.nanoStream <- function(con,
483483
#'
484484
call_aio <- function(aio) {
485485

486-
.Call(rnng_aio_call, .subset2(aio, "aio")) && return(invisible(aio))
487-
if (inherits(aio, "recvAio")) {
488-
.subset2(aio, "data")
489-
} else if (inherits(aio, "sendAio")) {
490-
.subset2(aio, "result")
491-
}
492-
invisible(aio)
486+
invisible(.Call(rnng_aio_call, aio))
493487

494488
}
495489

@@ -510,7 +504,7 @@ call_aio <- function(aio) {
510504
#'
511505
stop_aio <- function(aio) {
512506

513-
invisible(.Call(rnng_aio_stop, .subset2(aio, "aio")))
507+
invisible(.Call(rnng_aio_stop, aio))
514508

515509
}
516510

R/ncurl.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ncurl <- function(url, async = FALSE, method = NULL, headers = NULL, data = NULL
6868
aio <- .Call(rnng_ncurl_aio, url, method, headers, data)
6969
is.integer(aio) && {
7070
logerror(aio)
71-
return(invisible(`class<-`(aio, "errorValue")))
71+
return(invisible(aio))
7272
}
7373
env <- `class<-`(new.env(), "recvAio")
7474
data <- raw <- NULL
@@ -78,7 +78,7 @@ ncurl <- function(url, async = FALSE, method = NULL, headers = NULL, data = NULL
7878
res <- .Call(rnng_aio_http, aio)
7979
missing(res) && return(.Call(rnng_aio_unresolv))
8080
is.integer(res) && {
81-
data <<- raw <<- `class<-`(res, "errorValue")
81+
data <<- raw <<- res
8282
unresolv <<- FALSE
8383
logerror(res)
8484
return(invisible(data))
@@ -94,7 +94,7 @@ ncurl <- function(url, async = FALSE, method = NULL, headers = NULL, data = NULL
9494
res <- .Call(rnng_aio_http, aio)
9595
missing(res) && return(.Call(rnng_aio_unresolv))
9696
is.integer(res) && {
97-
data <<- raw <<- `class<-`(res, "errorValue")
97+
data <<- raw <<- res
9898
unresolv <<- FALSE
9999
logerror(res)
100100
return(invisible(data))

R/sendrecv.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ recv.nanoSocket <- function(con,
238238
res <- .Call(rnng_recv, con, block)
239239
is.integer(res) && {
240240
logerror(res)
241-
return(invisible(`class<-`(res, "errorValue")))
241+
return(invisible(res))
242242
}
243243
on.exit(expr = return(res))
244244
data <- decode(con = res, mode = mode)
@@ -263,7 +263,7 @@ recv.nanoContext <- function(con,
263263
res <- .Call(rnng_ctx_recv, con, block)
264264
is.integer(res) && {
265265
logerror(res)
266-
return(invisible(`class<-`(res, "errorValue")))
266+
return(invisible(res))
267267
}
268268
on.exit(expr = return(res))
269269
data <- decode(con = res, mode = mode)
@@ -290,7 +290,7 @@ recv.nanoStream <- function(con,
290290
res <- .Call(rnng_stream_recv, con, n, block)
291291
is.integer(res) && {
292292
logerror(res)
293-
return(invisible(`class<-`(res, "errorValue")))
293+
return(invisible(res))
294294
}
295295
on.exit(expr = return(res))
296296
data <- decode(con = res, mode = mode)

0 commit comments

Comments
 (0)