| 1 |
#include "R_zmq.h" |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
SEXP R_zmq_ctx_new(void){ |
| 8 |
SEXP R_context = R_NilValue; |
| 9 |
void *C_context = zmq_ctx_new(); |
| 10 |
|
| 11 |
if(C_context != NULL){ |
| 12 |
PROTECT(R_context = R_MakeExternalPtr(C_context, R_NilValue, R_NilValue)); |
| 13 |
|
| 14 |
UNPROTECT(1); |
| 15 |
} else{ |
| 16 |
Rprintf("R_zmq_ctx_new: R_context is not available.\n"); |
| 17 |
} |
| 18 |
return(R_context); |
| 19 |
} |
| 20 |
|
| 21 |
SEXP R_zmq_ctx_destroy(SEXP R_context){ |
| 22 |
int C_ret = -1, C_errno; |
| 23 |
void *C_context = R_ExternalPtrAddr(R_context); |
| 24 |
|
| 25 |
if(C_context == NULL){ |
| 26 |
return(R_NilValue); |
| 27 |
} |
| 28 |
|
| 29 |
C_ret = zmq_ctx_destroy(C_context); |
| 30 |
if(C_ret == -1){ |
| 31 |
C_errno = zmq_errno(); |
| 32 |
Rprintf("R_zmq_ctx_destroy errno: %d strerror: %s\n", |
| 33 |
C_errno, zmq_strerror(C_errno)); |
| 34 |
} |
| 35 |
return(AsInt(C_ret)); |
| 36 |
} |