Skip to content

Commit

Permalink
Implement ability to close individual pipes (#73)
Browse files Browse the repository at this point in the history
* pipe close concept

* misc

* add tests
  • Loading branch information
shikokuchuo authored Jan 8, 2025
1 parent a15e9e3 commit 3523c36
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 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.4.0.9000
Version: 1.4.0.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
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# nanonext 1.4.0.9000 (development)
# nanonext 1.4.0.9001 (development)

#### Updates

* Removes partial matching from using `$`, `[[` or `[` on an object inheriting from class 'nano'.
* `reap()` now accepts an integer pipe ID to close the associated pipe.
* Removes partial matching when using `$`, `[[` or `[` on an object inheriting from class 'nano'.

# nanonext 1.4.0

Expand Down
4 changes: 2 additions & 2 deletions R/messenger.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022-2024 Hibiki AI Limited <info@hibiki-ai.com>
# Copyright (C) 2022-2025 Hibiki AI Limited <info@hibiki-ai.com>
#
# This file is part of nanonext.
#
Expand Down Expand Up @@ -60,7 +60,7 @@ messenger <- function(url, auth = NULL) {
sock <- .Call(rnng_messenger, url)
on.exit(expr = {
send(sock, data = writeBin(":d ", raw()), mode = 2L, block = FALSE)
.Call(rnng_close, sock)
close(sock)
})
cat("\n", file = stdout())
intro <- unlist(strsplit("nanonext messenger", ""))
Expand Down
4 changes: 2 additions & 2 deletions R/socket.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022-2024 Hibiki AI Limited <info@hibiki-ai.com>
# Copyright (C) 2022-2025 Hibiki AI Limited <info@hibiki-ai.com>
#
# This file is part of nanonext.
#
Expand Down Expand Up @@ -168,7 +168,7 @@ close.nanoSocket <- function(con, ...) invisible(.Call(rnng_close, con))
#' \code{\link{.context}}. Returns silently and does not warn or error, nor does
#' it update the state of object attributes.
#'
#' @param con a Socket, Context, Listener, Dialer or Pipe.
#' @param con a Socket, Context, Listener, Dialer or integer pipe ID.
#'
#' @return An integer exit code (zero on success).
#'
Expand Down
2 changes: 1 addition & 1 deletion man/reap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/proto.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022-2024 Hibiki AI Limited <info@hibiki-ai.com>
// Copyright (C) 2022-2025 Hibiki AI Limited <info@hibiki-ai.com>
//
// This file is part of nanonext.
//
Expand Down Expand Up @@ -195,6 +195,11 @@ SEXP rnng_reap(SEXP con) {
} else if (ptrtag == nano_DialerSymbol) {
xc = nng_dialer_close(*(nng_dialer *) NANO_PTR(con));

} else if (TYPEOF(con) == INTSXP) {
nng_pipe p;
p.id = (uint32_t) NANO_INTEGER(con);
xc = nng_pipe_close(p);

} else {
xc = 3;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ test_zero(send_aio(poly, "one", timeout = 500, pipe = pipes[1L])[])
test_zero(send(poly, "two", block = 500, pipe = pipes[2L]))
test_type("character", recv(poly1, block = 500))
test_type("character", recv(poly2, block = 500))
test_zero(reap(pipes[1L]))
test_zero(reap(pipes[2L]))
test_zero(reap(poly2))
test_zero(reap(poly1))
test_true(wait(cv))
Expand Down

0 comments on commit 3523c36

Please sign in to comment.