Skip to content

Commit 95792cb

Browse files
committed
automatic detection for latomic linker flag
1 parent ed7726b commit 95792cb

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

README.Rmd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,6 @@ Otherwise, the environment variable `Sys.setenv(NANONEXT_TLS=1)` may be set prio
478478
- your system installations of 'libnng' (built with TLS support) and 'libmbedtls' are in different locations; or
479479
- you have a system installation of 'libmbedtls' but not 'libnng' and want nanonext to download and build a more recent version of 'libnng' than available in system repositories against this.
480480

481-
#### Certain ARM architectures
482-
483-
If package installation initially fails with an error message of `unable to load shared object:[ ] undefined symbol: __atomic_fetch_sub_8` or similar, please set the environment variable
484-
`Sys.setenv(NANONEXT_ARM=1)` and then proceed with installation again.
485-
486481
### Links
487482

488483
nanonext on CRAN: <https://cran.r-project.org/package=nanonext><br />

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Send message from ‘nano1’:
105105

106106
``` r
107107
nano1$send("hello world!")
108-
#> [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
108+
#> [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
109109
#> [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
110110
#> [51] 21
111111
```
@@ -115,7 +115,7 @@ Receive message using ‘nano2’:
115115
``` r
116116
nano2$recv()
117117
#> $raw
118-
#> [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
118+
#> [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
119119
#> [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
120120
#> [51] 21
121121
#>
@@ -146,7 +146,7 @@ Send message from ‘socket1’:
146146

147147
``` r
148148
send(socket1, "hello world!")
149-
#> [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
149+
#> [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
150150
#> [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
151151
#> [51] 21
152152
```
@@ -156,7 +156,7 @@ Receive message using ‘socket2’:
156156
``` r
157157
recv(socket2)
158158
#> $raw
159-
#> [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
159+
#> [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
160160
#> [26] 00 10 00 00 00 01 00 04 00 09 00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64
161161
#> [51] 21
162162
#>
@@ -235,6 +235,7 @@ n$recv(mode = "double")
235235
massively-scaleable concurrency framework.
236236

237237
``` r
238+
238239
s1 <- socket("pair", listen = "inproc://nano")
239240
s2 <- socket("pair", dial = "inproc://nano")
240241
```
@@ -247,6 +248,7 @@ operation is ongoing, automatically resolving to a final value once
247248
complete.
248249

249250
``` r
251+
250252
# an async receive is requested, but no messages are waiting (yet to be sent)
251253
msg <- recv_aio(s2)
252254
msg
@@ -260,6 +262,7 @@ msg$data
260262
For a ‘sendAio’ object, the result is stored at `$result`.
261263

262264
``` r
265+
263266
res <- send_aio(s1, data.frame(a = 1, b = 2))
264267
res
265268
#> < sendAio >
@@ -276,12 +279,13 @@ For a ‘recvAio’ object, the message is stored at `$data`, and the raw
276279
message at `$raw` (if kept).
277280

278281
``` r
282+
279283
# now that a message has been sent, the 'recvAio' automatically resolves
280284
msg$data
281285
#> a b
282286
#> 1 1 2
283287
msg$raw
284-
#> [1] 58 0a 00 00 00 03 00 04 01 03 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
288+
#> [1] 58 0a 00 00 00 03 00 04 02 00 00 03 05 00 00 00 00 05 55 54 46 2d 38 00 00
285289
#> [26] 03 13 00 00 00 02 00 00 00 0e 00 00 00 01 3f f0 00 00 00 00 00 00 00 00 00
286290
#> [51] 0e 00 00 00 01 40 00 00 00 00 00 00 00 00 00 04 02 00 00 00 01 00 04 00 09
287291
#> [76] 00 00 00 05 6e 61 6d 65 73 00 00 00 10 00 00 00 02 00 04 00 09 00 00 00 01
@@ -298,6 +302,7 @@ and after. This means there is no need to actually wait (block) for an
298302
Aio to resolve, as the example below demonstrates.
299303

300304
``` r
305+
301306
msg <- recv_aio(s2)
302307

303308
# unresolved() queries for resolution itself so no need to use it again within the while loop
@@ -317,6 +322,7 @@ The values may also be called explicitly using `call_aio()`. This will
317322
wait for completion of the Aio (blocking).
318323

319324
``` r
325+
320326
# will wait for completion then return the resolved Aio
321327
call_aio(msg)
322328

@@ -343,6 +349,7 @@ separate ‘server’ process running concurrently.
343349
function, in this case `rnorm()`, before sending back the result.
344350

345351
``` r
352+
346353
library(nanonext)
347354
rep <- socket("rep", listen = "tcp://127.0.0.1:6546")
348355
ctxp <- context(rep)
@@ -353,6 +360,7 @@ reply(ctxp, execute = rnorm, send_mode = "raw")
353360
request and returns immediately with a `recvAio` object.
354361

355362
``` r
363+
356364
library(nanonext)
357365
req <- socket("req", dial = "tcp://127.0.0.1:6546")
358366
ctxq <- context(req)
@@ -373,13 +381,14 @@ The return value from the server request is then retrieved and stored in
373381
the Aio as `$data`.
374382

375383
``` r
384+
376385
call_aio(aio)
377386

378387
aio
379388
#> < recvAio >
380389
#> - $data for message data
381390
aio$data |> str()
382-
#> num [1:100000000] -0.876 0.565 0.656 -1.265 -0.642 ...
391+
#> num [1:100000000] 0.5354 0.1424 0.3993 0.0906 1.6356 ...
383392
```
384393

385394
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -406,6 +415,7 @@ example. A subscriber can subscribe to one or multiple topics broadcast
406415
by a publisher.
407416

408417
``` r
418+
409419
pub <- socket("pub", listen = "inproc://nanobroadcast")
410420
sub <- socket("sub", dial = "inproc://nanobroadcast")
411421

@@ -454,6 +464,7 @@ itself is a timed event, and responses received after the timeout are
454464
discarded.
455465

456466
``` r
467+
457468
sur <- socket("surveyor", listen = "inproc://nanoservice")
458469
res1 <- socket("respondent", dial = "inproc://nanoservice")
459470
res2 <- socket("respondent", dial = "inproc://nanoservice")
@@ -511,21 +522,23 @@ returning immediately with a ‘recvAio’.
511522
For normal use, it takes just the URL. It can follow redirects.
512523

513524
``` r
525+
514526
ncurl("http://httpbin.org/headers")
515527
#> $raw
516528
#> [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
517529
#> [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
518530
#> [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
519-
#> [76] 2d 36 32 36 61 62 33 31 37 2d 31 39 63 35 39 37 30 32 36 63 30 63 64 65 32
520-
#> [101] 63 36 32 61 37 33 39 35 35 22 0a 20 20 7d 0a 7d 0a
531+
#> [76] 2d 36 32 36 64 62 31 35 33 2d 32 39 39 31 38 39 63 35 33 61 30 30 35 61 32
532+
#> [101] 38 32 33 65 31 34 38 62 37 22 0a 20 20 7d 0a 7d 0a
521533
#>
522534
#> $data
523-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626ab317-19c597026c0cde2c62a73955\"\n }\n}\n"
535+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626db153-299189c53a005a2823e148b7\"\n }\n}\n"
524536
```
525537

526538
For advanced use, supports additional HTTP methods such as POST or PUT.
527539

528540
``` r
541+
529542
res <- ncurl("http://httpbin.org/post", async = TRUE, method = "POST",
530543
headers = c(`Content-Type` = "application/json", Authorization = "Bearer APIKEY"),
531544
data = '{"key": "value"}')
@@ -535,7 +548,7 @@ res
535548
#> - $raw for raw message
536549

537550
call_aio(res)$data
538-
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626ab317-57e5ea9a6c08c36277518b08\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.189.204\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
551+
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-626db153-400a5a4e7880ba63075877ec\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"78.145.225.121\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
539552
```
540553

541554
In this respect, it may be used as a performant and lightweight method
@@ -550,6 +563,7 @@ communicating with raw sockets. This may be used for connecting to
550563
arbitrary non-NNG endpoints.
551564

552565
``` r
566+
553567
s <- stream(dial = "wss://demo.piesocket.com/v3/channel_1", textframes = TRUE)
554568
s
555569
#> < nanoStream >
@@ -619,13 +633,6 @@ set prior to installation if:
619633
want nanonext to download and build a more recent version of
620634
‘libnng’ than available in system repositories against this.
621635

622-
#### Certain ARM architectures
623-
624-
If package installation initially fails with an error message of
625-
`unable to load shared object:[ ] undefined symbol: __atomic_fetch_sub_8`
626-
or similar, please set the environment variable
627-
`Sys.setenv(NANONEXT_ARM=1)` and then proceed with installation again.
628-
629636
### Links
630637

631638
nanonext on CRAN: <https://cran.r-project.org/package=nanonext><br />

configure

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33

44
# set -x
55

6+
# Find compiler
7+
CC=`${R_HOME}/bin/R CMD config CC`
8+
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
9+
610
# Library settings
711
PKG_TEST_HEADER="<nng/nng.h>"
812
PKG_LIBS="-lnng"
913
if [ "$NANONEXT_TLS" ]; then
1014
echo "trying with TLS support"
1115
PKG_LIBS="$PKG_LIBS -lmbedtls -lmbedx509 -lmbedcrypto"
1216
fi
13-
if [ "$NANONEXT_ARM" ]; then
17+
18+
# Detect -latomic linker flag for e.g. ARM architectures (Raspberry Pi etc.)
19+
echo "#include <stdint.h>
20+
uint64_t v;
21+
int main() {
22+
return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
23+
}" | ${CC} -x c - -o /dev/null > /dev/null 2>&1
24+
if [ $? -ne 0 ]; then
25+
echo "adding -latomic linker flag"
1426
PKG_LIBS="$PKG_LIBS -latomic"
1527
fi
28+
1629
PKG_CFLAGS=""
1730
LIB_VER="169221d"
1831
SYS_LIB=0
@@ -86,10 +99,6 @@ fi
8699
# echo "Using PKG_CFLAGS=$PKG_CFLAGS"
87100
# echo "Using PKG_LIBS=$PKG_LIBS"
88101

89-
# Find compiler
90-
CC=`${R_HOME}/bin/R CMD config CC`
91-
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
92-
93102
# Test for libnng
94103
echo "#include $PKG_TEST_HEADER" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>&1
95104

0 commit comments

Comments
 (0)