Don't know if it's the same issue, but I just spent a few hours debugging a memory error on zmq::msg_t::init().
It turned out that a recent commit to libzmq changed the size of the zmq_msg_t and zmq::msg_t structures. They're still the same---that's fine---but my binding, zmqpp, hadn't been fully rebuilt and was still trying to use the old size. Try rebuilding your binding completely. On Thu, Jan 16, 2014 at 3:18 PM, Goswin von Brederlow <[email protected]>wrote: > 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. > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
