Skip to content

Commit 2b9480a

Browse files
committed
compact code
1 parent 39e7bbb commit 2b9480a

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.9.2.9038
4+
Version: 0.9.2.9039
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols, a
77
cross-platform standard for messaging and communications. Serves as a

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nanonext 0.9.2.9038 (development)
1+
# nanonext 0.9.2.9039 (development)
22

33
#### New Features
44

src/aio.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
825825

826826
if ((xc = nng_msg_alloc(&msg, 0))) {
827827
NANO_FREE(buf);
828-
R_Free(saio);
829-
return mk_error_data(-xc);
828+
goto exitlevel1;
830829
}
830+
831831
if ((xc = nng_msg_append(msg, buf.buf, buf.cur)) ||
832832
(xc = nng_aio_alloc(&saio->aio, saio_complete, saio))) {
833833
nng_msg_free(msg);
834834
NANO_FREE(buf);
835-
R_Free(saio);
836-
return mk_error_data(-xc);
835+
goto exitlevel1;
837836
}
838837

839838
nng_aio_set_msg(saio->aio, msg);
@@ -854,16 +853,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
854853

855854
if ((xc = nng_msg_alloc(&msg, 0))) {
856855
NANO_FREE(buf);
857-
R_Free(saio);
858-
return mk_error_data(-xc);
856+
goto exitlevel1;
859857
}
860858

861859
if ((xc = nng_msg_append(msg, buf.buf, buf.cur)) ||
862860
(xc = nng_aio_alloc(&saio->aio, saio_complete, saio))) {
863861
nng_msg_free(msg);
864862
NANO_FREE(buf);
865-
R_Free(saio);
866-
return mk_error_data(-xc);
863+
goto exitlevel1;
867864
}
868865

869866
nng_aio_set_msg(saio->aio, msg);
@@ -890,15 +887,13 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
890887

891888
if ((xc = nng_aio_alloc(&saio->aio, isaio_complete, saio))) {
892889
R_Free(saio->data);
893-
R_Free(saio);
894-
return mk_error_data(-xc);
890+
goto exitlevel1;
895891
}
896892

897893
if ((xc = nng_aio_set_iov(saio->aio, 1u, &iov))) {
898894
nng_aio_free(saio->aio);
899895
R_Free(saio->data);
900-
R_Free(saio);
901-
return mk_error_data(-xc);
896+
goto exitlevel1;
902897
}
903898

904899
nng_aio_set_timeout(saio->aio, dur);
@@ -926,6 +921,10 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
926921
UNPROTECT(3);
927922
return env;
928923

924+
exitlevel1:
925+
R_Free(saio);
926+
return mk_error_data(-xc);
927+
929928
}
930929

931930
SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
@@ -942,10 +941,8 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
942941
raio->type = RECVAIO;
943942
raio->mode = nano_matcharg(mode);
944943

945-
if ((xc = nng_aio_alloc(&raio->aio, raio_complete, raio))) {
946-
R_Free(raio);
947-
return mk_error_data(xc);
948-
}
944+
if ((xc = nng_aio_alloc(&raio->aio, raio_complete, raio)))
945+
goto exitlevel1;
949946

950947
nng_aio_set_timeout(raio->aio, dur);
951948
nng_recv_aio(*sock, raio->aio);
@@ -959,10 +956,8 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
959956
raio->type = RECVAIO;
960957
raio->mode = nano_matcharg(mode);
961958

962-
if ((xc = nng_aio_alloc(&raio->aio, raio_complete, raio))) {
963-
R_Free(raio);
964-
return mk_error_data(xc);
965-
}
959+
if ((xc = nng_aio_alloc(&raio->aio, raio_complete, raio)))
960+
goto exitlevel1;
966961

967962
nng_aio_set_timeout(raio->aio, dur);
968963
nng_ctx_recv(*ctxp, raio->aio);
@@ -982,18 +977,11 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
982977
iov.iov_len = xlen;
983978
iov.iov_buf = raio->data;
984979

985-
if ((xc = nng_aio_alloc(&raio->aio, iraio_complete, raio))) {
986-
R_Free(raio->data);
987-
R_Free(raio);
988-
return mk_error_data(xc);
989-
}
980+
if ((xc = nng_aio_alloc(&raio->aio, iraio_complete, raio)))
981+
goto exitlevel2;
990982

991-
if ((xc = nng_aio_set_iov(raio->aio, 1u, &iov))) {
992-
nng_aio_free(raio->aio);
993-
R_Free(raio->data);
994-
R_Free(raio);
995-
return mk_error_data(xc);
996-
}
983+
if ((xc = nng_aio_set_iov(raio->aio, 1u, &iov)))
984+
goto exitlevel3;
997985

998986
nng_aio_set_timeout(raio->aio, dur);
999987
nng_stream_recv(sp, raio->aio);
@@ -1021,6 +1009,14 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
10211009
UNPROTECT(3);
10221010
return env;
10231011

1012+
exitlevel3:
1013+
nng_aio_free(raio->aio);
1014+
exitlevel2:
1015+
R_Free(raio->data);
1016+
exitlevel1:
1017+
R_Free(raio);
1018+
return mk_error_data(xc);
1019+
10241020
}
10251021

10261022
// ncurl aio -------------------------------------------------------------------

src/nanonext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ extern SEXP nano_StreamSymbol;
204204
extern SEXP nano_TextframesSymbol;
205205
extern SEXP nano_TlsSymbol;
206206
extern SEXP nano_UrlSymbol;
207-
extern SEXP nano_unresolved;
208207

209208
extern SEXP nano_addRedirect;
210209
extern SEXP nano_aioFormals;
@@ -216,6 +215,7 @@ extern SEXP nano_ncurlSession;
216215
extern SEXP nano_recvAio;
217216
extern SEXP nano_sendAio;
218217
extern SEXP nano_success;
218+
extern SEXP nano_unresolved;
219219

220220
extern SEXP rnng_aio_call(SEXP);
221221
extern SEXP rnng_aio_get_msg(SEXP);

0 commit comments

Comments
 (0)