|
21 | 21 | #' |
22 | 22 | #' Note: not every protocol supports creation of separate contexts. |
23 | 23 | #' |
24 | | -#' To send and receive over a context use \code{\link{send_ctx}} and |
25 | | -#' \code{\link{recv_ctx}} respectively. It is also possible to perform async |
26 | | -#' send and receive over a context using \code{\link{send_aio}} and |
| 24 | +#' To send and receive over a context use \code{\link{send}} and |
| 25 | +#' \code{\link{recv}} or their async counterparts \code{\link{send_aio}} and |
27 | 26 | #' \code{\link{recv_aio}}. |
28 | 27 | #' |
29 | 28 | #' @examples |
@@ -125,9 +124,7 @@ reply <- function(context, |
125 | 124 | data <- execute(data, ...) |
126 | 125 | data <- encode(data = data, mode = send_mode) |
127 | 126 | on.exit() |
128 | | - res <- .Call(rnng_ctx_send, context, data, timeout) |
129 | | - is.integer(res) && return(invisible(res)) |
130 | | - invisible(0L) |
| 127 | + invisible(.Call(rnng_ctx_send, context, data, timeout)) |
131 | 128 |
|
132 | 129 | } |
133 | 130 |
|
@@ -257,80 +254,3 @@ request <- function(context, |
257 | 254 |
|
258 | 255 | } |
259 | 256 |
|
260 | | -# Deprecated - do not use ------------------------------------------------------ |
261 | | - |
262 | | -#' Send over Context |
263 | | -#' |
264 | | -#' Send data over a Context [Deprecated]. |
265 | | -#' |
266 | | -#' @param context a Context. |
267 | | -#' @inheritParams send |
268 | | -#' @inheritParams send_aio |
269 | | -#' |
270 | | -#' @return Raw vector of sent data, or (invisibly) an integer exit code (zero on |
271 | | -#' success) if 'echo' is set to FALSE. |
272 | | -#' |
273 | | -#' @details Will block if the send is in progress and has not yet completed - |
274 | | -#' certain protocol / transport combinations may limit the number of messages |
275 | | -#' that can be queued if they have yet to be received. Set a timeout to |
276 | | -#' ensure the function returns under all scenarios. |
277 | | -#' |
278 | | -#' @keywords internal |
279 | | -#' @export |
280 | | -#' |
281 | | -send_ctx <- function(context, data, mode = c("serial", "raw"), timeout = -2L, echo = TRUE) { |
282 | | - |
283 | | - mode <- match.arg2(mode, c("serial", "raw")) |
284 | | - force(data) |
285 | | - data <- encode(data = data, mode = mode) |
286 | | - res <- .Call(rnng_ctx_send, context, data, timeout) |
287 | | - is.integer(res) && return(invisible(res)) |
288 | | - if (missing(echo) || isTRUE(echo)) res else invisible(0L) |
289 | | - |
290 | | -} |
291 | | - |
292 | | -#' Receive over Context |
293 | | -#' |
294 | | -#' Receive data over a Context [Deprecated]. |
295 | | -#' |
296 | | -#' @param context a Context. |
297 | | -#' @inheritParams recv |
298 | | -#' @inheritParams send_aio |
299 | | -#' |
300 | | -#' @return Named list of 2 elements: 'raw' containing the received raw vector |
301 | | -#' and 'data' containing the converted object, or else the converted object |
302 | | -#' if 'keep.raw' is set to FALSE. |
303 | | -#' |
304 | | -#' @details Will block while awaiting the receive operation to complete. |
305 | | -#' Set a timeout to ensure that the function returns under all scenarios. |
306 | | -#' |
307 | | -#' In case of an error, an integer 'errorValue' is returned (to be |
308 | | -#' distiguishable from an integer message value). This can be verified using |
309 | | -#' \code{\link{is_error_value}}. |
310 | | -#' |
311 | | -#' If the raw data was successfully received but an error occurred in |
312 | | -#' unserialisation or data conversion (for example if the incorrect mode was |
313 | | -#' specified), the received raw vector will always be returned to allow for |
314 | | -#' the data to be recovered. |
315 | | -#' |
316 | | -#' @keywords internal |
317 | | -#' @export |
318 | | -#' |
319 | | -recv_ctx <- function(context, |
320 | | - mode = c("serial", "character", "complex", "double", |
321 | | - "integer", "logical", "numeric", "raw"), |
322 | | - timeout = -2L, |
323 | | - keep.raw = TRUE) { |
324 | | - |
325 | | - mode <- match.arg2(mode, c("serial", "character", "complex", "double", |
326 | | - "integer", "logical", "numeric", "raw")) |
327 | | - res <- .Call(rnng_ctx_recv, context, timeout) |
328 | | - is.integer(res) && return(invisible(res)) |
329 | | - on.exit(expr = return(res)) |
330 | | - data <- decode(con = res, mode = mode) |
331 | | - on.exit() |
332 | | - missing(data) && return(.Call(rnng_scm)) |
333 | | - if (missing(keep.raw) || isTRUE(keep.raw)) list(raw = res, data = data) else data |
334 | | - |
335 | | -} |
336 | | - |
0 commit comments