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 { mlm_proto_set_status_code (self->message, MLM_PROTO_INTERNAL_ERROR); engine_set_exception (self, exception_event); zsys_warning ("writer trying to talk to multiple streams"); } }
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 { mlm_proto_set_status_code (self->message, MLM_PROTO_INTERNAL_ERROR); engine_set_exception (self, exception_event); zsys_warning ("reader trying to talk to multiple streams"); } }
static void deregister_the_client (client_t *self) { // If the client never sent CONNECTION_OPEN then self->address was // never set, so avoid trying to dereference it. Nothing needs to // be cleaned up. if (self->address) { if (*self->address) zsys_info ("client %u address='%s' - de-registering", self->unique_id, self->address); // Cancel all stream subscriptions stream_t *stream = (stream_t *) zlistx_detach (self->readers, NULL); while (stream) { zsock_send (stream->actor, "sp", "CANCEL", self); stream = (stream_t *) zlistx_detach (self->readers, NULL); } // Cancel all service offerings service_t *service = (service_t *) zhashx_first (self->server->services); while (service) { offer_t *offer = (offer_t *) zlistx_first (service->offers); while (offer) { if (offer->client == self) zlistx_delete (service->offers, zlistx_cursor (service->offers)); offer = (offer_t *) zlistx_next (service->offers); } service = (service_t *) zhashx_next (self->server->services); } if (*self->address) zhashx_delete (self->server->clients, self->address); } mlm_proto_set_status_code (self->message, MLM_PROTO_SUCCESS); }
static void deregister_the_client (client_t *self) { if (*self->address) zsys_info ("client address='%s' - de-registering", self->address); // Cancel all stream subscriptions stream_t *stream = (stream_t *) zlistx_detach (self->readers, NULL); while (stream) { zsock_send (stream->actor, "sp", "CANCEL", self); stream = (stream_t *) zlistx_detach (self->readers, NULL); } // Cancel all service offerings service_t *service = (service_t *) zhashx_first (self->server->services); while (service) { offer_t *offer = (offer_t *) zlistx_first (service->offers); while (offer) { if (offer->client == self) zlistx_delete (service->offers, zlistx_cursor (service->offers)); offer = (offer_t *) zlistx_next (service->offers); } service = (service_t *) zhashx_next (self->server->services); } if (*self->address) zhashx_delete (self->server->clients, self->address); mlm_proto_set_status_code (self->message, MLM_PROTO_SUCCESS); }
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 register_new_client (client_t *self) { self->address = strdup (mlm_proto_address (self->message)); // We ignore anonymous clients, which have empty addresses if (*self->address) { // If there's an existing client with this address, expire it // The alternative would be to reject new clients with the same address client_t *existing = (client_t *) zhashx_lookup ( self->server->clients, self->address); if (existing) engine_send_event (existing, expired_event); // In any case, we now own this address zhashx_update (self->server->clients, self->address, self); } if (*self->address) zsys_info ("client %u address='%s' - registering", self->unique_id, self->address); mlm_proto_set_status_code (self->message, MLM_PROTO_SUCCESS); }
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"); } }
static void signal_command_invalid (client_t *self) { zsys_info ("client %u address='%s' - invalid command", self->unique_id, self->address); mlm_proto_set_status_code (self->message, MLM_PROTO_COMMAND_INVALID); }
static void signal_operation_failed (client_t *self) { mlm_proto_set_status_code (self->message, MLM_PROTO_FAILED); }