Skip to content

Commit 6f4e78d

Browse files
committed
critical correction + efficiency updates
1 parent 2dfc386 commit 6f4e78d

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/aio.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,17 +1072,14 @@ SEXP rnng_ncurl_session(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP
10721072
nng_http_conn *conn;
10731073
conn = nng_aio_get_output(haio->aio, 0);
10741074

1075-
PROTECT(sess = R_MakeExternalPtr(conn, nano_StatusSymbol, R_NilValue));
1075+
PROTECT(sess = R_MakeExternalPtr(conn, nano_StatusSymbol, (response != R_NilValue && TYPEOF(response) == STRSXP) ? response : R_NilValue));
10761076
R_RegisterCFinalizerEx(sess, session_finalizer, TRUE);
10771077
Rf_classgets(sess, Rf_mkString("ncurlSession"));
10781078

10791079
PROTECT(aio = R_MakeExternalPtr(haio, nano_AioSymbol, R_NilValue));
10801080
R_RegisterCFinalizerEx(aio, haio_finalizer, TRUE);
10811081
Rf_setAttrib(sess, nano_AioSymbol, aio);
10821082

1083-
if (response != R_NilValue && TYPEOF(response) == STRSXP)
1084-
Rf_setAttrib(sess, nano_ResponseSymbol, response);
1085-
10861083
UNPROTECT(2);
10871084
return sess;
10881085

@@ -1131,7 +1128,7 @@ SEXP rnng_ncurl_transact(SEXP session) {
11311128
const uint16_t code = nng_http_res_get_status(handle->res);
11321129
SET_VECTOR_ELT(out, 0, Rf_ScalarInteger(code));
11331130

1134-
response = Rf_getAttrib(session, nano_ResponseSymbol);
1131+
response = R_ExternalPtrProtected(session);
11351132
if (response != R_NilValue) {
11361133
const R_xlen_t rlen = XLENGTH(response);
11371134
rvec = Rf_allocVector(VECSXP, rlen);
@@ -1170,9 +1167,9 @@ SEXP rnng_ncurl_session_close(SEXP session) {
11701167
nng_http_conn *sp = (nng_http_conn *) R_ExternalPtrAddr(session);
11711168
nng_http_conn_close(sp);
11721169
R_SetExternalPtrTag(session, R_NilValue);
1170+
R_SetExternalPtrProtected(session, R_NilValue);
11731171
R_ClearExternalPtr(session);
11741172
Rf_setAttrib(session, nano_AioSymbol, R_NilValue);
1175-
Rf_setAttrib(session, nano_ResponseSymbol, R_NilValue);
11761173

11771174
return nano_success;
11781175

@@ -1287,15 +1284,16 @@ SEXP rnng_set_promise_context(SEXP x, SEXP ctx) {
12871284
if (R_ExternalPtrTag(aio) != nano_AioSymbol)
12881285
return x;
12891286

1287+
nano_aio *raio = (nano_aio *) R_ExternalPtrAddr(aio);
1288+
if (raio->type != REQAIO)
1289+
return x;
1290+
12901291
if (eln2 == eln2dummy) {
12911292
Rf_eval(nano_onLoad, R_GlobalEnv);
12921293
eln2 = (void (*)(void (*)(void *), void *, double, int)) R_GetCCallable("later", "execLaterNative2");
12931294
}
1294-
nano_aio *raio = (nano_aio *) R_ExternalPtrAddr(aio);
1295-
if (raio->type == REQAIO) {
1296-
nano_aio *saio = (nano_aio *) raio->next;
1297-
saio->data = nano_PreserveObject(ctx);
1298-
}
1295+
nano_aio *saio = (nano_aio *) raio->next;
1296+
saio->data = nano_PreserveObject(ctx);
12991297

13001298
return x;
13011299

src/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ SEXP rnng_protocol_open(SEXP protocol, SEXP raw) {
134134

135135
NANO_CLASS2(socket, "nanoSocket", "nano");
136136
Rf_setAttrib(socket, nano_IdSymbol, Rf_ScalarInteger(nng_socket_id(*sock)));
137-
Rf_setAttrib(socket, nano_StateSymbol, Rf_mkString("opened"));
138137
Rf_setAttrib(socket, nano_ProtocolSymbol, Rf_mkString(pname));
138+
Rf_setAttrib(socket, nano_StateSymbol, Rf_mkString("opened"));
139139

140140
UNPROTECT(1);
141141
return socket;

0 commit comments

Comments
 (0)