Debian Codegraph @

man/recv_aio.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/aio.R
3 \name{recv_aio}
4 \alias{recv_aio}
5 \title{Receive Async}
6 \usage{
7 recv_aio(
8 con,
9 mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric",
10 "raw", "string"),
11 timeout = NULL,
12 cv = NULL
13 )
14 }
15 \arguments{
16 \item{con}{a Socket, Context or Stream.}
17
18 \item{mode}{[default 'serial'] character value or integer equivalent - one
19 of \code{"serial"} (1L), \code{"character"} (2L), \code{"complex"} (3L), \code{"double"} (4L),
20 \code{"integer"} (5L), \code{"logical"} (6L), \code{"numeric"} (7L), \code{"raw"} (8L), or
21 \code{"string"} (9L). The default \code{"serial"} means a serialised R object; for
22 the other modes, received bytes are converted into the respective mode.
23 \code{"string"} is a faster option for length one character vectors. For
24 Streams, \code{"serial"} will default to \code{"character"}.}
25
26 \item{timeout}{[default NULL] integer value in milliseconds or NULL, which
27 applies a socket-specific default, usually the same as no timeout.}
28
29 \item{cv}{(optional) a 'conditionVariable' to signal when the async receive
30 is complete.}
31 }
32 \value{
33 A 'recvAio' (object of class 'recvAio') (invisibly).
34 }
35 \description{
36 Receive data asynchronously over a connection (Socket, Context or Stream).
37 }
38 \details{
39 Async receive is always non-blocking and returns a 'recvAio' immediately.
40
41 For a 'recvAio', the received message is available at \verb{$data}. An
42 'unresolved' logical NA is returned if the async operation is yet to
43 complete.
44
45 To wait for the async operation to complete and retrieve the received
46 message, use \code{\link[=call_aio]{call_aio()}} on the returned 'recvAio' object.
47
48 Alternatively, to stop the async operation, use \code{\link[=stop_aio]{stop_aio()}}.
49
50 In case of an error, an integer 'errorValue' is returned (to be
51 distiguishable from an integer message value). This can be checked using
52 \code{\link[=is_error_value]{is_error_value()}}.
53
54 If an error occurred in unserialization or conversion of the message data to
55 the specified mode, a raw vector will be returned instead to allow recovery
56 (accompanied by a warning).
57 }
58 \section{Signalling}{
59
60
61 By supplying a 'conditionVariable', when the receive is complete, the
62 'conditionVariable' is signalled by incrementing its value by 1. This
63 happens asynchronously and independently of the R execution thread.
64 }
65
66 \examples{
67 s1 <- socket("pair", listen = "inproc://nanonext")
68 s2 <- socket("pair", dial = "inproc://nanonext")
69
70 res <- send_aio(s1, data.frame(a = 1, b = 2), timeout = 100)
71 msg <- recv_aio(s2, timeout = 100)
72 msg
73 msg$data
74
75 res <- send_aio(s1, c(1.1, 2.2, 3.3), mode = "raw", timeout = 100)
76 msg <- recv_aio(s2, mode = "double", timeout = 100)
77 msg
78 msg$data
79
80 res <- send_aio(s1, "example message", mode = "raw", timeout = 100)
81 msg <- recv_aio(s2, mode = "character", timeout = 100)
82 call_aio(msg)
83 msg$data
84
85 close(s1)
86 close(s2)
87
88 # Signalling a condition variable
89
90 s1 <- socket("pair", listen = "inproc://cv-example")
91 cv <- cv()
92 msg <- recv_aio(s1, timeout = 100, cv = cv)
93 until(cv, 10L)
94 msg$data
95 close(s1)
96
97 # in another process in parallel
98 s2 <- socket("pair", dial = "inproc://cv-example")
99 res <- send_aio(s2, c(1.1, 2.2, 3.3), mode = "raw", timeout = 100)
100 close(s2)
101
102 }
103 \seealso{
104 \code{\link[=recv]{recv()}} for synchronous receive.
105 }