@@ -165,7 +165,6 @@ ctx_recv <- function(context,
165165# ' @param execute a function which takes the received (converted) data as its
166166# ' first argument. Can be an anonymous function of the form \code{function(x) do(x)}.
167167# ' Additional arguments can also be passed in through '...'.
168- # ' @param ... additional arguments passed to the function specified by 'execute'.
169168# ' @param send_mode [default 'serial'] whether data will be sent serialized or
170169# ' as a raw vector. Use 'serial' for sending and receiving within R to ensure
171170# ' perfect reproducibility. Use 'raw' for sending vectors of any type (will be
@@ -179,15 +178,17 @@ ctx_recv <- function(context,
179178# ' be used. Note this applies to each of the receive and send legs, hence the
180179# ' total elapsed time could be up to twice this parameter plus the time to
181180# ' perform 'execute' on the received data.
181+ # ' @param ... additional arguments passed to the function specified by 'execute'.
182182# '
183183# ' @return Invisible NULL.
184184# '
185185# ' @details Async recv will block while awaiting a message to arrive and is
186186# ' usually the desired result. Set a timeout to allow the function to return
187187# ' if no data is forthcoming.
188188# '
189- # ' In case of an error in unserialisation or data conversion, the function
190- # ' will return the received raw vector to allow the data to be recovered.
189+ # ' In the event of an error in unserialisation or data conversion, or in the
190+ # ' evaluation of the function with respect to the data, a NULL byte (or
191+ # ' serialized NULL byte) will be sent in reply to signal an error to the client.
191192# '
192193# ' @examples
193194# ' req <- socket("req", listen = "tcp://127.0.0.1:6546")
@@ -211,11 +212,11 @@ ctx_recv <- function(context,
211212# '
212213ctx_rep <- function (context ,
213214 execute ,
214- ... ,
215215 recv_mode = c(" serial" , " character" , " complex" , " double" ,
216216 " integer" , " logical" , " numeric" , " raw" ),
217217 send_mode = c(" serial" , " raw" ),
218- timeout ) {
218+ timeout ,
219+ ... ) {
219220
220221 recv_mode <- match.arg(recv_mode )
221222 send_mode <- match.arg(send_mode )
@@ -225,14 +226,14 @@ ctx_rep <- function(context,
225226 message(res , " : " , nng_error(res ))
226227 return (invisible (res ))
227228 }
228- on.exit(expr = return ( res ))
229+ on.exit(expr = send_aio( context , writeBin( object = " " , con = raw()), mode = send_mode ))
229230 data <- switch (recv_mode ,
230231 serial = unserialize(connection = res ),
231232 character = (r <- readBin(con = res , what = recv_mode , n = length(res )))[r != " " ],
232233 raw = res ,
233234 readBin(con = res , what = recv_mode , n = length(res )))
234- on.exit(expr = NULL )
235235 msg <- execute(data , ... )
236+ on.exit(expr = NULL )
236237 ctx_send(context , data = msg , mode = send_mode , timeout = timeout , echo = FALSE )
237238
238239}
@@ -260,6 +261,9 @@ ctx_rep <- function(context,
260261# ' In case of an error in unserialisation or data conversion, the function
261262# ' will return the received raw vector to allow the data to be recovered.
262263# '
264+ # ' If an error occured in the server process, a NULL byte will be received
265+ # ' (as \code{$data} if 'recv_mode' = 'serial', as \code{$raw} otherwise).
266+ # '
263267# ' @examples
264268# ' req <- socket("req", listen = "tcp://127.0.0.1:6546")
265269# ' rep <- socket("rep", dial = "tcp://127.0.0.1:6546")
0 commit comments