Skip to content

Commit

Permalink
reorg header definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jun 21, 2024
1 parent ab8ea92 commit a24131d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 50 deletions.
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#### New Features

* Adds 'ncurlAio' method for `promises::as.promise()` and `promises::is.promising()` to enable 'ncurlAio' promises.
* Adds method `x[]` for an Aio `x` as a new equivalent to `collect_aio_(x)`, which waits for and collects the data.
* Adds `x[]` as a new method for an Aio `x` equivalent to `collect_aio_(x)`, which waits for and collects the data.

#### Updates

* `request()` specifying argument 'cv' other than NULL or a 'conditionVariable' will cause the pipe connection to be dropped when the reply is (asynchronously) completed.
* Removes deprecated functions `strcat()`, `recv_aio_signal()` and `request_signal()`.
* Removes `base64enc()` and `base64dec()` in favour of those in the {secretbase} package.
* `later` is now a 'suggests' dependency (only required if using promises).
* Drops `base64enc()` and `base64dec()` in favour of those from the {secretbase} package.
* `later` is now relaxed to a soft 'suggests' dependency (only required if using promises).
* `promises` is added as a soft 'enhances' dependency.

# nanonext 1.1.0

Expand Down
20 changes: 3 additions & 17 deletions src/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

// nanonext - C level - Async Functions ----------------------------------------

#define NANONEXT_HTTP
#define NANONEXT_SUPPLEMENTALS
#define NANONEXT_SIGNALS
#include "nanonext.h"
Expand All @@ -37,19 +36,6 @@ static inline SEXP R_mkClosure(SEXP formals, SEXP body, SEXP env) {

// internals -------------------------------------------------------------------

typedef struct nano_cv_duo_s {
nano_cv *cv;
nano_cv *cv2;
} nano_cv_duo;

typedef struct nano_handle_s {
nng_url *url;
nng_http_client *cli;
nng_http_req *req;
nng_http_res *res;
nng_tls_config *cfg;
} nano_handle;

static SEXP mk_error_aio(const int xc, SEXP env) {

SEXP err = PROTECT(Rf_ScalarInteger(xc));
Expand Down Expand Up @@ -88,7 +74,7 @@ static SEXP mk_error_haio(const int xc, SEXP env) {

}

static SEXP mk_error_ncurl(const int xc) {
static SEXP mk_error_ncurlaio(const int xc) {

SEXP env, err;
PROTECT(env = Rf_allocSExp(ENVSXP));
Expand Down Expand Up @@ -1033,7 +1019,7 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP dat
exitlevel1:
R_Free(handle);
R_Free(haio);
return mk_error_ncurl(xc);
return mk_error_ncurlaio(xc);

}

Expand Down Expand Up @@ -1259,7 +1245,7 @@ SEXP rnng_ncurl_transact(SEXP session) {
nng_http_conn_transact(conn, handle->req, handle->res, haio->aio);
nng_aio_wait(haio->aio);
if (haio->result > 0)
return mk_error_ncurl(haio->result);
return mk_error_ncurlaio(haio->result);

SEXP out, vec, rvec, response;
void *dat;
Expand Down
9 changes: 0 additions & 9 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@
static uint8_t special_bit = 0;
static uint8_t registered = 0;

typedef union nano_opt_u {
char *str;
bool b;
nng_duration d;
int i;
size_t s;
uint64_t u;
} nano_opt;

SEXP nano_PreserveObject(SEXP x) {

SEXP node = Rf_cons(nano_precious, CDR(nano_precious));
Expand Down
39 changes: 35 additions & 4 deletions src/nanonext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@
#include <nng/protocol/survey0/respond.h>
#endif

#ifdef NANONEXT_HTTP
#include <nng/supplemental/http/http.h>
#endif

#ifdef NANONEXT_SUPPLEMENTALS
#include <nng/supplemental/http/http.h>
#include <nng/supplemental/tls/tls.h>
#include <nng/supplemental/util/platform.h>

typedef union nano_opt_u {
char *str;
bool b;
nng_duration d;
int i;
size_t s;
uint64_t u;
} nano_opt;

typedef struct nano_listener_s {
nng_listener list;
nng_tls_config *tls;
Expand Down Expand Up @@ -87,13 +93,38 @@ typedef struct nano_aio_s {
void *next;
} nano_aio;

typedef struct nano_handle_s {
nng_url *url;
nng_http_client *cli;
nng_http_req *req;
nng_http_res *res;
nng_tls_config *cfg;
} nano_handle;

typedef struct nano_cv_s {
int condition;
int flag;
nng_mtx *mtx;
nng_cv *cv;
} nano_cv;

typedef struct nano_cv_duo_s {
nano_cv *cv;
nano_cv *cv2;
} nano_cv_duo;

typedef struct nano_thread_aio_s {
nng_thread *thr;
nano_cv *cv;
nng_aio *aio;
} nano_thread_aio;

typedef struct nano_thread_duo_s {
nng_thread *thr;
nano_cv *cv;
nano_cv *cv2;
} nano_thread_duo;

#endif

#ifdef NANONEXT_SIGNALS
Expand Down
14 changes: 0 additions & 14 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@
#define NANONEXT_IO
#include "nanonext.h"

// internals -------------------------------------------------------------------

typedef struct nano_thread_aio_s {
nng_thread *thr;
nano_cv *cv;
nng_aio *aio;
} nano_thread_aio;

typedef struct nano_thread_duo_s {
nng_thread *thr;
nano_cv *cv;
nano_cv *cv2;
} nano_thread_duo;

// messenger -------------------------------------------------------------------

// # nocov start
Expand Down
5 changes: 2 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// nanonext - C level - Utilities ----------------------------------------------

#define NANONEXT_PROTOCOLS
#define NANONEXT_HTTP
#define NANONEXT_SUPPLEMENTALS
#include "nanonext.h"

Expand Down Expand Up @@ -678,8 +677,8 @@ SEXP rnng_tls_config(SEXP client, SEXP server, SEXP pass, SEXP auth) {
return xp;

exitlevel2:
nng_tls_config_free(cfg);
nng_tls_config_free(cfg);
exitlevel1:
ERROR_OUT(xc);
ERROR_OUT(xc);

}

0 comments on commit a24131d

Please sign in to comment.