Skip to content

Commit 8e4bbb8

Browse files
committed
add is_nano, is_aio & remove deprecated funcs
1 parent ccb6c4a commit 8e4bbb8

21 files changed

+165
-321
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.4.0
4+
Version: 0.4.0.9000
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols,
77
implementing a cross-platform standard for messaging and communications.

NAMESPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method("$",nano)
4+
S3method("$<-",nano)
45
S3method("$<-",nanoObject)
56
S3method("$<-",recvAio)
67
S3method("$<-",sendAio)
@@ -47,10 +48,11 @@ export(.mirai_scm)
4748
export(call_aio)
4849
export(context)
4950
export(dial)
51+
export(is_aio)
5052
export(is_error_value)
53+
export(is_nano)
5154
export(is_nul_byte)
5255
export(listen)
53-
export(logging)
5456
export(messenger)
5557
export(nano)
5658
export(nano_init)
@@ -59,12 +61,10 @@ export(nng_error)
5961
export(nng_version)
6062
export(recv)
6163
export(recv_aio)
62-
export(recv_ctx)
6364
export(reply)
6465
export(request)
6566
export(send)
6667
export(send_aio)
67-
export(send_ctx)
6868
export(setopt)
6969
export(socket)
7070
export(stop_aio)

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# nanonext 0.4.0.9000 (under development)
2+
3+
#### New Features
4+
5+
* Added convenience auxiliary functions `is_nano()` and `is_aio()`.
6+
7+
#### Updates
8+
9+
* Deprecated `send_ctx()`, `recv_ctx()` and logging are removed.
10+
* Internal performance optimisations.
11+
112
# nanonext 0.4.0
213

314
#### New Features

R/context.R

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
#'
2222
#' Note: not every protocol supports creation of separate contexts.
2323
#'
24-
#' To send and receive over a context use \code{\link{send_ctx}} and
25-
#' \code{\link{recv_ctx}} respectively. It is also possible to perform async
26-
#' send and receive over a context using \code{\link{send_aio}} and
24+
#' To send and receive over a context use \code{\link{send}} and
25+
#' \code{\link{recv}} or their async counterparts \code{\link{send_aio}} and
2726
#' \code{\link{recv_aio}}.
2827
#'
2928
#' @examples
@@ -125,9 +124,7 @@ reply <- function(context,
125124
data <- execute(data, ...)
126125
data <- encode(data = data, mode = send_mode)
127126
on.exit()
128-
res <- .Call(rnng_ctx_send, context, data, timeout)
129-
is.integer(res) && return(invisible(res))
130-
invisible(0L)
127+
invisible(.Call(rnng_ctx_send, context, data, timeout))
131128

132129
}
133130

@@ -257,80 +254,3 @@ request <- function(context,
257254

258255
}
259256

260-
# Deprecated - do not use ------------------------------------------------------
261-
262-
#' Send over Context
263-
#'
264-
#' Send data over a Context [Deprecated].
265-
#'
266-
#' @param context a Context.
267-
#' @inheritParams send
268-
#' @inheritParams send_aio
269-
#'
270-
#' @return Raw vector of sent data, or (invisibly) an integer exit code (zero on
271-
#' success) if 'echo' is set to FALSE.
272-
#'
273-
#' @details Will block if the send is in progress and has not yet completed -
274-
#' certain protocol / transport combinations may limit the number of messages
275-
#' that can be queued if they have yet to be received. Set a timeout to
276-
#' ensure the function returns under all scenarios.
277-
#'
278-
#' @keywords internal
279-
#' @export
280-
#'
281-
send_ctx <- function(context, data, mode = c("serial", "raw"), timeout = -2L, echo = TRUE) {
282-
283-
mode <- match.arg2(mode, c("serial", "raw"))
284-
force(data)
285-
data <- encode(data = data, mode = mode)
286-
res <- .Call(rnng_ctx_send, context, data, timeout)
287-
is.integer(res) && return(invisible(res))
288-
if (missing(echo) || isTRUE(echo)) res else invisible(0L)
289-
290-
}
291-
292-
#' Receive over Context
293-
#'
294-
#' Receive data over a Context [Deprecated].
295-
#'
296-
#' @param context a Context.
297-
#' @inheritParams recv
298-
#' @inheritParams send_aio
299-
#'
300-
#' @return Named list of 2 elements: 'raw' containing the received raw vector
301-
#' and 'data' containing the converted object, or else the converted object
302-
#' if 'keep.raw' is set to FALSE.
303-
#'
304-
#' @details Will block while awaiting the receive operation to complete.
305-
#' Set a timeout to ensure that the function returns under all scenarios.
306-
#'
307-
#' In case of an error, an integer 'errorValue' is returned (to be
308-
#' distiguishable from an integer message value). This can be verified using
309-
#' \code{\link{is_error_value}}.
310-
#'
311-
#' If the raw data was successfully received but an error occurred in
312-
#' unserialisation or data conversion (for example if the incorrect mode was
313-
#' specified), the received raw vector will always be returned to allow for
314-
#' the data to be recovered.
315-
#'
316-
#' @keywords internal
317-
#' @export
318-
#'
319-
recv_ctx <- function(context,
320-
mode = c("serial", "character", "complex", "double",
321-
"integer", "logical", "numeric", "raw"),
322-
timeout = -2L,
323-
keep.raw = TRUE) {
324-
325-
mode <- match.arg2(mode, c("serial", "character", "complex", "double",
326-
"integer", "logical", "numeric", "raw"))
327-
res <- .Call(rnng_ctx_recv, context, timeout)
328-
is.integer(res) && return(invisible(res))
329-
on.exit(expr = return(res))
330-
data <- decode(con = res, mode = mode)
331-
on.exit()
332-
missing(data) && return(.Call(rnng_scm))
333-
if (missing(keep.raw) || isTRUE(keep.raw)) list(raw = res, data = data) else data
334-
335-
}
336-

R/listdial.R

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,14 @@ dial <- function(socket,
7373
url = "inproc://nanonext",
7474
autostart = TRUE) {
7575

76-
if (missing(autostart) || isTRUE(autostart)) {
77-
res <- .Call(rnng_dial, socket, url)
78-
is.integer(res) && return(invisible(res))
79-
if (.logging.) loginfo(evt = "dial start", pkey = "sock", pval = attr(res, "socket"),
80-
skey = "url", sval = url)
81-
76+
res <- if (missing(autostart) || isTRUE(autostart)) {
77+
.Call(rnng_dial, socket, url)
8278
} else {
83-
res <- .Call(rnng_dialer_create, socket, url)
84-
is.integer(res) && return(invisible(res))
85-
79+
.Call(rnng_dialer_create, socket, url)
8680
}
8781

82+
is.integer(res) && return(invisible(res))
83+
8884
if (is.environment(socket)) {
8985

9086
socket[["dialer"]] <- c(.subset2(socket, "dialer"), res)
@@ -181,18 +177,14 @@ listen <- function(socket,
181177
url = "inproc://nanonext",
182178
autostart = TRUE) {
183179

184-
if (missing(autostart) || isTRUE(autostart)) {
185-
res <- .Call(rnng_listen, socket, url)
186-
is.integer(res) && return(invisible(res))
187-
if (.logging.) loginfo(evt = "list start", pkey = "sock", pval = attr(res, "socket"),
188-
skey = "url", sval = url)
189-
180+
res <- if (missing(autostart) || isTRUE(autostart)) {
181+
.Call(rnng_listen, socket, url)
190182
} else {
191-
res <- .Call(rnng_listener_create, socket, url)
192-
is.integer(res) && return(invisible(res))
193-
183+
.Call(rnng_listener_create, socket, url)
194184
}
195185

186+
is.integer(res) && return(invisible(res))
187+
196188
if (is.environment(socket)) {
197189

198190
socket[["listener"]] <- c(.subset2(socket, "listener"), res)

R/methods.R

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ NULL
2626
#'
2727
start.nanoListener <- function(x, ...) {
2828

29-
if (.logging.) {
30-
loginfo(evt = "list start", pkey = "sock", pval = attr(x, "socket"),
31-
skey = "url", sval = attr(x, "url"))
32-
}
3329
invisible(.Call(rnng_listener_start, x))
3430

3531
}
@@ -40,10 +36,6 @@ start.nanoListener <- function(x, ...) {
4036
#'
4137
start.nanoDialer <- function(x, async = TRUE, ...) {
4238

43-
if (.logging.) {
44-
loginfo(evt = "dial start", pkey = "sock", pval = attr(x, "socket"),
45-
skey = "url", sval = attr(x, "url"))
46-
}
4739
invisible(.Call(rnng_dialer_start, x, async))
4840

4941
}
@@ -83,10 +75,6 @@ NULL
8375
#'
8476
close.nanoSocket <- function(con, ...) {
8577

86-
if (.logging.) {
87-
loginfo(evt = "sock close", pkey = "id", pval = attr(con, "id"),
88-
skey = "protocol", sval = attr(con, "protocol"))
89-
}
9078
invisible(.Call(rnng_close, con))
9179

9280
}
@@ -107,10 +95,6 @@ close.nanoContext <- function(con, ...) {
10795
#'
10896
close.nanoDialer <- function(con, ...) {
10997

110-
if (.logging.) {
111-
loginfo(evt = "dial close", pkey = "sock", pval = attr(con, "socket"),
112-
skey = "url", sval = attr(con, "url"))
113-
}
11498
invisible(.Call(rnng_dialer_close, con))
11599

116100
}
@@ -121,10 +105,6 @@ close.nanoDialer <- function(con, ...) {
121105
#'
122106
close.nanoListener <- function(con, ...) {
123107

124-
if (.logging.) {
125-
loginfo(evt = "list close", pkey = "sock", pval = attr(con, "socket"),
126-
skey = "url", sval = attr(con, "url"))
127-
}
128108
invisible(.Call(rnng_listener_close, con))
129109

130110
}
@@ -135,10 +115,6 @@ close.nanoListener <- function(con, ...) {
135115
#'
136116
close.nanoStream <- function(con, ...) {
137117

138-
pkey <- if (is.null(attr(con, "dialer"))) "list" else "dial"
139-
sval <- attr(con, "url")
140-
if (.logging.) loginfo(evt = "stream close", pkey = pkey, pval = 1,
141-
skey = "url", sval = sval)
142118
invisible(.Call(rnng_stream_close, con))
143119

144120
}

R/nano.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ print.sendAio <- function(x, ...) {
267267

268268
}
269269

270+
#' @export
271+
#'
272+
`$<-.nano` <- function(x, name, value) {
273+
x
274+
}
275+
270276
#' @export
271277
#'
272278
`$<-.nanoObject` <- function(x, name, value) {

R/nanonext-package.R

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@
126126
#'
127127
NULL
128128

129-
.onLoad <- function(libname, pkgname) {
130-
.logging. <- switch(tolower(Sys.getenv("NANONEXT_LOG")),
131-
info = TRUE,
132-
FALSE)
133-
.logging. <<- .logging.
134-
invisible()
135-
}
136-
137129
.onUnload <- function(libpath) {
138130
if (!is.null(warn <- getOption("nanonext.original.warn"))) {
139131
options(warn = warn)
@@ -142,4 +134,3 @@ NULL
142134
invisible()
143135
}
144136

145-
.logging. <- FALSE

R/protocol.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
#'
3939
subscribe <- function(socket, topic = NULL) {
4040

41-
if (.logging.) {
42-
loginfo(evt = "subscribe", pkey = "sock", pval = attr(socket, "id"),
43-
skey = "topic", sval = if (is.null(topic)) "ALL" else topic)
44-
}
4541
invisible(.Call(rnng_socket_set, socket, 5L, "sub:subscribe", topic))
4642

4743
}
@@ -88,10 +84,6 @@ subscribe <- function(socket, topic = NULL) {
8884
#'
8985
unsubscribe <- function(socket, topic = NULL) {
9086

91-
if (.logging.) {
92-
loginfo(evt = "unsubscribe", pkey = "sock", pval = attr(socket, "id"),
93-
skey = "topic", sval = if (is.null(topic)) "ALL" else topic)
94-
}
9587
invisible(.Call(rnng_socket_set, socket, 5L, "sub:unsubscribe", topic))
9688

9789
}
@@ -140,10 +132,6 @@ unsubscribe <- function(socket, topic = NULL) {
140132
#'
141133
survey_time <- function(socket, time) {
142134

143-
if (.logging.) {
144-
loginfo(evt = "survey", pkey = "sock", pval = attr(socket, "id"),
145-
skey = "set time", sval = as.character(time))
146-
}
147135
invisible(.Call(rnng_socket_set, socket, 3L, "surveyor:survey-time", time))
148136

149137
}

R/sendrecv.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ send.nanoSocket <- function(con,
7878
force(data)
7979
data <- encode(data = data, mode = mode)
8080
res <- .Call(rnng_send, con, data, block)
81-
is.integer(res) && return(invisible(res))
82-
if (missing(echo) || isTRUE(echo)) res else invisible(0L)
81+
res && return(invisible(res))
82+
if (missing(echo) || isTRUE(echo)) data else invisible(res)
8383

8484
}
8585

@@ -98,8 +98,8 @@ send.nanoContext <- function(con,
9898
data <- encode(data = data, mode = mode)
9999
if (missing(block) || isTRUE(block)) block <- -2L
100100
res <- .Call(rnng_ctx_send, con, data, block)
101-
is.integer(res) && return(invisible(res))
102-
if (missing(echo) || isTRUE(echo)) res else invisible(0L)
101+
res && return(invisible(res))
102+
if (missing(echo) || isTRUE(echo)) data else invisible(res)
103103

104104
}
105105

@@ -117,8 +117,8 @@ send.nanoStream <- function(con,
117117
data <- encode(data = data, mode = 2L)
118118
if (missing(block) || isTRUE(block)) block <- -2L
119119
res <- .Call(rnng_stream_send, con, data, block)
120-
is.integer(res) && return(invisible(res))
121-
if (missing(echo) || isTRUE(echo)) res else invisible(0L)
120+
res && return(invisible(res))
121+
if (missing(echo) || isTRUE(echo)) data else invisible(res)
122122

123123
}
124124

0 commit comments

Comments
 (0)