[zeromq-dev] zmq_poll returns -1 ( Context has been shut down) when polling 2 sockets

Arnaud Loonstra arnaud at sphaero.org
Tue Jul 4 22:52:07 CEST 2023


I'm not sure but skimming your code you are mixing czmq sockets and zmq 
poll method. If you want to use the zmp_poll method you can use 
zsock_resolve on the czmq sockets

//  Probe the supplied reference. If it looks like a zsock_t instance, 
return
//  the underlying libzmq socket handle; else if it looks like a file
//  descriptor, return NULL; else if it looks like a libzmq socket handle,
//  return the supplied value. Takes a polymorphic socket reference.
CZMQ_EXPORT void *
     zsock_resolve (void *self);

Otherwise use the zpoller czmq class instead of zmq_poll

Rg,

Arnaud

On 04-07-2023 11:26, Chandrasekhar Nunna wrote:
> hi all,
> i am using zactor and in the call back i receive a pipe socket.
> i create a router socket and polling this sockets for messages.
> it is not working and giving -1 result as return value of zmq_poll;
> what could be the problem?
> void
> echo_actor (zsock_t *pipe, void *args)
> {
>      // need to implement...?
>      printf("thread id : %lu", GetCurrentThreadId());
>      server_t* self = server_new(pipe);
>      zmq_pollitem_t items[] =
>      {
>          { self->pipe, 0, ZMQ_POLLIN, 0 },
>          { self->router, 0, ZMQ_POLLIN, 0 }
>      };
>      self->monitor_at = zclock_time() + self->monitor;
>      while (!self->stopped && !zctx_interrupted)
>      {
>          //  Calculate tickless timer, up to interval seconds
>          uint64_t tickless = zclock_time() + self->monitor;
>          uint64_t diff = (tickless - zclock_time()) * ZMQ_POLL_MSEC;
>          //  Poll until at most next timer event
>          int rc = zmq_poll(items, 2, diff );
>          if (rc == -1)
>          {
>              break;              //  Context has been shut down
>          }
> 
>          //  Process incoming message from either socket
>          if (items[0].revents & ZMQ_POLLIN)
>              server_control_message(self);
> 
>          if (items[1].revents & ZMQ_POLLIN)
>              server_client_message(self);
> 
>          //  If clock went past timeout, then monitor server
>          if (zclock_time() >= self->monitor_at)
>          {
>              printf("clock went past timeout, need to monitor the server");
>          }
>      }
>      server_destroy(&self);
> }
> 
> int main()
> {
>      zactor_t *actor = zactor_new (echo_actor, "Hello, World");
>      assert (actor);
>      zstr_sendx (actor, "ECHO", "This is a string", NULL);
>      char *string = zstr_recv (actor);
>      fprintf(stdout,"%s\n",string);
>      assert (streq (string, "This is a string"));
>      free (string);
>      zactor_destroy (&actor);
> }
> 
> 
> 
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev


More information about the zeromq-dev mailing list