Skip to content

Commit 7029857

Browse files
committed
various cleanups
1 parent 9952eb2 commit 7029857

File tree

12 files changed

+198
-175
lines changed

12 files changed

+198
-175
lines changed

R/aio.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ send_aio.nanoSocket <- function(con, data, mode = c("serial", "raw"), timeout =
5555
aio <- .Call(rnng_send_aio, con, data, timeout)
5656
is.integer(aio) && return(invisible(aio))
5757

58-
result <- NULL
58+
data <- result <- NULL
5959
unresolv <- TRUE
6060
env <- new.env(hash = FALSE)
6161
makeActiveBinding(sym = "result", fun = function(x) {
@@ -84,7 +84,7 @@ send_aio.nanoContext <- function(con, data, mode = c("serial", "raw"), timeout =
8484
aio <- .Call(rnng_ctx_send_aio, con, data, timeout)
8585
is.integer(aio) && return(invisible(aio))
8686

87-
result <- NULL
87+
data <- result <- NULL
8888
unresolv <- TRUE
8989
env <- new.env(hash = FALSE)
9090
makeActiveBinding(sym = "result", fun = function(x) {
@@ -112,7 +112,7 @@ send_aio.nanoStream <- function(con, data, mode = "raw", timeout = -2L) {
112112
aio <- .Call(rnng_stream_send_aio, con, data, timeout)
113113
is.integer(aio) && return(invisible(aio))
114114

115-
result <- NULL
115+
data <- result <- NULL
116116
unresolv <- TRUE
117117
env <- new.env(hash = FALSE)
118118
makeActiveBinding(sym = "result", fun = function(x) {
@@ -191,7 +191,7 @@ recv_aio <- function(con,
191191
timeout = -2L,
192192
keep.raw = TRUE,
193193
...,
194-
n = 100000L) UseMethod("recv_aio")
194+
n = 65536L) UseMethod("recv_aio")
195195

196196
#' @rdname recv_aio
197197
#' @method recv_aio nanoSocket
@@ -354,7 +354,7 @@ recv_aio.nanoStream <- function(con,
354354
"logical", "numeric", "raw"),
355355
timeout = -2L,
356356
keep.raw = TRUE,
357-
n = 100000L,
357+
n = 65536L,
358358
...) {
359359

360360
mode <- match.arg2(mode, c("character", "complex", "double", "integer",

R/messenger.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
#'
2020
#' \code{:q} is the command to quit.
2121
#'
22-
#' NOTE: This is a proof of concept intended for use within internal
23-
#' networks. Currently no measures are taken to verify the identity of
24-
#' endpoints, and hence should not be used to transmit sensitive information.
22+
#' NOTE: This is currently a proof of concept and should not be used for
23+
#' critical applications.
2524
#'
2625
#' @export
2726
#'
@@ -43,6 +42,7 @@ messenger <- function(url) {
4342
}
4443
cat(sprintf("\n| url: %s\n", url), file = stdout())
4544
cat("| connecting... ", file = stderr())
45+
4646
s <- suppressWarnings(.Call(rnng_send, sock, writeBin(":c ", raw()), 1000L))
4747
if (is.integer(s)) {
4848
cat(sprintf("\r| peer offline: %s\n", format.POSIXct(Sys.time())), file = stderr())

R/sendrecv.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ send.nanoStream <- function(con,
142142
#' @param keep.raw [default TRUE] logical flag whether to keep the received raw
143143
#' vector (useful for verification e.g. via hashing). If FALSE, will return
144144
#' the converted data only.
145-
#' @param n <Streams> [default 100000L] the maximum number of bytes to receive.
145+
#' @param n <Streams> [default 65536L] the maximum number of bytes to receive.
146146
#' Can be an over-estimate, but note that a buffer of this size is reserved.
147147
#' @param ... currently unused.
148148
#'
@@ -212,7 +212,7 @@ recv <- function(con,
212212
block,
213213
keep.raw = TRUE,
214214
...,
215-
n = 100000L) UseMethod("recv")
215+
n = 65536L) UseMethod("recv")
216216

217217
#' @rdname recv
218218
#' @method recv nanoSocket
@@ -269,7 +269,7 @@ recv.nanoStream <- function(con,
269269
"logical", "numeric", "raw"),
270270
block = TRUE,
271271
keep.raw = TRUE,
272-
n = 100000L,
272+
n = 65536L,
273273
...) {
274274

275275
mode <- match.arg2(mode, c("character", "complex", "double", "integer",

man/messenger.Rd

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/recv.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/recv_aio.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aio.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct nano_handle_s {
3131
nng_tls_config *cfg;
3232
} nano_handle;
3333

34-
static void saio_complete(void *arg) {
34+
void saio_complete(void *arg) {
3535

3636
nano_aio *saio = (nano_aio *) (arg);
3737
saio->result = nng_aio_result(saio->aio);
@@ -43,7 +43,7 @@ static void saio_complete(void *arg) {
4343

4444
}
4545

46-
static void raio_complete(void *arg) {
46+
void raio_complete(void *arg) {
4747

4848
nano_aio *raio = (nano_aio *) (arg);
4949
raio->result = nng_aio_result(raio->aio);
@@ -55,7 +55,7 @@ static void raio_complete(void *arg) {
5555

5656
}
5757

58-
static void iaio_complete(void *arg) {
58+
void iaio_complete(void *arg) {
5959

6060
nano_aio *iaio = (nano_aio *) (arg);
6161
iaio->result = nng_aio_result(iaio->aio);
@@ -65,7 +65,7 @@ static void iaio_complete(void *arg) {
6565

6666
}
6767

68-
static void saio_finalizer(SEXP xptr) {
68+
void saio_finalizer(SEXP xptr) {
6969

7070
if (R_ExternalPtrAddr(xptr) == NULL)
7171
return;
@@ -76,7 +76,7 @@ static void saio_finalizer(SEXP xptr) {
7676

7777
}
7878

79-
static void raio_finalizer(SEXP xptr) {
79+
void raio_finalizer(SEXP xptr) {
8080

8181
if (R_ExternalPtrAddr(xptr) == NULL)
8282
return;
@@ -89,7 +89,7 @@ static void raio_finalizer(SEXP xptr) {
8989

9090
}
9191

92-
static void isaio_finalizer(SEXP xptr) {
92+
void isaio_finalizer(SEXP xptr) {
9393

9494
if (R_ExternalPtrAddr(xptr) == NULL)
9595
return;
@@ -101,7 +101,7 @@ static void isaio_finalizer(SEXP xptr) {
101101

102102
}
103103

104-
static void iraio_finalizer(SEXP xptr) {
104+
void iraio_finalizer(SEXP xptr) {
105105

106106
if (R_ExternalPtrAddr(xptr) == NULL)
107107
return;
@@ -115,7 +115,7 @@ static void iraio_finalizer(SEXP xptr) {
115115

116116
}
117117

118-
static void haio_finalizer(SEXP xptr) {
118+
void haio_finalizer(SEXP xptr) {
119119

120120
if (R_ExternalPtrAddr(xptr) == NULL)
121121
return;
@@ -393,7 +393,7 @@ SEXP rnng_stream_recv_aio(SEXP stream, SEXP bytes, SEXP timeout) {
393393

394394
nng_stream *sp = (nng_stream *) R_ExternalPtrAddr(stream);
395395
const nng_duration dur = (nng_duration) Rf_asInteger(timeout);
396-
const size_t xlen = Rf_asInteger(bytes) + 1;
396+
const size_t xlen = Rf_asInteger(bytes);
397397
int xc;
398398

399399
nano_aio *iaio = R_Calloc(1, nano_aio);

src/core.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,53 @@
22

33
#define NANONEXT_INTERNALS
44
#define NANONEXT_PROTOCOLS
5-
#define NANONEXT_FINALIZERS
65
#include "nanonext.h"
76

8-
/* statics ------------------------------------------------------------------ */
7+
/* mk_error ----------------------------------------------------------------- */
98

10-
static void context_finalizer(SEXP xptr) {
9+
SEXP mk_error(const int xc) {
10+
11+
SEXP err = PROTECT(Rf_ScalarInteger(xc));
12+
Rf_classgets(err, Rf_mkString("errorValue"));
13+
Rf_warning("%d | %s", xc, nng_strerror(xc));
14+
UNPROTECT(1);
15+
return err;
16+
17+
}
18+
19+
/* finalizers --------------------------------------------------------------- */
20+
21+
void socket_finalizer(SEXP xptr) {
22+
23+
if (R_ExternalPtrAddr(xptr) == NULL)
24+
return;
25+
nng_socket *xp = (nng_socket *) R_ExternalPtrAddr(xptr);
26+
nng_close(*xp);
27+
R_Free(xp);
28+
29+
}
30+
31+
void dialer_finalizer(SEXP xptr) {
32+
33+
if (R_ExternalPtrAddr(xptr) == NULL)
34+
return;
35+
nng_dialer *xp = (nng_dialer *) R_ExternalPtrAddr(xptr);
36+
nng_dialer_close(*xp);
37+
R_Free(xp);
38+
39+
}
40+
41+
void listener_finalizer(SEXP xptr) {
42+
43+
if (R_ExternalPtrAddr(xptr) == NULL)
44+
return;
45+
nng_listener *xp = (nng_listener *) R_ExternalPtrAddr(xptr);
46+
nng_listener_close(*xp);
47+
R_Free(xp);
48+
49+
}
50+
51+
void context_finalizer(SEXP xptr) {
1152

1253
if (R_ExternalPtrAddr(xptr) == NULL)
1354
return;
@@ -21,7 +62,7 @@ static void context_finalizer(SEXP xptr) {
2162

2263
SEXP rnng_protocol_open(SEXP protocol) {
2364

24-
int pro = INTEGER(protocol)[0];
65+
const int pro = *INTEGER(protocol);
2566
char *pname;
2667
int xc;
2768

@@ -545,7 +586,7 @@ SEXP rnng_stream_recv(SEXP stream, SEXP bytes, SEXP timeout) {
545586

546587
nng_stream *sp = (nng_stream *) R_ExternalPtrAddr(stream);
547588
const nng_duration dur = (nng_duration) Rf_asInteger(timeout);
548-
const size_t xlen = Rf_asInteger(bytes) + 1;
589+
const size_t xlen = Rf_asInteger(bytes);
549590
nng_iov iov;
550591
nng_aio *aiop;
551592
int xc;

src/nanonext.h

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,12 @@
3333
#include <R_ext/Visibility.h>
3434

3535
#ifdef NANONEXT_INTERNALS
36-
static SEXP mk_error(const int xc) {
37-
38-
SEXP err = PROTECT(Rf_ScalarInteger(xc));
39-
Rf_classgets(err, Rf_mkString("errorValue"));
40-
Rf_warning("%d | %s", xc, nng_strerror(xc));
41-
UNPROTECT(1);
42-
return err;
43-
44-
}
45-
#endif
46-
47-
#ifdef NANONEXT_FINALIZERS
48-
static void socket_finalizer(SEXP xptr) {
49-
50-
if (R_ExternalPtrAddr(xptr) == NULL)
51-
return;
52-
nng_socket *xp = (nng_socket *) R_ExternalPtrAddr(xptr);
53-
nng_close(*xp);
54-
R_Free(xp);
55-
56-
}
57-
58-
static void dialer_finalizer(SEXP xptr) {
59-
60-
if (R_ExternalPtrAddr(xptr) == NULL)
61-
return;
62-
nng_dialer *xp = (nng_dialer *) R_ExternalPtrAddr(xptr);
63-
nng_dialer_close(*xp);
64-
R_Free(xp);
65-
66-
}
67-
68-
static void listener_finalizer(SEXP xptr) {
69-
70-
if (R_ExternalPtrAddr(xptr) == NULL)
71-
return;
72-
nng_listener *xp = (nng_listener *) R_ExternalPtrAddr(xptr);
73-
nng_listener_close(*xp);
74-
R_Free(xp);
75-
76-
}
36+
extern SEXP mk_error(const int);
37+
extern void socket_finalizer(SEXP);
38+
extern void dialer_finalizer(SEXP);
39+
extern void listener_finalizer(SEXP);
7740
#endif
7841

79-
/* define internal symbols */
8042
extern SEXP nano_AioSymbol;
8143
extern SEXP nano_ContextSymbol;
8244
extern SEXP nano_DataSymbol;
@@ -91,7 +53,6 @@ extern SEXP nano_StreamSymbol;
9153
extern SEXP nano_TextframesSymbol;
9254
extern SEXP nano_UrlSymbol;
9355

94-
/* define functions */
9556
extern SEXP rnng_aio_call(SEXP);
9657
extern SEXP rnng_aio_get_msg(SEXP);
9758
extern SEXP rnng_aio_http(SEXP);

0 commit comments

Comments
 (0)