示例#1
0
static void
s_agent_task (void *args, zctx_t *ctx, void *control)
{
    //  Create agent instance as we start this task
    agent_t *self = s_agent_new (ctx, control);
    if (!self)                  //  Interrupted
        return;

    //  We always poll all three sockets
    zmq_pollitem_t pollitems [] = {
        { self->control, 0, ZMQ_POLLIN, 0 },
        { self->router, 0, ZMQ_POLLIN, 0 },
        { self->data, 0, ZMQ_POLLIN, 0 }
    };
    while (!zctx_interrupted) {
        if (zmq_poll (pollitems, 3, -1) == -1)
            break;              //  Interrupted

        if (pollitems [0].revents & ZMQ_POLLIN)
            s_agent_handle_control (self);
        if (pollitems [1].revents & ZMQ_POLLIN)
            s_agent_handle_router (self);
        if (pollitems [2].revents & ZMQ_POLLIN)
            s_agent_handle_data (self);

        if (self->terminated)
            break;
    }
    //  Done, free all agent resources
    s_agent_destroy (&self);
}
示例#2
0
文件: zmonitor.c 项目: sirithink/czmq
static void
s_agent_task (void *args, zctx_t *ctx, void *pipe)
{
    char *endpoint = zstr_recv (pipe);
    assert (endpoint);

    agent_t *self = s_agent_new (ctx, pipe, endpoint);

    zpoller_t *poller = zpoller_new (self->pipe, self->socket, NULL);
    while (!zctx_interrupted) {
        //  Poll on API pipe and on monitor socket
        void *result = zpoller_wait (poller, -1);
        if (result == NULL)
            break; // Interrupted
        else
        if (result == self->pipe)
            s_api_command (self);
        else
        if (result == self->socket)
            s_socket_event (self);

        if (self->terminated)
            break;
    }
    zpoller_destroy (&poller);
    s_agent_destroy (&self);
}
示例#3
0
static void
s_agent_task (void *args, zctx_t *ctx, void *pipe)
{
    //  Create agent instance as we start this task
    agent_t *self = s_agent_new (ctx, pipe);
    if (!self)                  //  Interrupted
        return;

    //  We have three sockets, but poll third one only selectively
    zmq_pollitem_t pollitems [] = {
        { self->control, 0, ZMQ_POLLIN, 0 },
        { self->dealer, 0, ZMQ_POLLIN, 0 },
        { self->data, 0, ZMQ_POLLIN, 0 }
    };

    while (!zctx_interrupted) {
        int pollsize = self->state == connected? 3: 2;
        if (zmq_poll (pollitems, pollsize, -1) == -1)
            break;              //  Interrupted
        if (pollitems [0].revents & ZMQ_POLLIN)
            s_agent_handle_control (self);
        if (pollitems [1].revents & ZMQ_POLLIN)
            s_agent_handle_dealer (self);
        if (pollitems [2].revents & ZMQ_POLLIN)
            s_agent_handle_data (self);

        if (self->state == terminated
        ||  self->state == exception)
            break;
    }
    //  Done, free all agent resources
    s_agent_destroy (&self);
}
示例#4
0
void
drops_agent_main (void *args, zctx_t *ctx, void *pipe)
{
    //  Create agent instance to pass around
    s_agent_t *self = s_agent_new (ctx, pipe);
    if (!self)                  //  Interrupted
        return;
    zstr_send (self->pipe, "OK");

    //  These are the sockets we will monitor for activity
    zpoller_t *poller = zpoller_new (
        self->pipe, zyre_socket (self->zyre), NULL);

    while (!zpoller_terminated (poller)) {
        //  Check directory once a second; this is a pretty nasty way of
        //  doing it, but portable and simple. Later I'd like to use file
        //  system monitoring library and get events back over a socket.
        void *which = zpoller_wait (poller, 1000);
        if (which == self->pipe)
            s_recv_from_api (self);
        else
        if (which == zyre_socket (self->zyre))
            s_recv_from_zyre (self);
        
        if (self->terminated)
            break;
        
        s_check_directory (self);
    }
    zpoller_destroy (&poller);
    s_agent_destroy (&self);
}
示例#5
0
static void
s_agent_task (void *args, zctx_t *ctx, void *pipe)
{
    //  Create agent instance as we start this task
    agent_t *self = s_agent_new (ctx, pipe);
    if (!self)                  //  Interrupted
        return;
        
    zpoller_t *poller = zpoller_new (self->pipe, self->handler, NULL);
    while (!zpoller_terminated (poller) && !self->terminated) {
        void *which = zpoller_wait (poller, -1);
        if (which == self->pipe)
            s_agent_handle_pipe (self);
        else
        if (which == self->handler)
            s_agent_authenticate (self);
    }
    //  Done, free all agent resources
    zpoller_destroy (&poller);
    s_agent_destroy (&self);
}