|
5 | 5 | #' Send data over a connection (Socket, Context or Stream). |
6 | 6 | #' |
7 | 7 | #' @param con a Socket, Context or Stream. |
8 | | -#' @param data an object (if mode = 'raw', a vector). |
9 | | -#' @param mode whether data will be sent serialized or as a raw vector. Specify |
10 | | -#' 'serial' for sending and receiving objects within R for perfect |
11 | | -#' reproducibility. Specify 'raw' for sending vectors of any type (converted |
12 | | -#' to a raw byte vector for sending) - essential when interfacing with |
13 | | -#' external applications. For Streams, 'raw' is the only choice and any other |
14 | | -#' value is ignored. |
15 | | -#' @param block <Sockets> [default FALSE] logical flag whether to block until |
16 | | -#' successful or return immediately (e.g. if no connection is available). |
17 | | -#' <Contexts and Streams> [default TRUE] optionally an integer maximum time |
18 | | -#' to block in milliseconds, after which the operation will time out. |
19 | | -#' @param echo [default TRUE] logical flag whether to return the raw vector of |
20 | | -#' sent data. Set to FALSE for performance-critical applications. |
| 8 | +#' @param data an object (a vector, if mode = 'raw'). |
| 9 | +#' @param mode either 'serial' for sending serialised R objects, or 'raw' for |
| 10 | +#' sending vectors of any type (converted to a raw byte vector for sending). |
| 11 | +#' For Streams, 'raw' is the only choice and any other value is ignored. Use |
| 12 | +#' 'serial' for perfect reproducibility within R, although 'raw' must be used |
| 13 | +#' when interfacing with external applications that do not understand R |
| 14 | +#' serialisation. |
| 15 | +#' @param block logical TRUE to block until successful or FALSE to return |
| 16 | +#' immediately even if unsuccessful (e.g. if no connection is available), |
| 17 | +#' or else an integer value specifying the maximum time to block in |
| 18 | +#' milliseconds, after which the operation will time out. |
| 19 | +#' @param echo [default TRUE] logical TRUE to return the raw vector of sent data, |
| 20 | +#' or FALSE to return an integer exit code (invisibly). |
21 | 21 | #' |
22 | 22 | #' @return Raw vector of sent data, or (invisibly) an integer exit code (zero on |
23 | 23 | #' success) if 'echo' is set to FALSE. |
24 | 24 | #' |
25 | | -#' @section Contexts: Will block if the send is in progress and has not yet |
26 | | -#' completed - certain protocol / transport combinations may limit the |
27 | | -#' number of messages that can be queued if they have yet to be received. |
28 | | -#' Set a timeout to ensure the function returns under all scenarios. |
| 25 | +#' @section Blocking: |
29 | 26 | #' |
30 | | -#' @section Streams: Sending a byte stream synchronously will block if the send |
31 | | -#' is in progress and has not yet completed. Set a timeout to ensure the |
32 | | -#' function returns under all scenarios. |
| 27 | +#' For Sockets: the default behaviour is non-blocking with \code{block = FALSE}. |
| 28 | +#' This will return immediately with an error if the message could not be |
| 29 | +#' queued for sending. |
| 30 | +#' |
| 31 | +#' For Contexts and Streams: the default behaviour is blocking with \code{block = TRUE}. |
| 32 | +#' This will wait until the send has completed. For Contexts, certain protocol / |
| 33 | +#' transport combinations may limit the number of messages that can be queued |
| 34 | +#' if they have yet to be received. Set a timeout in this case to ensure that |
| 35 | +#' the function returns under all scenarios. As the underlying implementation |
| 36 | +#' differs to that for Sockets, it is recommended to set a positive integer |
| 37 | +#' value for \code{block} rather than FALSE. |
33 | 38 | #' |
34 | 39 | #' @examples |
35 | 40 | #' pub <- socket("pub", dial = "inproc://nanonext") |
|
54 | 59 | #' @rdname send |
55 | 60 | #' @export |
56 | 61 | #' |
57 | | -send <- function(con, data, mode, block, echo) UseMethod("send") |
| 62 | +send <- function(con, |
| 63 | + data, |
| 64 | + mode = c("serial", "raw"), |
| 65 | + block, |
| 66 | + echo = TRUE) UseMethod("send") |
58 | 67 |
|
59 | 68 | #' @rdname send |
60 | 69 | #' @method send nanoSocket |
@@ -156,12 +165,19 @@ send.nanoStream <- function(con, |
156 | 165 | #' specified), the received raw vector will always be returned to allow for |
157 | 166 | #' the data to be recovered. |
158 | 167 | #' |
159 | | -#' @section Contexts: Will block while awaiting the receive operation to complete. |
160 | | -#' Set a timeout to ensure that the function returns under all scenarios. |
| 168 | +#' @section Blocking: |
| 169 | +#' |
| 170 | +#' For Sockets: the default behaviour is non-blocking with \code{block = FALSE}. |
| 171 | +#' This will return immediately with an error if the message could not be |
| 172 | +#' queued for sending. |
161 | 173 | #' |
162 | | -#' @section Streams: Receivng a byte stream synchronously will block while |
163 | | -#' awaiting the receive operation to complete. Set a timeout to ensure that |
164 | | -#' the function returns under all scenarios. |
| 174 | +#' For Contexts and Streams: the default behaviour is blocking with \code{block = TRUE}. |
| 175 | +#' This will wait until the send has completed. For Contexts, certain protocol / |
| 176 | +#' transport combinations may limit the number of messages that can be queued |
| 177 | +#' if they have yet to be received. Set a timeout in this case to ensure that |
| 178 | +#' the function returns under all scenarios. As the underlying implementation |
| 179 | +#' differs to that for Sockets, it is recommended to set a positive integer |
| 180 | +#' value for \code{block} rather than FALSE. |
165 | 181 | #' |
166 | 182 | #' @examples |
167 | 183 | #' s1 <- socket("bus", listen = "inproc://nanonext") |
@@ -202,7 +218,7 @@ send.nanoStream <- function(con, |
202 | 218 | recv <- function(con, |
203 | 219 | mode = c("serial", "character", "complex", "double", |
204 | 220 | "integer", "logical", "numeric", "raw"), |
205 | | - block = FALSE, |
| 221 | + block, |
206 | 222 | keep.raw = TRUE, |
207 | 223 | ..., |
208 | 224 | n) UseMethod("recv") |
|
0 commit comments