|
1 | | -# nanonext - Contexts ---------------------------------------------------------- |
| 1 | +# nanonext - Contexts and RPC -------------------------------------------------- |
2 | 2 |
|
3 | 3 | #' Open Context |
4 | 4 | #' |
@@ -53,88 +53,6 @@ context <- function(socket) { |
53 | 53 |
|
54 | 54 | } |
55 | 55 |
|
56 | | -#' Send over Context |
57 | | -#' |
58 | | -#' Send data over a Context [Deprecated]. |
59 | | -#' |
60 | | -#' @param context a Context. |
61 | | -#' @inheritParams send |
62 | | -#' @inheritParams send_aio |
63 | | -#' |
64 | | -#' @return Raw vector of sent data, or (invisibly) an integer exit code (zero on |
65 | | -#' success) if 'echo' is set to FALSE. |
66 | | -#' |
67 | | -#' @details Will block if the send is in progress and has not yet completed - |
68 | | -#' certain protocol / transport combinations may limit the number of messages |
69 | | -#' that can be queued if they have yet to be received. Set a timeout to |
70 | | -#' ensure the function returns under all scenarios. |
71 | | -#' |
72 | | -#' @keywords internal |
73 | | -#' @export |
74 | | -#' |
75 | | -send_ctx <- function(context, data, mode = c("serial", "raw"), timeout, echo = TRUE) { |
76 | | - |
77 | | - mode <- match.arg(mode) |
78 | | - if (missing(timeout)) timeout <- -2L |
79 | | - force(data) |
80 | | - data <- encode(data = data, mode = mode) |
81 | | - res <- .Call(rnng_ctx_send, context, data, timeout) |
82 | | - is.integer(res) && { |
83 | | - logerror(res) |
84 | | - return(invisible(res)) |
85 | | - } |
86 | | - if (missing(echo) || isTRUE(echo)) res else invisible(0L) |
87 | | - |
88 | | -} |
89 | | - |
90 | | -#' Receive over Context |
91 | | -#' |
92 | | -#' Receive data over a Context [Deprecated]. |
93 | | -#' |
94 | | -#' @param context a Context. |
95 | | -#' @inheritParams recv |
96 | | -#' @inheritParams send_aio |
97 | | -#' |
98 | | -#' @return Named list of 2 elements: 'raw' containing the received raw vector |
99 | | -#' and 'data' containing the converted object, or else the converted object |
100 | | -#' if 'keep.raw' is set to FALSE. |
101 | | -#' |
102 | | -#' @details Will block while awaiting the receive operation to complete. |
103 | | -#' Set a timeout to ensure that the function returns under all scenarios. |
104 | | -#' |
105 | | -#' In case of an error, an integer 'errorValue' is returned (to be |
106 | | -#' distiguishable from an integer message value). This can be verified using |
107 | | -#' \code{\link{is_error_value}}. |
108 | | -#' |
109 | | -#' If the raw data was successfully received but an error occurred in |
110 | | -#' unserialisation or data conversion (for example if the incorrect mode was |
111 | | -#' specified), the received raw vector will always be returned to allow for |
112 | | -#' the data to be recovered. |
113 | | -#' |
114 | | -#' @keywords internal |
115 | | -#' @export |
116 | | -#' |
117 | | -recv_ctx <- function(context, |
118 | | - mode = c("serial", "character", "complex", "double", |
119 | | - "integer", "logical", "numeric", "raw"), |
120 | | - timeout, |
121 | | - keep.raw = TRUE) { |
122 | | - |
123 | | - mode <- match.arg(mode) |
124 | | - if (missing(timeout)) timeout <- -2L |
125 | | - res <- .Call(rnng_ctx_recv, context, timeout) |
126 | | - is.integer(res) && { |
127 | | - logerror(res) |
128 | | - return(invisible(`class<-`(res, "errorValue"))) |
129 | | - } |
130 | | - on.exit(expr = return(res)) |
131 | | - data <- decode(con = res, mode = mode) |
132 | | - on.exit() |
133 | | - missing(data) && return(.Call(rnng_scm)) |
134 | | - if (missing(keep.raw) || isTRUE(keep.raw)) list(raw = res, data = data) else data |
135 | | - |
136 | | -} |
137 | | - |
138 | 56 | #' Reply over Context (RPC Server for Req/Rep Protocol) |
139 | 57 | #' |
140 | 58 | #' Implements an executor/server for the rep node of the req/rep protocol. Awaits |
@@ -349,3 +267,87 @@ request <- function(context, |
349 | 267 |
|
350 | 268 | } |
351 | 269 |
|
| 270 | +# Deprecated - do not use ------------------------------------------------------ |
| 271 | + |
| 272 | +#' Send over Context |
| 273 | +#' |
| 274 | +#' Send data over a Context [Deprecated]. |
| 275 | +#' |
| 276 | +#' @param context a Context. |
| 277 | +#' @inheritParams send |
| 278 | +#' @inheritParams send_aio |
| 279 | +#' |
| 280 | +#' @return Raw vector of sent data, or (invisibly) an integer exit code (zero on |
| 281 | +#' success) if 'echo' is set to FALSE. |
| 282 | +#' |
| 283 | +#' @details Will block if the send is in progress and has not yet completed - |
| 284 | +#' certain protocol / transport combinations may limit the number of messages |
| 285 | +#' that can be queued if they have yet to be received. Set a timeout to |
| 286 | +#' ensure the function returns under all scenarios. |
| 287 | +#' |
| 288 | +#' @keywords internal |
| 289 | +#' @export |
| 290 | +#' |
| 291 | +send_ctx <- function(context, data, mode = c("serial", "raw"), timeout, echo = TRUE) { |
| 292 | + |
| 293 | + mode <- match.arg(mode) |
| 294 | + if (missing(timeout)) timeout <- -2L |
| 295 | + force(data) |
| 296 | + data <- encode(data = data, mode = mode) |
| 297 | + res <- .Call(rnng_ctx_send, context, data, timeout) |
| 298 | + is.integer(res) && { |
| 299 | + logerror(res) |
| 300 | + return(invisible(res)) |
| 301 | + } |
| 302 | + if (missing(echo) || isTRUE(echo)) res else invisible(0L) |
| 303 | + |
| 304 | +} |
| 305 | + |
| 306 | +#' Receive over Context |
| 307 | +#' |
| 308 | +#' Receive data over a Context [Deprecated]. |
| 309 | +#' |
| 310 | +#' @param context a Context. |
| 311 | +#' @inheritParams recv |
| 312 | +#' @inheritParams send_aio |
| 313 | +#' |
| 314 | +#' @return Named list of 2 elements: 'raw' containing the received raw vector |
| 315 | +#' and 'data' containing the converted object, or else the converted object |
| 316 | +#' if 'keep.raw' is set to FALSE. |
| 317 | +#' |
| 318 | +#' @details Will block while awaiting the receive operation to complete. |
| 319 | +#' Set a timeout to ensure that the function returns under all scenarios. |
| 320 | +#' |
| 321 | +#' In case of an error, an integer 'errorValue' is returned (to be |
| 322 | +#' distiguishable from an integer message value). This can be verified using |
| 323 | +#' \code{\link{is_error_value}}. |
| 324 | +#' |
| 325 | +#' If the raw data was successfully received but an error occurred in |
| 326 | +#' unserialisation or data conversion (for example if the incorrect mode was |
| 327 | +#' specified), the received raw vector will always be returned to allow for |
| 328 | +#' the data to be recovered. |
| 329 | +#' |
| 330 | +#' @keywords internal |
| 331 | +#' @export |
| 332 | +#' |
| 333 | +recv_ctx <- function(context, |
| 334 | + mode = c("serial", "character", "complex", "double", |
| 335 | + "integer", "logical", "numeric", "raw"), |
| 336 | + timeout, |
| 337 | + keep.raw = TRUE) { |
| 338 | + |
| 339 | + mode <- match.arg(mode) |
| 340 | + if (missing(timeout)) timeout <- -2L |
| 341 | + res <- .Call(rnng_ctx_recv, context, timeout) |
| 342 | + is.integer(res) && { |
| 343 | + logerror(res) |
| 344 | + return(invisible(`class<-`(res, "errorValue"))) |
| 345 | + } |
| 346 | + on.exit(expr = return(res)) |
| 347 | + data <- decode(con = res, mode = mode) |
| 348 | + on.exit() |
| 349 | + missing(data) && return(.Call(rnng_scm)) |
| 350 | + if (missing(keep.raw) || isTRUE(keep.raw)) list(raw = res, data = data) else data |
| 351 | + |
| 352 | +} |
| 353 | + |
0 commit comments