Skip to content

Commit

Permalink
allow opt() to get options for a Pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Nov 25, 2024
1 parent d713c85 commit f82d28e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nanonext
Type: Package
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
Version: 1.3.2.9000
Version: 1.3.2.9001
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
a socket library implementing 'Scalability Protocols', a reliable,
high-performance standard for common communications patterns including
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# nanonext 1.3.2.9000 (development)
# nanonext 1.3.2.9001 (development)

#### New Features

* `opt()` gains the ability to retrieve options from a Pipe.

# nanonext 1.3.2

Expand Down
20 changes: 19 additions & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,26 @@ SEXP rnng_get_opt(SEXP object, SEXP opt) {
typ = 6; break;
}

} else if (ptrtag == nano_PipeSymbol) {

nng_pipe *p = (nng_pipe *) NANO_PTR(object);
for (;;) {
xc = nng_pipe_get_string(*p, op, &optval.str);
if (xc == 0) { typ = 1; break; }
xc = nng_pipe_get_ms(*p, op, &optval.d);
if (xc == 0) { typ = 2; break; }
xc = nng_pipe_get_size(*p, op, &optval.s);
if (xc == 0) { typ = 3; break; }
xc = nng_pipe_get_int(*p, op, &optval.i);
if (xc == 0) { typ = 4; break; }
xc = nng_pipe_get_bool(*p, op, &optval.b);
if (xc == 0) { typ = 5; break; }
xc = nng_pipe_get_uint64(*p, op, &optval.u);
typ = 6; break;
}

} else {
Rf_error("'object' is not a valid Socket, Context, Stream, Listener or Dialer");
Rf_error("'object' is not a valid Socket, Context, Stream, Listener, Dialer or Pipe");
}

if (xc)
Expand Down
3 changes: 3 additions & 0 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ test_class("recvAio", r <- recv_aio(rep, timeout = 500))
test_zero(req$send("", block = 500))
test_print(p <- tryCatch(collect_pipe(r), error = function(e) NULL))
if (!is.null(p)) test_class("nano", p)
if (is_nano(p)) test_type("integer", p$id)
if (is_nano(p)) test_type("integer", opt(p, "recv-fd"))
test_true(.mark())
test_class("sendAio", r <- send_aio(if (is_nano(p)) p else rep, "", timeout = 500))
if (later) test_null(.keep(r, new.env()))
Expand Down Expand Up @@ -323,6 +325,7 @@ test_equal(suppressWarnings(close(ctx)), 7L)
test_zero(close(rep))
if (is_nano(p)) test_equal(reap(p), 12L)
if (is_nano(p)) test_equal(suppressWarnings(close(p)), 12L)
if (is_nano(p)) test_error(opt(p, "recv-fd"), "12")

test_class("nanoObject", pub <- nano("pub", listen = "inproc://ps"))
test_class("nanoObject", sub <- nano("sub", dial = "inproc://ps", autostart = NA))
Expand Down

0 comments on commit f82d28e

Please sign in to comment.