[zeromq-dev] zmq_poll() and ZMQ_REP/ZMQ_REQ sockets
Kamil Shakirov
kamils80 at gmail.com
Tue Jan 12 06:44:14 CET 2010
Hi Martin,
I am getting crashes when trying to use zmq_poll() on ZMQ_REP and
ZMQ_REQ at the same time. It is working if a poll item passed with
ZMQ_REP socket (ZMQ_POLLIN and ZMQ_POLLOUT flags set). It crashes when
passing ZMQ_REQ socket with ZMQ_POLLIN flag set. I attached a simple
test app that reproduces the error.
Has a ZMQ socket to be bound/connected before calling zmq_poll()?
A simple test app that uses ZMQ_REP and ZMQ_REQ sockets (tested with the zeromq HEAD):
static void* g_create_socket(void *zmq, zmq_pollitem_t *poll_item, int type)
{
void *sock = zmq_socket(zmq, type);
if(!sock) {
ERROR_EXIT("zmq_socket()");
}
poll_item->socket = sock;
poll_item->fd = -1;
poll_item->events = ZMQ_POLLIN | ZMQ_POLLOUT;
poll_item->revents = 0;
return sock;
}
static void g_destroy_socket(void *socket)
{
int rc = zmq_close(socket);
if(rc != 0) {
ERROR_EXIT("zmq_close()");
}
}
int main()
{
void *zmq, *req_sock, *rep_sock;
zmq_pollitem_t poll_items[2];
int rc;
zmq = zmq_init(1, 1, ZMQ_POLL);
if(!zmq) {
ERROR_EXIT("zmq_init()");
}
req_sock = g_create_socket(zmq, &poll_items[0], ZMQ_REQ);
rep_sock = g_create_socket(zmq, &poll_items[1], ZMQ_REP);
rc = zmq_bind(req_sock, "tcp://eth0:5555");
if(rc != 0) {
ERROR_EXIT("zmq_bind()");
}
rc = zmq_bind(rep_sock, "tcp://eth0:6666");
if(rc != 0) {
ERROR_EXIT("zmq_bind()");
}
rc = zmq_poll(poll_items, sizeof(poll_items)/sizeof(poll_items[0]), -1);
if(rc < 0) {
ERROR_EXIT("zmq_poll()");
}
g_destroy_socket(rep_sock);
g_destroy_socket(req_sock);
rc = zmq_term(zmq);
if(rc != 0) {
ERROR_EXIT("zmq_term()");
}
return 0;
}
Here is gdb output (tested on linux-x86 (ubuntu 9.10)):
kamil at devbox ~/temp/zmq % gdb ./test
GNU gdb (GDB) 7.0-ubuntu
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/kamil/temp/zmq/test...done.
(gdb) run
Starting program: /home/kamil/temp/zmq/test
[Thread debugging using libthread_db enabled]
[New Thread 0xb7fe7b70 (LWP 4945)]
Program received signal SIGSEGV, Segmentation fault.
0x0020f5b9 in zmq::reader_t::check_read (this=0x0) at pipe.cpp:52
52 if (pipe->check_read ())
Current language: auto
The current source language is "auto; currently c++".
(gdb) bt
#0 0x0020f5b9 in zmq::reader_t::check_read (this=0x0) at pipe.cpp:52
#1 0x0021586f in zmq::req_t::xhas_in (this=0x804b430) at req.cpp:200
#2 0x0021a8be in zmq::socket_base_t::has_in (this=0x804b430) at socket_base.cpp:434
#3 0x00222824 in zmq_poll (items_=0xbffff838, nitems_=2, timeout_=-1) at zmq.cpp:374
#4 0x0804893b in main () at test.c:62
(gdb)
--
--wbr.
More information about the zeromq-dev
mailing list