I'm trying to set option ZMQ_CONFLATE to 1 (http://api.zeromq.org/master:zmq-setsockopt) for a ZMQ_SUB socket.
I didn't see a built-in function to do that, so I tried to add my own. Here's what I did:
- Added function to
R/zmq.R, following pattern of set.affinity:
set.conflate <- function(socket, option.value) {
.Call("set_conflate",socket, option.value, PACKAGE="rzmq")
}
-
Added set.conflate to export list in NAMESPACE file.
-
Added set_conflate function in src/interface.cpp, following same pattern as
set_affinity:
SEXP set_conflate(SEXP socket_, SEXP option_value_) {
zmq::socket_t* socket = reinterpret_cast<zmq::socket_t*>(checkExternalPointer(socket_,"zmq::socket_t*"));
if(!socket) { REprintf("bad socket object.\n");return R_NilValue; }
if(TYPEOF(option_value_)!=INTSXP) { REprintf("option value must be an int.\n");return R_NilValue; }
SEXP ans; PROTECT(ans = allocVector(LGLSXP,1)); LOGICAL(ans)[0] = 1;
uint64_t option_value(INTEGER(option_value_)[0]);
try {
socket->setsockopt(ZMQ_CONFLATE, &option_value, sizeof(uint64_t));
} catch(std::exception& e) {
REprintf("%s\n",e.what());
LOGICAL(ans)[0] = 0;
}
UNPROTECT(1);
return ans;
}
- Added a line to
src/interface.h in the extern "C" block:
SEXP set_conflate(SEXP socket_, SEXP option_value_);
-
Deleted src/rzmq.so from my prior installation.
-
Re-installed package from source, verified src/rzmq.so was re-built.
-
When I tried to use it, it definitely finds the function and tries, but it says the argument is invalid:
> library(rzmq)
> sock = init.socket(init.context(), "ZMQ_SUB")
> connect.socket(sock, "tcp://host:port")
> subscribe(sock, "")
> set.conflate(sock, 1L)
Invalid argument
[1] FALSE
Two questions:
- Why would it say
1L is an invalid argument? The docs say it's expecting an integer.
- Is there a better way to accomplish setting
ZMQ_CONFLATE to 1?
I'm trying to set option
ZMQ_CONFLATEto 1 (http://api.zeromq.org/master:zmq-setsockopt) for aZMQ_SUBsocket.I didn't see a built-in function to do that, so I tried to add my own. Here's what I did:
R/zmq.R, following pattern ofset.affinity:Added
set.conflateto export list inNAMESPACEfile.Added
set_conflatefunction insrc/interface.cpp, following same pattern asset_affinity:src/interface.hin theextern "C"block:SEXP set_conflate(SEXP socket_, SEXP option_value_);Deleted
src/rzmq.sofrom my prior installation.Re-installed package from source, verified
src/rzmq.sowas re-built.When I tried to use it, it definitely finds the function and tries, but it says the argument is invalid:
Two questions:
1Lis an invalid argument? The docs say it's expecting an integer.ZMQ_CONFLATEto 1?