Skip to content

Commit b8ed236

Browse files
committed
more efficient aio structure; remove legacy nng compat; requires nng >= 1.6.0
1 parent 3233638 commit b8ed236

File tree

9 files changed

+12
-152
lines changed

9 files changed

+12
-152
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ License: GPL (>= 3)
2626
BugReports: https://github.com/shikokuchuo/nanonext/issues
2727
URL: https://shikokuchuo.net/nanonext/, https://github.com/shikokuchuo/nanonext/
2828
Encoding: UTF-8
29-
SystemRequirements: 'libnng' >= 1.5 and 'libmbedtls' >= 2.5, or 'cmake' to
29+
SystemRequirements: 'libnng' >= 1.6 and 'libmbedtls' >= 2.5, or 'cmake' to
3030
compile NNG and/or Mbed TLS included in package sources
3131
Depends:
3232
R (>= 3.5)

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Integrates with the `later` package to provide the foundation for truly event-driven (non-polling) promises (thanks @jcheng5 for the initial prototype in #28), where side-effects are enacted asynchronously upon aio completion.
44
* Adds `request2()` for creating a request that may be turned into an event-driven promise.
5+
* Updates minimum 'libnng' version requirement to v1.6.0 (if a suitable system-installed version is not found, the bundled version is compiled from source).
56

67
# nanonext 0.13.6
78

README.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ vignette("nanonext", package = "nanonext")
149149

150150
#### Linux / Mac / Solaris
151151

152-
Installation from source requires 'libnng' >= v1.5.0 and 'libmbedtls' >= 2.5.0 (suitable installations are automatically detected), or else 'cmake' to compile 'libnng' v1.7.3 and 'libmbedtls' v3.6.0 LTS included within the package sources.
152+
Installation from source requires 'libnng' >= v1.6.0 and 'libmbedtls' >= 2.5.0 (suitable installations are automatically detected), or else 'cmake' to compile 'libnng' v1.7.3 and 'libmbedtls' v3.6.0 LTS included within the package sources.
153153

154154
**It is recommended for optimal performance and stability to let the package automatically compile bundled versions of 'libmbedtls' and 'libnng' during installation.** To ensure the libraries are compiled from source even if system installations are present, set the `NANONEXT_LIBS` environment variable prior to installation e.g. by `Sys.setenv(NANONEXT_LIBS = 1)`.
155155

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ vignette("nanonext", package = "nanonext")
178178

179179
#### Linux / Mac / Solaris
180180

181-
Installation from source requires ‘libnng’ \>= v1.5.0 and ‘libmbedtls’
181+
Installation from source requires ‘libnng’ \>= v1.6.0 and ‘libmbedtls’
182182
\>= 2.5.0 (suitable installations are automatically detected), or else
183183
‘cmake’ to compile ‘libnng’ v1.7.3 and ‘libmbedtls’ v3.6.0 LTS included
184184
within the package sources.

configure

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fi
128128

129129
echo "#include <nng/nng.h>
130130
int main() {
131-
#if NNG_MAJOR_VERSION < 1 || NNG_MAJOR_VERSION == 1 && NNG_MINOR_VERSION < 5
131+
#if NNG_MAJOR_VERSION < 1 || NNG_MAJOR_VERSION == 1 && NNG_MINOR_VERSION < 6
132132
*(void *) 0 = 0;
133133
#endif
134134
}" | ${CC} ${NNG_CFLAGS} -xc - -o /dev/null > /dev/null 2>&1
@@ -140,7 +140,7 @@ fi
140140

141141
if [ $? -ne 0 ]
142142
then
143-
echo "No existing 'libnng' >= 1.5 found"
143+
echo "No existing 'libnng' >= 1.6 found"
144144
echo "Detecting 'cmake'..."
145145
which cmake
146146
if [ $? -ne 0 ]

src/aio.c

+6-77
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,7 @@ static void saio_complete(void *arg) {
160160
const int res = nng_aio_result(saio->aio);
161161
if (res)
162162
nng_msg_free(nng_aio_get_msg(saio->aio));
163-
164-
#ifdef NANONEXT_LEGACY_NNG
165-
nng_mtx_lock(shr_mtx);
166-
saio->result = res - !res;
167-
nng_mtx_unlock(shr_mtx);
168-
#else
169163
saio->result = res - !res;
170-
#endif
171164

172165
}
173166

@@ -185,14 +178,7 @@ static void isaio_complete(void *arg) {
185178
const int res = nng_aio_result(iaio->aio);
186179
if (iaio->data != NULL)
187180
R_Free(iaio->data);
188-
189-
#ifdef NANONEXT_LEGACY_NNG
190-
nng_mtx_lock(shr_mtx);
191181
iaio->result = res - !res;
192-
nng_mtx_unlock(shr_mtx);
193-
#else
194-
iaio->result = res - !res;
195-
#endif
196182

197183
}
198184

@@ -203,13 +189,7 @@ static void raio_complete(void *arg) {
203189
if (res == 0)
204190
raio->data = nng_aio_get_msg(raio->aio);
205191

206-
#ifdef NANONEXT_LEGACY_NNG
207-
nng_mtx_lock(shr_mtx);
208-
raio->result = res - !res;
209-
nng_mtx_unlock(shr_mtx);
210-
#else
211192
raio->result = res - !res;
212-
#endif
213193

214194
}
215195

@@ -271,17 +251,11 @@ static void raio_complete_cb(void *arg) {
271251
const int res = nng_aio_result(raio->aio);
272252
if (res == 0)
273253
raio->data = nng_aio_get_msg(raio->aio);
274-
275-
#ifdef NANONEXT_LEGACY_NNG
276-
nng_mtx_lock(shr_mtx);
277254
raio->result = res - !res;
278-
nng_mtx_unlock(shr_mtx);
279-
#else
280-
raio->result = res - !res;
281-
#endif
282255

283-
if (CADR(ATTRIB(raio->cb)) != R_NilValue)
284-
later2(raio_invoke_cb, raio->cb, 0);
256+
nano_aio *saio = (nano_aio *) raio->next;
257+
if (CADR(ATTRIB((SEXP) saio->data)) != R_NilValue)
258+
later2(raio_invoke_cb, saio->data, 0);
285259

286260
}
287261

@@ -303,23 +277,16 @@ static void request_complete_cb(void *arg) {
303277
nng_cv_wake(cv);
304278
nng_mtx_unlock(mtx);
305279

306-
if (CADR(ATTRIB(raio->cb)) != R_NilValue)
307-
later2(raio_invoke_cb, raio->cb, 0);
280+
if (CADR(ATTRIB((SEXP) saio->data)) != R_NilValue)
281+
later2(raio_invoke_cb, saio->data, 0);
308282

309283
}
310284

311285
static void iraio_complete(void *arg) {
312286

313287
nano_aio *iaio = (nano_aio *) arg;
314288
const int res = nng_aio_result(iaio->aio);
315-
316-
#ifdef NANONEXT_LEGACY_NNG
317-
nng_mtx_lock(shr_mtx);
318-
iaio->result = res - !res;
319-
nng_mtx_unlock(shr_mtx);
320-
#else
321289
iaio->result = res - !res;
322-
#endif
323290

324291
}
325292

@@ -367,9 +334,6 @@ static void request_finalizer(SEXP xptr) {
367334
if (R_ExternalPtrAddr(xptr) == NULL) return;
368335
nano_aio *xp = (nano_aio *) R_ExternalPtrAddr(xptr);
369336
nano_aio *saio = (nano_aio *) xp->next;
370-
#ifdef NANONEXT_LEGACY_NNG
371-
nng_ctx_close(*(nng_ctx *) saio->data);
372-
#endif
373337
nng_aio_free(saio->aio);
374338
nng_aio_free(xp->aio);
375339
if (xp->data != NULL)
@@ -447,15 +411,7 @@ SEXP rnng_aio_result(SEXP env) {
447411

448412
nano_aio *saio = (nano_aio *) R_ExternalPtrAddr(aio);
449413

450-
#ifdef NANONEXT_LEGACY_NNG
451-
int res;
452-
nng_mtx_lock(shr_mtx);
453-
res = saio->result;
454-
nng_mtx_unlock(shr_mtx);
455-
if (res == 0)
456-
#else
457414
if (nng_aio_busy(saio->aio))
458-
#endif
459415
return nano_unresolved;
460416

461417
if (saio->result > 0)
@@ -479,15 +435,7 @@ SEXP rnng_aio_get_msg(SEXP env) {
479435

480436
nano_aio *raio = (nano_aio *) R_ExternalPtrAddr(aio);
481437

482-
#ifdef NANONEXT_LEGACY_NNG
483-
int res;
484-
nng_mtx_lock(shr_mtx);
485-
res = raio->result;
486-
nng_mtx_unlock(shr_mtx);
487-
if (res == 0)
488-
#else
489438
if (nng_aio_busy(raio->aio))
490-
#endif
491439
return nano_unresolved;
492440

493441
if (raio->result > 0)
@@ -652,15 +600,7 @@ SEXP rnng_unresolved2(SEXP aio) {
652600

653601
nano_aio *aiop = (nano_aio *) R_ExternalPtrAddr(coreaio);
654602

655-
#ifdef NANONEXT_LEGACY_NNG
656-
int res;
657-
nng_mtx_lock(shr_mtx);
658-
res = aiop->result;
659-
nng_mtx_unlock(shr_mtx);
660-
return Rf_ScalarLogical(!res);
661-
#else
662603
return Rf_ScalarLogical(nng_aio_busy(aiop->aio));
663-
#endif
664604

665605
}
666606

@@ -1004,15 +944,7 @@ SEXP rnng_aio_http(SEXP env, SEXP response, SEXP type) {
1004944

1005945
nano_aio *haio = (nano_aio *) R_ExternalPtrAddr(aio);
1006946

1007-
#ifdef NANONEXT_LEGACY_NNG
1008-
int res;
1009-
nng_mtx_lock(shr_mtx);
1010-
res = haio->result;
1011-
nng_mtx_unlock(shr_mtx);
1012-
if (res == 0)
1013-
#else
1014947
if (nng_aio_busy(haio->aio))
1015-
#endif
1016948
return nano_unresolved;
1017949

1018950
if (haio->result > 0)
@@ -1292,9 +1224,6 @@ SEXP rnng_request_impl(const SEXP con, const SEXP data, const SEXP sendmode,
12921224
}
12931225

12941226
saio = R_Calloc(1, nano_aio);
1295-
#ifdef NANONEXT_LEGACY_NNG
1296-
saio->data = ctx;
1297-
#endif
12981227
saio->next = ncv;
12991228

13001229
if ((xc = nng_msg_alloc(&msg, 0)))
@@ -1316,7 +1245,7 @@ SEXP rnng_request_impl(const SEXP con, const SEXP data, const SEXP sendmode,
13161245
raio->next = saio;
13171246
if (promises) {
13181247
R_PreserveObject(env);
1319-
raio->cb = env;
1248+
saio->data = env;
13201249
}
13211250

13221251
if ((xc = nng_aio_alloc(&raio->aio,

src/core.c

-52
Original file line numberDiff line numberDiff line change
@@ -982,30 +982,6 @@ SEXP rnng_send(SEXP con, SEXP data, SEXP mode, SEXP block) {
982982
nng_ctx *ctxp = (nng_ctx *) R_ExternalPtrAddr(con);
983983
nng_msg *msgp;
984984

985-
#ifdef NANONEXT_LEGACY_NNG
986-
987-
nng_aio *aiop;
988-
989-
if ((xc = nng_msg_alloc(&msgp, 0)))
990-
goto exitlevel1;
991-
992-
if ((xc = nng_msg_append(msgp, buf.buf, buf.cur)) ||
993-
(xc = nng_aio_alloc(&aiop, NULL, NULL))) {
994-
nng_msg_free(msgp);
995-
goto exitlevel1;
996-
}
997-
998-
nng_aio_set_msg(aiop, msgp);
999-
nng_aio_set_timeout(aiop, flags < 0 ? 0 : flags > 0 ? flags : (*NANO_INTEGER(block) == 1) * NNG_DURATION_DEFAULT);
1000-
nng_ctx_send(*ctxp, aiop);
1001-
NANO_FREE(buf);
1002-
nng_aio_wait(aiop);
1003-
if ((xc = nng_aio_result(aiop)))
1004-
nng_msg_free(nng_aio_get_msg(aiop));
1005-
nng_aio_free(aiop);
1006-
1007-
#else
1008-
1009985
if (flags <= 0) {
1010986

1011987
if ((xc = nng_msg_alloc(&msgp, 0)))
@@ -1043,8 +1019,6 @@ SEXP rnng_send(SEXP con, SEXP data, SEXP mode, SEXP block) {
10431019

10441020
}
10451021

1046-
#endif
1047-
10481022
} else if (ptrtag == nano_StreamSymbol) {
10491023

10501024
nano_encode(&buf, data);
@@ -1136,30 +1110,6 @@ SEXP rnng_recv(SEXP con, SEXP mode, SEXP block, SEXP bytes) {
11361110
nng_ctx *ctxp = (nng_ctx *) R_ExternalPtrAddr(con);
11371111
nng_msg *msgp;
11381112

1139-
#ifdef NANONEXT_LEGACY_NNG
1140-
1141-
nng_aio *aiop;
1142-
1143-
if ((xc = nng_aio_alloc(&aiop, NULL, NULL)))
1144-
goto exitlevel1;
1145-
nng_aio_set_timeout(aiop, flags < 0 ? 0 : flags > 0 ? flags : (*NANO_INTEGER(block) == 1) * NNG_DURATION_DEFAULT);
1146-
nng_ctx_recv(*ctxp, aiop);
1147-
1148-
nng_aio_wait(aiop);
1149-
if ((xc = nng_aio_result(aiop))) {
1150-
nng_aio_free(aiop);
1151-
goto exitlevel1;
1152-
}
1153-
1154-
msgp = nng_aio_get_msg(aiop);
1155-
nng_aio_free(aiop);
1156-
buf = nng_msg_body(msgp);
1157-
sz = nng_msg_len(msgp);
1158-
res = nano_decode(buf, sz, mod);
1159-
nng_msg_free(msgp);
1160-
1161-
#else
1162-
11631113
if (flags <= 0) {
11641114

11651115
xc = nng_ctx_recvmsg(*ctxp, &msgp, (flags < 0 || *NANO_INTEGER(block) != 1) * NNG_FLAG_NONBLOCK);
@@ -1195,8 +1145,6 @@ SEXP rnng_recv(SEXP con, SEXP mode, SEXP block, SEXP bytes) {
11951145

11961146
}
11971147

1198-
#endif
1199-
12001148
} else if (ptrtag == nano_StreamSymbol) {
12011149

12021150
mod = nano_matchargs(mode);

src/init.c

-10
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ SEXP nano_refHook;
5050
SEXP nano_success;
5151
SEXP nano_unresolved;
5252

53-
#ifdef NANONEXT_LEGACY_NNG
54-
nng_mtx *shr_mtx;
55-
#endif
56-
5753
static void RegisterSymbols(void) {
5854
nano_AioSymbol = Rf_install("aio");
5955
nano_ContextSymbol = Rf_install("context");
@@ -193,17 +189,11 @@ static const R_ExternalMethodDef externalMethods[] = {
193189
void attribute_visible R_init_nanonext(DllInfo* dll) {
194190
RegisterSymbols();
195191
PreserveObjects();
196-
#ifdef NANONEXT_LEGACY_NNG
197-
nng_mtx_alloc(&shr_mtx);
198-
#endif
199192
R_registerRoutines(dll, NULL, callMethods, NULL, externalMethods);
200193
R_useDynamicSymbols(dll, FALSE);
201194
R_forceSymbols(dll, TRUE);
202195
}
203196

204197
void attribute_visible R_unload_nanonext(DllInfo *info) {
205198
ReleaseObjects();
206-
#ifdef NANONEXT_LEGACY_NNG
207-
nng_mtx_free(shr_mtx);
208-
#endif
209199
}

src/nanonext.h

-8
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
#include <nng/nng.h>
2323

24-
#if NNG_MAJOR_VERSION == 1 && NNG_MINOR_VERSION < 6
25-
#define NANONEXT_LEGACY_NNG
26-
#endif
27-
2824
#ifdef NANONEXT_PROTOCOLS
2925
#include <nng/protocol/bus0/bus.h>
3026
#include <nng/protocol/pair0/pair.h>
@@ -45,9 +41,6 @@
4541
#ifdef NANONEXT_SUPPLEMENTALS
4642
#include <nng/supplemental/tls/tls.h>
4743
#include <nng/supplemental/util/platform.h>
48-
#ifdef NANONEXT_LEGACY_NNG
49-
extern nng_mtx *shr_mtx;
50-
#endif
5144

5245
typedef struct nano_listener_s {
5346
nng_listener list;
@@ -88,7 +81,6 @@ typedef struct nano_aio_s {
8881
int result;
8982
void *data;
9083
void *next;
91-
void *cb;
9284
} nano_aio;
9385

9486
typedef struct nano_cv_s {

0 commit comments

Comments
 (0)