[zeromq-dev] Odd failure (EFAULT) on zmq_msg_close()
Goswin von Brederlow
goswin-v-b at web.de
Thu Jan 16 21:18:34 CET 2014
Hi,
I'm playing with the ocaml bindings for zmq (4.0.3) and STREAM sockets
and I'm getting an odd failure.
On STREAM sockets to close the connection to one pear one has to send
a 0 message with ZMQ_SNDMORE. So on the ocaml side I call:
Printf.fprintf stderr "Sending zero\n%1";
ZMQ.Socket.send ~opt:ZMQ.Socket.S_more sock "";
This eventually calls:
CAMLprim value caml_zmq_send(value socket, value string, value snd_options) {
CAMLparam3 (socket, string, snd_options);
int caml_snd_option = Int_val(snd_options);
if (!is_caml_snd_option_valid(caml_snd_option))
caml_failwith("Invalid send option.");
void *sock = CAML_ZMQ_Socket_val(socket);
zmq_msg_t msg;
int length = caml_string_length(string);
fprintf(stderr, "caml_zmq_send(): length = %d\n", length);
int option = native_snd_option_for_caml_snd_option[caml_snd_option];
int result = zmq_msg_init_size(&msg, length);
caml_zmq_raise_if (result == -1);
/* Doesn't copy '\0' */
memcpy ((void *) zmq_msg_data (&msg), String_val(string), length);
caml_release_runtime_system();
result = zmq_msg_send(&msg, sock, option);
fprintf(stderr, "caml_zmq_send(): sending: result = %d\n", result);
caml_acquire_runtime_system();
int close_result = zmq_msg_close (&msg);
fprintf(stderr, "caml_zmq_send(): closing: close_result = %d\n", close_result);
caml_zmq_raise_if (result == -1);
caml_zmq_raise_if (close_result == -1);
CAMLreturn(Val_unit);
}
This produces the following output:
Sending zero
caml_zmq_send(): length = 0
caml_zmq_send(): sending: result = 0
caml_zmq_send(): closing: close_result = -1
Fatal error: exception ZMQ.ZMQ_exception(1, "Bad address")
>From what I can tell the code is fine and everything works for non-0
messages. And a quick glance at the source for libzmq didn't show me
how a length == 0 would cause a EFAULT.
What am I missing?
MfG
Goswin
PS: Skipping the msg stuff and sending zmq_send(sock, NULL, 0, option)
directly makes it work. But I would still like to understand why
zmq_msg_close() fails.
More information about the zeromq-dev
mailing list