| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/aio.R |
| 3 |
\name{send_aio} |
| 4 |
\alias{send_aio} |
| 5 |
\title{Send Async} |
| 6 |
\usage{ |
| 7 |
send_aio(con, data, mode = c("serial", "raw"), timeout = NULL, pipe = 0L) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{con}{a Socket, Context or Stream.} |
| 11 |
|
| 12 |
\item{data}{an object (a vector, if \code{mode = "raw"}).} |
| 13 |
|
| 14 |
\item{mode}{[default 'serial'] character value or integer equivalent - |
| 15 |
either \code{"serial"} (1L) to send serialised R objects, or \code{"raw"} (2L) to |
| 16 |
send atomic vectors of any type as a raw byte vector. For Streams, \code{"raw"} |
| 17 |
is the only option and this argument is ignored.} |
| 18 |
|
| 19 |
\item{timeout}{[default NULL] integer value in milliseconds or NULL, which |
| 20 |
applies a socket-specific default, usually the same as no timeout.} |
| 21 |
|
| 22 |
\item{pipe}{[default 0L] only applicable to Sockets using the 'poly' |
| 23 |
protocol, an integer pipe ID if directing the send via a specific pipe.} |
| 24 |
} |
| 25 |
\value{ |
| 26 |
A 'sendAio' (object of class 'sendAio') (invisibly). |
| 27 |
} |
| 28 |
\description{ |
| 29 |
Send data asynchronously over a connection (Socket, Context, Stream or Pipe). |
| 30 |
} |
| 31 |
\details{ |
| 32 |
Async send is always non-blocking and returns a 'sendAio' immediately. |
| 33 |
|
| 34 |
For a 'sendAio', the send result is available at \verb{$result}. An 'unresolved' |
| 35 |
logical NA is returned if the async operation is yet to complete. The |
| 36 |
resolved value will be zero on success, or else an integer error code. |
| 37 |
|
| 38 |
To wait for and check the result of the send operation, use \code{\link[=call_aio]{call_aio()}} on |
| 39 |
the returned 'sendAio' object. |
| 40 |
|
| 41 |
Alternatively, to stop the async operation, use \code{\link[=stop_aio]{stop_aio()}}. |
| 42 |
} |
| 43 |
\section{Send Modes}{ |
| 44 |
|
| 45 |
|
| 46 |
The default mode \code{"serial"} sends serialised R objects to ensure perfect |
| 47 |
reproducibility within R. When receiving, the corresponding mode \code{"serial"} |
| 48 |
should be used. Custom serialization and unserialization functions for |
| 49 |
reference objects may be enabled by the function \code{\link[=serial_config]{serial_config()}}. |
| 50 |
|
| 51 |
Mode \code{"raw"} sends atomic vectors of any type as a raw byte vector, and must |
| 52 |
be used when interfacing with external applications or raw system sockets, |
| 53 |
where R serialization is not in use. When receiving, the mode corresponding |
| 54 |
to the vector sent should be used. |
| 55 |
} |
| 56 |
|
| 57 |
\examples{ |
| 58 |
pub <- socket("pub", dial = "inproc://nanonext") |
| 59 |
|
| 60 |
res <- send_aio(pub, data.frame(a = 1, b = 2), timeout = 100) |
| 61 |
res |
| 62 |
res$result |
| 63 |
|
| 64 |
res <- send_aio(pub, "example message", mode = "raw", timeout = 100) |
| 65 |
call_aio(res)$result |
| 66 |
|
| 67 |
close(pub) |
| 68 |
|
| 69 |
} |
| 70 |
\seealso{ |
| 71 |
\code{\link[=send]{send()}} for synchronous send. |
| 72 |
} |