[zeromq-dev] Problems with 2.0.6 poll using C++ api

Matthew Giedt mgiedt at gmail.com
Thu Mar 18 23:53:49 CET 2010


Here's the application that I'm using to test:

int main( int argc, char *argv[] )
{
    int signum = 0;
    zmq::message_t msg;
    zmq::socket_t* sock1;
    zmq::socket_t* sock2;
    zmq::context_t ctx ( 1, 1, 0 );

    sock1 = new zmq::socket_t( ctx, ZMQ_SUB );
    sock1->connect( "tcp://127.0.0.1:5550" );
    sock1->setsockopt( ZMQ_SUBSCRIBE, "", 0 );

    sock2 = new zmq::socket_t( ctx, ZMQ_SUB );
    sock2->connect( "tcp://127.0.0.1:5551" );
    sock2->setsockopt( ZMQ_SUBSCRIBE, "", 0 );

    zmq::pollitem_t items [ 2 ];
    items[ 0 ].socket = sock1;
    items[ 0 ].events = ZMQ_POLLIN;
    items[ 1 ].socket = sock2;
    items[ 1 ].events = ZMQ_POLLIN;

    while( 1 )
    {
        sock1->recv( &msg );
        cout << " sock1 recv: " << msg.data() << endl;

        sock2->recv( &msg );
        cout << " sock2 recv: " << msg.data() << endl;

        cout << "poll..." << endl;
        signum = zmq::poll( items, 2 );

        printf( " signum = %i\n", signum );

        if( items[ 0 ].revents == ZMQ_POLLIN )
        {
            cout << "received sock1 event!!!" << endl;
        }

        if( items[ 1 ].revents == ZMQ_POLLIN )
        {
            cout << "received sock2 event!!!" << endl;
        }
    }
    return 0;
}

This produces:

 sock1 recv: 0xfce9e8
 sock2 recv: 0xfcece8
poll...
terminate called after throwing and instance of 'zmq::error_t'
  what(): Bad address
Aborted

I've included the gdb output below -- it's thinking that the two sockets
were created from different threads?

(gdb) s
zmq::poll (items_=0x7fffffffe1f0, nitems_=2, timeout_=-1) at
/usr/local/include/zmq.hpp:53
53            int rc = zmq_poll (items_, nitems_, timeout_);
(gdb) s
zmq_poll (items_=0x7fffffffe1f0, nitems_=2, timeout_=-1) at zmq.cpp:328
328    {
(gdb) n
335        pollfd *pollfds = (pollfd*) malloc (nitems_ * sizeof (pollfd));
(gdb)
336        zmq_assert (pollfds);
(gdb)
335        pollfd *pollfds = (pollfd*) malloc (nitems_ * sizeof (pollfd));
(gdb)
336        zmq_assert (pollfds);
(gdb)
342        for (int i = 0; i != nitems_; i++) {
(gdb)
336        zmq_assert (pollfds);
(gdb)
345            if (items_ [i].socket) {
(gdb)
350                if (app_thread) {
(gdb)
358                    app_thread = s->get_thread ();
(gdb)
342        for (int i = 0; i != nitems_; i++) {
(gdb)
360                nsockets++;
(gdb)
342        for (int i = 0; i != nitems_; i++) {
(gdb)
345            if (items_ [i].socket) {
(gdb)
350                if (app_thread) {
(gdb)
351                    if (app_thread != s->get_thread ()) {
(gdb)
352                        free (pollfds);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100318/184f459f/attachment.htm>


More information about the zeromq-dev mailing list