diff --git a/DESCRIPTION b/DESCRIPTION index 1e474236e..a7ab11601 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: nanonext Type: Package Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library -Version: 1.2.1.9020 +Version: 1.2.1.9021 Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library implementing 'Scalability Protocols', a reliable, high-performance standard for common communications patterns including diff --git a/NEWS.md b/NEWS.md index 1df758081..1d081abd9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# nanonext 1.2.1.9020 (development) +# nanonext 1.2.1.9021 (development) #### New Features @@ -7,6 +7,7 @@ #### Updates +* Warning messages for failure of unserialization or conversion of received message data are now suppressable. * Upgrades `reply()` to always return even when there is an evaluation error. This allows it to be used safely in a loop without exiting early, for example. * Removes deprecated and defunct `next_config()`. * Performance enhancements for `promises::as.promise()` methods. diff --git a/src/core.c b/src/core.c index d5f3ffc06..972cff115 100644 --- a/src/core.c +++ b/src/core.c @@ -290,7 +290,7 @@ SEXP rawToChar(const unsigned char *buf, const size_t sz) { int i, j; for (i = 0, j = -1; i < sz; i++) if (buf[i]) j = i; else break; if (sz - i > 1) { - nano_REprintf("data could not be converted to a character string\n"); + Rf_warningcall_immediate(R_NilValue, "data could not be converted to a character string"); out = Rf_allocVector(RAWSXP, sz); memcpy(NANO_DATAPTR(out), buf, sz); return out; @@ -445,7 +445,7 @@ SEXP nano_unserialize(unsigned char *buf, const size_t sz, SEXP hook) { } } - nano_REprintf("received data could not be unserialized\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be unserialized"); return nano_decode(buf, sz, 8, R_NilValue); resume: ; @@ -500,7 +500,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho case 3: size = 2 * sizeof(double); if (sz % size) { - nano_REprintf("received data could not be converted to complex\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be converted to complex"); data = Rf_allocVector(RAWSXP, sz); } else { data = Rf_allocVector(CPLXSXP, sz / size); @@ -509,7 +509,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho case 4: size = sizeof(double); if (sz % size) { - nano_REprintf("received data could not be converted to double\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be converted to double"); data = Rf_allocVector(RAWSXP, sz); } else { data = Rf_allocVector(REALSXP, sz / size); @@ -518,7 +518,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho case 5: size = sizeof(int); if (sz % size) { - nano_REprintf("received data could not be converted to integer\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be converted to integer"); data = Rf_allocVector(RAWSXP, sz); } else { data = Rf_allocVector(INTSXP, sz / size); @@ -527,7 +527,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho case 6: size = sizeof(int); if (sz % size) { - nano_REprintf("received data could not be converted to logical\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be converted to logical"); data = Rf_allocVector(RAWSXP, sz); } else { data = Rf_allocVector(LGLSXP, sz / size); @@ -536,7 +536,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho case 7: size = sizeof(double); if (sz % size) { - nano_REprintf("received data could not be converted to numeric\n"); + Rf_warningcall_immediate(R_NilValue, "received data could not be converted to numeric"); data = Rf_allocVector(RAWSXP, sz); } else { data = Rf_allocVector(REALSXP, sz / size); diff --git a/src/nanonext.h b/src/nanonext.h index 2b492704d..1045169b2 100644 --- a/src/nanonext.h +++ b/src/nanonext.h @@ -302,7 +302,6 @@ int nano_encodes(const SEXP); int nano_matcharg(const SEXP); int nano_matchargs(const SEXP); -void nano_REprintf(const char *); void pipe_cb_signal(nng_pipe, nng_pipe_ev, void *); SEXP rnng_advance_rng_state(void); diff --git a/src/thread.c b/src/thread.c index b42a3eccc..d66d45128 100644 --- a/src/thread.c +++ b/src/thread.c @@ -20,12 +20,6 @@ #define NANONEXT_IO #include "nanonext.h" -void nano_REprintf(const char *fmt) { - - if (write(STDERR_FILENO, fmt, strlen(fmt))) {} ; - -} - // messenger ------------------------------------------------------------------- // # nocov start diff --git a/src/tls.c b/src/tls.c index 4f4f98389..7c307d7d0 100644 --- a/src/tls.c +++ b/src/tls.c @@ -165,7 +165,7 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) { snprintf(issuer_name, clen, "CN=%s,O=Nanonext,C=JP", common); int xc, exit = 1; - if (interactive) nano_REprintf("Generating key + certificate [ ]"); + if (interactive) REprintf("Generating key + certificate [ ]"); mbedtls_x509_crt issuer_crt; mbedtls_pk_context loaded_issuer_key; mbedtls_pk_context *issuer_key = &loaded_issuer_key; @@ -191,18 +191,18 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) { mbedtls_mpi_init(&serial); #endif - if (interactive) nano_REprintf("\rGenerating key + certificate [. ]"); + if (interactive) REprintf("\rGenerating key + certificate [. ]"); if ((xc = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen(pers))) || (xc = mbedtls_pk_setup(&key, mbedtls_pk_info_from_type((mbedtls_pk_type_t) MBEDTLS_PK_RSA)))) goto exitlevel1; - if (interactive) nano_REprintf("\rGenerating key + certificate [.. ]"); + if (interactive) REprintf("\rGenerating key + certificate [.. ]"); if ((xc = mbedtls_rsa_gen_key(mbedtls_pk_rsa(key), mbedtls_ctr_drbg_random, &ctr_drbg, 4096, 65537))) goto exitlevel1; - if (interactive) nano_REprintf("\rGenerating key + certificate [... ]"); + if (interactive) REprintf("\rGenerating key + certificate [... ]"); if ((xc = mbedtls_pk_write_key_pem(&key, key_buf, 16000))) goto exitlevel1; @@ -256,7 +256,7 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) { SET_STRING_ELT(cstr, 0, Rf_mkChar((char *) &output_buf)); SET_STRING_ELT(cstr, 1, R_BlankString); - if (interactive) nano_REprintf("\rGenerating key + certificate [done]\n"); + if (interactive) REprintf("\rGenerating key + certificate [done]\n"); exit = 0; exitlevel1: diff --git a/tests/tests.R b/tests/tests.R index 4e707cecc..f683bbe1d 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -110,7 +110,7 @@ test_class("errorValue", msg$data) test_identical(call_aio(n), n) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "r", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = 1L, timeout = 500)) -test_true(is_nul_byte(call_aio_(rraio)$data)) +test_true(is_nul_byte(suppressWarnings(call_aio_(rraio)$data))) test_class("sendAio", sraio <- n$send_aio(as.raw(1L), mode = "ra", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "raw", timeout = 500)) test_type("raw", call_aio(rraio)$data) @@ -128,16 +128,16 @@ test_class("recvAio", rraio <- n1$recv_aio(mode = "i", timeout = 500)) test_type("integer", call_aio(rraio)$data) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "double", timeout = 500)) -test_type("raw", call_aio(rraio)$data) +test_type("raw", suppressWarnings(call_aio(rraio)$data)) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "int", timeout = 500)) -test_type("raw", call_aio(rraio)$data) +test_type("raw", suppressWarnings(call_aio(rraio)$data)) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "logical", timeout = 500)) -test_type("raw", collect_aio(rraio)) +test_type("raw", suppressWarnings(collect_aio(rraio))) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "numeric", timeout = 500)) -test_type("raw", rraio[]) +test_type("raw", suppressWarnings(rraio[])) test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500)) test_class("recvAio", rraio <- n1$recv_aio(mode = "complex", timeout = 500)) test_type("raw", suppressWarnings(collect_aio_(rraio))) @@ -405,7 +405,7 @@ haio <- ncurl_aio("https://i.i") test_class("errorValue", call_aio(haio)$data) test_print(haio$data) ncaio <- ncurl_aio("https://shikokuchuo.net/nanonext/reference/figures/logo.png") -if (call_aio(ncaio)$status == 200L) test_true(is.raw(ncaio$data)) +if (suppressWarnings(call_aio(ncaio)$status == 200L)) test_type("raw", ncaio$data) test_class("errorValue", ncurl_aio("http")$data) sess <- ncurl_session("https://postman-echo.com/post", method = "POST", headers = c(`Content-Type` = "text/plain"), data = "test", response = c("date", "Server"), timeout = 3000L) test_true(is_ncurl_session(sess) || is_error_value(sess)) @@ -468,14 +468,14 @@ is_nano(s) && { test_notnull(recv(s, mode = 9L, block = 100)) test_type("integer", send(s, 2L, block = 500)) test_class("recvAio", sr <- recv_aio(s, mode = "i", timeout = 500L, n = 8192L)) - test_notnull(call_aio(sr)[["data"]]) + test_notnull(suppressWarnings(call_aio(sr)[["data"]])) test_null(stop_aio(sr)) test_class("sendAio", ss <- send_aio(s, "async", timeout = 500L)) test_type("integer", ss[]) test_null(stop_aio(ss)) test_type("integer", send(s, 12.56, mode = "raw", block = 500L)) test_class("recvAio", sr <- recv_aio(s, mode = "double", timeout = 500L, cv = cv)) - test_notnull(call_aio_(sr)[["data"]]) + test_notnull(suppressWarnings(call_aio_(sr)[["data"]])) test_true(cv_value(cv) > 0L) test_type("character", opt(s, "ws:request-headers")) test_notnull(opt(s, "tcp-nodelay") <- FALSE)