diff --git a/R/daemon.R b/R/daemon.R index 46ebd40a..af163b20 100644 --- a/R/daemon.R +++ b/R/daemon.R @@ -87,17 +87,17 @@ #' #' @export #' -daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = TRUE, +daemon <- function(url, dispatcher = FALSE, ..., asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE, output = FALSE, tls = NULL, rs = NULL) { - dispatcher || return( + missing(dispatcher) && return( daemon_legacy( url = url, asyncdial = asyncdial, autoexit = autoexit, cleanup = cleanup, output = output, ..., tls = tls, rs = rs ) ) cv <- cv() - sock <- socket(protocol = "poly") + sock <- socket(protocol = if (dispatcher) "poly" else "rep") on.exit(reap(sock)) `[[<-`(., "sock", sock) autoexit && pipe_notify(sock, cv = cv, remove = TRUE, flag = as.integer(autoexit)) @@ -117,17 +117,27 @@ daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = T } snapshot() - repeat { - aio <- recv_aio(sock, mode = 1L, cv = cv) - wait(cv) || break - m <- collect_aio(aio) - is.object(m) && next - cancel <- recv_aio(sock, mode = 8L, cv = NA) - data <- eval_mirai(m) - stop_aio(cancel) - send(sock, data, mode = 1L, block = TRUE) - if (cleanup) do_cleanup() - } + if (dispatcher) + repeat { + aio <- recv_aio(sock, mode = 1L, cv = cv) + wait(cv) || break + m <- collect_aio(aio) + is.object(m) && next + cancel <- recv_aio(sock, mode = 8L, cv = NA) + data <- eval_mirai(m) + stop_aio(cancel) + send(sock, data, mode = 1L, block = TRUE) + if (cleanup) do_cleanup() + } else + repeat { + ctx <- .context(sock) + aio <- recv_aio(ctx, mode = 1L, cv = cv) + wait(cv) || break + m <- collect_aio(aio) + data <- eval_mirai(m) + send(ctx, data, mode = 1L, block = TRUE) + if (cleanup) do_cleanup() + } } diff --git a/man/daemon.Rd b/man/daemon.Rd index 6dbafc72..9ec78008 100644 --- a/man/daemon.Rd +++ b/man/daemon.Rd @@ -6,8 +6,8 @@ \usage{ daemon( url, - ..., dispatcher = FALSE, + ..., asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE, @@ -21,11 +21,11 @@ daemon( port to connect to (and optionally for websockets, a path), e.g. 'tcp://hostname:5555' or 'ws://10.75.32.70:5555/path'.} -\item{...}{reserved but not currently used.} - \item{dispatcher}{[default FALSE] logical value, which should be set to TRUE if using dispatcher and FALSE otherwise.} +\item{...}{reserved but not currently used.} + \item{asyncdial}{[default FALSE] whether to perform dials asynchronously. The default FALSE will error if a connection is not immediately possible (for instance if \code{\link{daemons}} has yet to be called on the host, or the diff --git a/tests/tests.R b/tests/tests.R index 3b0c081d..c63acef1 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -281,8 +281,8 @@ connection && Sys.getenv("NOT_CRAN") == "true" && { m <- mirai_map(1:10, function(x) { Sys.sleep(2); y <<- TRUE }) s <- stop_mirai(m) test_equal(sum(unlist(m[])), 200L) - if (.Platform[["OS.type"]] != "windows") test_identical(s, !logical(10L)) - if (.Platform[["OS.type"]] != "windows") test_class("errorValue", mirai(y)[]) + if (Sys.info()[["sysname"]] == "Linux") test_identical(s, !logical(10L)) + if (Sys.info()[["sysname"]] == "Linux") test_class("errorValue", mirai(y)[]) test_equal(status()$connections, 1L) test_equal(length(nextget("urls")), 1L) test_class("miraiLaunchCmd", launch_remote(1))