Example #1
0
static void
have_message_confirmation (client_t *self)
{
    mlm_proto_set_status_code (self->message, MLM_PROTO_NOT_IMPLEMENTED);
    engine_set_exception (self, exception_event);
    zsys_warning ("message confirmations are not implemented");
}
static void
connect_to_server_endpoint (client_t *self)
{
    if (zsock_connect (self->dealer, "%s", self->args->endpoint)) {
        engine_set_exception (self, bad_endpoint_event);
        zsys_warning ("could not connect to %s", self->args->endpoint);
    }
}
Example #3
0
static void
check_timeouts (client_t *self)
{
    self->timeouts++;
    if (self->timeouts == MAX_TIMEOUTS) {
        engine_set_exception(self, destructor_event);
    }
}
static void
check_if_connection_is_dead (client_t *self)
{
    //  We send at most 3 heartbeats before expiring the server
    if (++self->retries >= 3) {
        engine_set_timeout (self, 0);
        engine_set_connected (self, false);
        engine_set_exception (self, exception_event);
    }
}
Example #5
0
static void
store_stream_writer (client_t *self)
{
    //  A writer talks to a single stream
    self->writer = s_stream_require (self, mlm_proto_stream (self->message));
    if (self->writer)
        mlm_proto_set_status_code (self->message, MLM_PROTO_SUCCESS);
    else {
        engine_set_exception (self, exception_event);
        zsys_warning ("writer trying to talk to multiple streams");
    }
}
Example #6
0
static void
collect_data_to_send (client_t *self)
{
    zsys_info ("read %d bytes", (int) zpipes_msg_size (self->request));
    //  Do we have enough data to satisfy the read request?
    size_t required = zpipes_msg_size (self->request);
    
    //  If pipe was closed, we'll do a short read with as much
    //  data as we have pending
    if (required > self->pending && self->pipe == NULL)
        required = self->pending;

    if (self->pipe == NULL && self->pending == 0)
        engine_set_exception (self, pipe_shut_event);
    else
    if (self->pending >= required) {
        //  Create a bucket chunk with the required max size
        zchunk_t *bucket = zchunk_new (NULL, required);

        //  Now fill the bucket with chunks from our queue
        while (zchunk_size (bucket) < required) {
            //  Get next chunk and consume as much of it as possible
            zchunk_t *chunk = (zchunk_t *) zlist_pop (self->queue);
            assert (chunk);
            zchunk_consume (bucket, chunk);
            //  If chunk is exhausted, destroy it
            if (zchunk_exhausted (chunk))
                zchunk_destroy (&chunk);
            else {
                //  Push chunk back for next time
                zlist_push (self->queue, chunk);
                assert (zchunk_size (bucket) == required);
            }
        }
        zpipes_msg_set_chunk (self->reply, &bucket);
        self->pending -= required;
    }
    else
        engine_set_exception (self, not_enough_data_event);
}
Example #7
0
static void
write_message_to_xrap_handler (client_t *self)
{
    service_t *service = self->server->xrap;
    assert (service);
    ztrie_t *routes = NULL;

    zmsg_t *content = zmsg_dup (xrap_traffic_content (self->message));
    xrap_msg_t *msg = xrap_msg_decode (&content);
    char *route;
    int method = xrap_msg_id (msg);
    if (method == XRAP_MSG_GET) {
        route = (char *) xrap_msg_resource (msg);
        routes = service->get_routes;
    }
    else
    if (method == XRAP_MSG_POST) {
        route = (char *) xrap_msg_parent (msg);
        routes = service->post_routes;
    }
    else
    if (method == XRAP_MSG_PUT) {
        route = (char *) xrap_msg_resource (msg);
        routes = service->put_routes;
    }
    else
    if (method == XRAP_MSG_DELETE) {
        route = (char *) xrap_msg_resource (msg);
        routes = service->delete_routes;
    }
    else {
        xrap_traffic_set_status_code (self->message, XRAP_TRAFFIC_BAD_REQUEST);
        engine_set_exception (self, fail_event);
    }

    client_t *target;
    if (routes && ztrie_matches (routes, route)) {
        target = (client_t *) ztrie_hit_data (routes);
        //  Save message for broker
        target->msg = zmsg_dup (xrap_traffic_content (self->message));
        //  Trigger dispatch event
        target->callee = self;
        engine_send_event (target, xrap_message_event);
    }
    else {
        xrap_traffic_set_status_code (self->message, XRAP_TRAFFIC_NOT_FOUND);
        self->rc = -1;
    }

    //  Clean up
    xrap_msg_destroy (&msg);
}
Example #8
0
static void
connect_to_server (client_t *self)
{
    if (zsock_connect(self->dealer, "%s", self->args->endpoint)) {
        engine_set_exception(self, connect_error_event);
        zsys_warning("could not connect to %s", self->args->endpoint);
        zsock_send(self->cmdpipe, "si", "FAILURE", 0);
    }
    else {
        zsys_debug("connected to %s", self->args->endpoint);
        zsock_send(self->cmdpipe, "si", "SUCCESS", 0);
    }
}
Example #9
0
static void
cancel_stream_reader (client_t *self)
{
    //  Cancel stream subscription
    stream_t *stream = s_stream_require (self, mlm_proto_stream (self->message));
    if (stream) {
        zsock_send (stream->actor, "sp", "CANCEL", self);
        stream = (stream_t *) zlistx_detach (self->readers, NULL);
    }
    else {
        engine_set_exception (self, exception_event);
        zsys_warning ("stream does not exist");
    }
}
Example #10
0
static void
store_stream_reader (client_t *self)
{
    stream_t *stream = s_stream_require (self, mlm_proto_stream (self->message));
    if (stream) {
        zlistx_add_end (self->readers, stream);
        zsock_send (stream->actor, "sps", "COMPILE", self, mlm_proto_pattern (self->message));
        mlm_proto_set_status_code (self->message, MLM_PROTO_SUCCESS);
    }
    else {
        engine_set_exception (self, exception_event);
        zsys_warning ("reader trying to talk to multiple streams");
    }
}
Example #11
0
static void
write_message_to_stream (client_t *self)
{
    if (self->writer) {
        mlm_msg_t *msg = mlm_msg_new (
            self->address,
            self->writer->name,
            mlm_proto_subject (self->message),
            NULL,
            mlm_proto_timeout (self->message),
            mlm_proto_get_content (self->message));
        zsock_bsend (self->writer->msgpipe, "pp", self, msg);
    }
    else {
        engine_set_exception (self, exception_event);
        zsys_warning ("client attempted to send without writer");
    }
}
Example #12
0
static void
write_message_to_stream (client_t *self)
{
    if (self->writer) {
        mlm_msg_t *msg = mlm_msg_new (
            self->address,
            self->writer->name,
            mlm_proto_subject (self->message),
            NULL,
            mlm_proto_timeout (self->message),
            mlm_proto_get_content (self->message));
        zsock_bsend (self->writer->msgpipe, "pp", self, msg);
    }
    else {
        //  TODO: we can't properly reply to a STREAM_SEND
        mlm_proto_set_status_code (self->message, MLM_PROTO_COMMAND_INVALID);
        engine_set_exception (self, exception_event);
        zsys_warning ("client attempted to send without writer");
    }
}
Example #13
0
static void
have_message_confirmation (client_t *self)
{
    engine_set_exception (self, exception_event);
    zsys_warning ("message confirmations are not implemented");
}