Skip to content

Commit a72885f

Browse files
committed
Deploying to gh-pages from @ 80407ad 🚀
1 parent 43098e5 commit a72885f

21 files changed

+532
-32
lines changed

dev/CLAUDE.html

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

dev/CLAUDE.md

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working
4+
with code in this repository.
5+
6+
## Overview
7+
8+
**nanonext** is an R package providing a binding to NNG (Nanomsg Next
9+
Gen), a high-performance messaging library. The package is implemented
10+
almost entirely in C, wrapping the NNG C library to provide R interfaces
11+
for socket-based messaging, asynchronous I/O operations, and distributed
12+
computing primitives.
13+
14+
## Core Architecture
15+
16+
### Dual Interface Design
17+
18+
The package provides two equivalent interfaces:
19+
20+
1. **Functional Interface**: Socket objects passed as first argument to
21+
functions like
22+
[`send()`](https://nanonext.r-lib.org/dev/reference/send.md),
23+
[`recv()`](https://nanonext.r-lib.org/dev/reference/recv.md),
24+
[`dial()`](https://nanonext.r-lib.org/dev/reference/dial.md),
25+
[`listen()`](https://nanonext.r-lib.org/dev/reference/listen.md)
26+
2. **Object-Oriented Interface**: Nano objects with methods accessible
27+
via `$send()`, `$recv()`, etc.
28+
29+
### Key C Source Files
30+
31+
- `src/nanonext.h` - Main header with type definitions, macros, and
32+
function declarations
33+
- `src/core.c` - Core serialization/unserialization, hooks, and
34+
fundamental utilities
35+
- `src/proto.c` - Protocol implementations (socket opening, option
36+
handling)
37+
- `src/aio.c` - Asynchronous I/O operations and callbacks
38+
- `src/comms.c` - Send/receive operations and data marshaling
39+
- `src/sync.c` - Synchronization primitives (condition variables,
40+
mutexes)
41+
- `src/thread.c` - Thread management and concurrent operations
42+
- `src/ncurl.c` - HTTP client implementation
43+
- `src/net.c` - Network utilities (IP address retrieval)
44+
- `src/tls.c` - TLS configuration and certificate handling
45+
- `src/utils.c` - Utility functions
46+
- `src/init.c` - Package initialization and registration
47+
48+
### Key R Source Files
49+
50+
- `R/socket.R` - Socket creation and management (functional interface)
51+
- `R/nano.R` - Nano object creation (OO interface)
52+
- `R/sendrecv.R` - Send/receive operations
53+
- `R/aio.R` - Async I/O wrappers
54+
- `R/context.R` - Context management for concurrent operations
55+
- `R/sync.R` - Synchronization primitives
56+
- `R/ncurl.R` - HTTP client functions
57+
- `R/stream.R` - WebSocket and stream interfaces
58+
- `R/tls.R` - TLS configuration
59+
60+
### External Dependencies
61+
62+
The package bundles and can compile: - `libnng` v1.11.0 (messaging
63+
library) - in `src/nng/` - `libmbedtls` v3.6.2 (TLS implementation) - in
64+
`src/mbedtls/`
65+
66+
These bundled libraries are compiled during installation if system
67+
libraries are not found or if `NANONEXT_LIBS=1` is set.
68+
69+
## Common Development Commands
70+
71+
### Building and Testing
72+
73+
``` r
74+
# Install package from source
75+
R CMD INSTALL .
76+
77+
# Build package
78+
R CMD build .
79+
80+
# Check package (run all tests and CRAN checks)
81+
R CMD check nanonext_*.tar.gz
82+
83+
# Run tests only
84+
Rscript tests/tests.R
85+
```
86+
87+
### Development Workflow
88+
89+
``` r
90+
# In R session - load package for development
91+
devtools::load_all()
92+
93+
# Build documentation
94+
devtools::document()
95+
96+
# Run tests
97+
devtools::test()
98+
99+
# Check package
100+
devtools::check()
101+
```
102+
103+
### Compilation
104+
105+
The package uses a configure script (`configure`) that: 1. Detects or
106+
compiles `libmbedtls` (requires \>= 2.5.0) 2. Detects or compiles
107+
`libnng` (requires \>= 1.9.0) 3. Generates `src/Makevars` with
108+
appropriate flags
109+
110+
For forced compilation of bundled libraries:
111+
112+
``` bash
113+
Sys.setenv(NANONEXT_LIBS = 1)
114+
```
115+
116+
### Testing Notes
117+
118+
- Tests are in `tests/tests.R` using a minimal custom testing framework
119+
- Tests cover: sockets, protocols, async I/O, serialization, HTTP
120+
client, TLS, streams, contexts
121+
- Network-dependent tests may fail if external services are unavailable
122+
- Some tests only run when `NOT_CRAN=true` or on specific platforms
123+
(Linux)
124+
125+
## Key Concepts
126+
127+
### Protocols
128+
129+
Implements scalability protocols: - **Bus** (mesh): `"bus"` - **Pair**
130+
(1-to-1): `"pair"` - **Poly** (polyamorous 1-to-1): `"poly"` -
131+
**Pipeline**: `"push"`, `"pull"` - **Pub/Sub**: `"pub"`, `"sub"` -
132+
**Request/Reply**: `"req"`, `"rep"` - **Survey**: `"surveyor"`,
133+
`"respondent"`
134+
135+
### Transports
136+
137+
Supported URL schemes: - `inproc://` - in-process (zero-copy) -
138+
`ipc://` - inter-process - `tcp://` - TCP/IP - `ws://` - WebSocket -
139+
`wss://` - WebSocket over TLS - `tls+tcp://` - TLS over TCP
140+
141+
### Async I/O (AIO)
142+
143+
Async operations return “aio” objects that auto-resolve: -
144+
[`send_aio()`](https://nanonext.r-lib.org/dev/reference/send_aio.md),
145+
[`recv_aio()`](https://nanonext.r-lib.org/dev/reference/recv_aio.md) -
146+
async send/receive -
147+
[`request()`](https://nanonext.r-lib.org/dev/reference/request.md) -
148+
async request/reply -
149+
[`ncurl_aio()`](https://nanonext.r-lib.org/dev/reference/ncurl_aio.md) -
150+
async HTTP - Objects have `$data`, `$result` fields - Use
151+
[`call_aio()`](https://nanonext.r-lib.org/dev/reference/call_aio.md) to
152+
wait/retrieve results - Use
153+
[`unresolved()`](https://nanonext.r-lib.org/dev/reference/unresolved.md)
154+
to check status
155+
156+
### Serialization Modes
157+
158+
Data can be sent in multiple modes: - `mode = "serial"` or `1` - R
159+
serialization (default, handles any R object) - `mode = "raw"` or `2` -
160+
raw bytes (for atomic vectors) - `mode = "string"` or `8` - character
161+
conversion - Various receive modes for type coercion
162+
163+
Custom serialization supported via
164+
[`serial_config()`](https://nanonext.r-lib.org/dev/reference/serial_config.md)
165+
for specific object classes.
166+
167+
### Object System
168+
169+
The package uses R’s S3 object system with heavy use of external
170+
pointers tagged with specific symbols (defined in `src/init.c`): -
171+
`nano_SocketSymbol` - Socket objects - `nano_ContextSymbol` - Context
172+
objects - `nano_AioSymbol` - AIO objects - `nano_CvSymbol` - Condition
173+
variables - etc.
174+
175+
External pointers are stored in pairlists with finalizers for automatic
176+
cleanup.
177+
178+
## Important Implementation Details
179+
180+
### Memory Management
181+
182+
- C code uses `NANO_ALLOC`, `NANO_FREE` macros for buffer management
183+
- R objects protected via `nano_precious` environment (prevents GC)
184+
- Finalizers registered for cleanup of C resources
185+
- Careful use of `PROTECT`/`UNPROTECT` in C code
186+
187+
### Thread Safety
188+
189+
- Package implements its own threading via NNG’s platform layer
190+
- Condition variables
191+
([`cv()`](https://nanonext.r-lib.org/dev/reference/cv.md)) for
192+
cross-thread signaling
193+
- Mutexes used internally for shared state
194+
- R interrupt handling on both Unix (via `R_interrupts_pending`) and
195+
Windows
196+
197+
### Error Handling
198+
199+
- NNG errors returned as integer error codes
200+
- `mk_error()` creates error values of class `"errorValue"`
201+
- Error messages via `nng_strerror()`
202+
- Use `ERROR_OUT()` macro to error, `ERROR_RET()` to return error value
203+
204+
### Configuration Options
205+
206+
Set/get socket/dialer/listener options via: -
207+
`opt(object, "option-name")` - get -
208+
`opt(object, "option-name") <- value` - set
209+
210+
Options are protocol-specific (e.g., `"req:resend-time"`,
211+
`"sub:prefnew"`).
212+
213+
## Build System
214+
215+
- `configure` - POSIX shell script for Unix-like systems
216+
- `configure.win` - Windows configuration
217+
- `configure.ucrt` - UCRT-specific Windows config
218+
- Requires `cmake` if compiling bundled libraries (no longer requires
219+
`xz` as libraries are pre-extracted)
220+
- Environment variables: `INCLUDE_DIR`, `LIB_DIR`, `NANONEXT_LIBS`
221+
222+
## Documentation
223+
224+
- Roxygen2-based documentation in R files
225+
- Main vignette: `vignettes/nanonext.Rmd`
226+
- Website: <https://nanonext.r-lib.org>
227+
- Generated with pkgdown
228+
229+
## Code Style
230+
231+
- C code follows NNG conventions with `nano_` prefixes for package
232+
functions
233+
- R code uses snake_case for functions
234+
- Clear separation between user-facing and internal functions
235+
(`.function` prefix for internal)
236+
- Extensive use of macros for code clarity (`NANO_PTR`, `NANO_DATAPTR`,
237+
etc.)

dev/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pkgdown: 2.2.0
33
pkgdown_sha: ~
44
articles:
55
nanonext: nanonext.html
6-
last_built: 2025-12-02T14:53Z
6+
last_built: 2025-12-03T11:30Z
77
urls:
88
reference: https://nanonext.r-lib.org/reference
99
article: https://nanonext.r-lib.org/articles

dev/reference/ip_addr.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/reference/ip_addr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Windows) e.g. 'eth0' or 'en0'.
2424
``` r
2525
ip_addr()
2626
#> eth0 docker0
27-
#> "10.1.0.209" "172.17.0.1"
27+
#> "10.1.0.250" "172.17.0.1"
2828
```

dev/reference/monitor.html

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

dev/reference/monitor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ dial(s1)
4949
cv_value(cv)
5050
#> [1] 1
5151
read_monitor(m)
52-
#> [1] 2031400433
52+
#> [1] 1599648764
5353

5454
close(s)
5555
close(s1)
5656

5757
read_monitor(m)
58-
#> [1] -2031400433
58+
#> [1] -1599648764
5959
```

dev/reference/ncurl.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/reference/ncurl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ncurl(
114114
#>
115115
#> $headers
116116
#> $headers$date
117-
#> [1] "Tue, 02 Dec 2025 14:53:14 GMT"
117+
#> [1] "Wed, 03 Dec 2025 11:30:50 GMT"
118118
#>
119119
#> $headers$`content-type`
120120
#> [1] "application/json; charset=utf-8"

dev/reference/ncurl_aio.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)