Learn R Programming

nanonext (version 0.2.0)

recv_aio: Receive Async

Description

Receive data asynchronously over a Socket or Context.

Usage

recv_aio(
  socket,
  mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric",
    "raw"),
  timeout,
  keep.raw = TRUE
)

Arguments

socket

a Socket or Context.

mode

[default 'serial'] mode of vector to be received - one of 'serial', 'character', 'complex', 'double', 'integer', 'logical', 'numeric', or 'raw'. The default 'serial' means a serialised R object, for the other modes, the raw vector received will be converted into the respective mode.

timeout

in ms. If unspecified, a socket-specific default timeout will be used.

keep.raw

[default TRUE] logical flag whether to keep the received raw vector (useful for verification e.g. via hashing). If FALSE, will return the converted data only.

Value

A recv Aio (object of class 'recvAio').

Details

Async receive is always non-blocking and returns immediately.

To wait for the AIO to complete and retrieve the received message, use call_aio on the returned 'recvAio' object.

Alternatively, to stop the async operation, use stop_aio.

Examples

Run this code
# NOT RUN {
s1 <- socket("pair", listen = "inproc://nanonext")
s2 <- socket("pair", dial = "inproc://nanonext")

send_aio(s1, data.frame(a = 1, b = 2), timeout = 100)
res <- recv_aio(s2, timeout = 100, keep.raw = FALSE)
res
call_aio(res)
res

send_aio(s1, c(1.1, 2.2, 3.3), mode = "raw", timeout = 100)
res <- recv_aio(s2, mode = "double", timeout = 100)
call_aio(res)
res

send_aio(s1, "example message", mode = "raw", timeout = 100)
res <- recv_aio(s2, mode = "character", timeout = 100)
call_aio(res)
res$raw
res$data

close(s1)
close(s2)

# }

Run the code above in your browser using DataLab