@@ -174,22 +174,9 @@ static SEXP mk_error_haio(const int xc, SEXP env) {
174174
175175static SEXP mk_error_data (const int xc ) {
176176
177- const char * names [] = {"data" , "" };
177+ const char * names [] = {xc < 0 ? "result" : "data" , "" };
178178 SEXP out = PROTECT (Rf_mkNamed (VECSXP , names ));
179- SEXP err = Rf_ScalarInteger (xc );
180- SET_ATTRIB (err , nano_error );
181- SET_OBJECT (err , 1 );
182- SET_VECTOR_ELT (out , 0 , err );
183- UNPROTECT (1 );
184- return out ;
185-
186- }
187-
188- static SEXP mk_error_result (const int xc ) {
189-
190- const char * names [] = {"result" , "" };
191- SEXP out = PROTECT (Rf_mkNamed (VECSXP , names ));
192- SEXP err = Rf_ScalarInteger (xc );
179+ SEXP err = Rf_ScalarInteger (abs (xc ));
193180 SET_ATTRIB (err , nano_error );
194181 SET_OBJECT (err , 1 );
195182 SET_VECTOR_ELT (out , 0 , err );
@@ -428,13 +415,13 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
428415
429416 if ((xc = nng_msg_alloc (& msg , 0 ))) {
430417 R_Free (saio );
431- return mk_error_result ( xc );
418+ return mk_error_data ( - xc );
432419 }
433420 if ((xc = nng_msg_append (msg , dp , xlen )) ||
434421 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
435422 nng_msg_free (msg );
436423 R_Free (saio );
437- return mk_error_result ( xc );
424+ return mk_error_data ( - xc );
438425 }
439426
440427 nng_aio_set_msg (saio -> aio , msg );
@@ -460,14 +447,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
460447
461448 if ((xc = nng_msg_alloc (& msg , 0 ))) {
462449 R_Free (saio );
463- return mk_error_result ( xc );
450+ return mk_error_data ( - xc );
464451 }
465452
466453 if ((xc = nng_msg_append (msg , dp , xlen )) ||
467454 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
468455 nng_msg_free (msg );
469456 R_Free (saio );
470- return mk_error_result ( xc );
457+ return mk_error_data ( - xc );
471458 }
472459
473460 nng_aio_set_msg (saio -> aio , msg );
@@ -497,14 +484,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
497484 if ((xc = nng_aio_alloc (& iaio -> aio , iaio_complete , iaio ))) {
498485 R_Free (iov );
499486 R_Free (iaio );
500- return mk_error_result ( xc );
487+ return mk_error_data ( - xc );
501488 }
502489
503490 if ((xc = nng_aio_set_iov (iaio -> aio , 1u , iov ))) {
504491 nng_aio_free (iaio -> aio );
505492 R_Free (iov );
506493 R_Free (iaio );
507- return mk_error_result ( xc );
494+ return mk_error_data ( - xc );
508495 }
509496
510497 nng_aio_set_timeout (iaio -> aio , dur );
0 commit comments