namespace_info_t * gcluster_get_namespace_info(addr_info_t * addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, &namespace_info_handler, NULL}, {0, 0, NULL, NULL} }; namespace_info_t *ns_info = NULL; struct reply_sequence_data_s data = { &ns_info, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GETNS, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GETNS); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GETNS); goto error_reply; } message_destroy(req, NULL); return (ns_info); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
gint gcluster_push_virtual_ns_space_used(addr_info_t * addr, long timeout, GHashTable *space_used, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; GSList *kv_list = NULL; /* send the hashtable in the body */ kv_list = key_value_pairs_convert_from_map(space_used, FALSE, error); if (!kv_list) { GSETERROR(error, "Conversion HashTable->List failure"); return (0); } /*encode the list */ buf = key_value_pairs_marshall_gba(kv_list, error); if (!buf) { GSETERROR(error, "Failed to marshall kv list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_PUSH_BROKEN_CONT); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (0); }
GSList * gcluster_get_service_types(addr_info_t *addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {206, REPSEQ_BODYMANDATORY, &container_list_content_handler, NULL}, {200, REPSEQ_FINAL, &container_list_content_handler, NULL}, {0, 0, NULL, NULL}}; GSList *srvtypes = NULL; struct reply_sequence_data_s data = { &srvtypes, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GET_SRVNAMES, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_reply; } message_destroy(req, NULL); return (srvtypes); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
int32_t _broadcast_direct( struct iolayer * self, uint8_t index, struct session_manager * manager, struct message * msg ) { uint32_t i = 0; int32_t count = 0; // 数据改造 if ( self->transform != NULL ) { // 数据需要改造 char * buffer = NULL; uint32_t nbytes = message_get_length( msg ); buffer = self->transform( self->context, message_get_buffer(msg), &nbytes ); if ( buffer == NULL ) { // 数据改造失败 message_destroy( msg ); return -1; } if ( buffer != message_get_buffer(msg) ) { // 数据改造成功 message_set_buffer( msg, buffer, nbytes ); } } for ( i = 0; i < sidlist_count(msg->tolist); ++i ) { sid_t id = sidlist_get(msg->tolist, i); if ( SID_INDEX(id) != index ) { message_add_failure( msg, id ); continue; } struct session * session = session_manager_get( manager, id ); if ( unlikely(session == NULL) ) { message_add_failure( msg, id ); continue; } if ( session_append(session, msg) >= 0 ) { // 尝试单独发送 // 添加到发送队列成功 ++count; } } // 消息发送完毕, 直接销毁 if ( message_is_complete(msg) ) { message_destroy( msg ); } return count; }
GByteArray* sqlx_pack_REPLICATE(struct sqlx_name_s *name, struct TableSequence *tabseq) { GError *err = NULL; GByteArray *body, *encoded; MESSAGE req; EXTRA_ASSERT(name != NULL); EXTRA_ASSERT(tabseq != NULL); body = sqlx_encode_TableSequence(tabseq, &err); if (!body) { GRID_WARN("Transaction encoding error : (%d) %s", err->code, err->message); return NULL; } req = make_request("SQLX_REPLICATE", name); (void) message_set_BODY(req, body->data, body->len, NULL); encoded = message_marshall_gba(req, NULL); g_byte_array_free(body, TRUE); (void) message_destroy(req, NULL); return encoded; }
static void remove_operation_message_by_index(AMQP_MANAGEMENT_INSTANCE* amqp_management_instance, size_t index) { message_destroy(amqp_management_instance->operation_messages[index]->message); amqpalloc_free(amqp_management_instance->operation_messages[index]); if (amqp_management_instance->operation_message_count - index > 1) { memmove(&amqp_management_instance->operation_messages[index], &amqp_management_instance->operation_messages[index + 1], sizeof(OPERATION_MESSAGE_INSTANCE*)); } if (amqp_management_instance->operation_message_count == 1) { amqpalloc_free(amqp_management_instance->operation_messages); amqp_management_instance->operation_messages = NULL; } else { OPERATION_MESSAGE_INSTANCE** new_operation_messages = (OPERATION_MESSAGE_INSTANCE**)amqpalloc_realloc(amqp_management_instance->operation_messages, sizeof(OPERATION_MESSAGE_INSTANCE*) * (amqp_management_instance->operation_message_count - 1)); if (new_operation_messages != NULL) { amqp_management_instance->operation_messages = new_operation_messages; } } amqp_management_instance->operation_message_count--; }
// -----[ _net_iface_ptmp_send ]------------------------------------- static net_error_t _net_iface_ptmp_send(net_iface_t * self, net_addr_t l2_addr, net_msg_t * msg) { net_subnet_t * subnet; net_iface_t * dst_iface; net_error_t error; int reached= 0; assert(self->type == NET_IFACE_PTMP); subnet= self->dest.subnet; error= ip_opt_hook_msg_subnet(subnet, msg, &reached); if (error != ESUCCESS) return error; if (reached) { message_destroy(&msg); return ESUCCESS; } // Find destination node (based on "physical address") dst_iface= net_subnet_find_link(subnet, l2_addr); if (dst_iface == NULL) return ENET_HOST_UNREACH; // Forward along link from subnet -> node ... if (!net_iface_is_enabled(dst_iface)) return ENET_LINK_DOWN; network_send(dst_iface, msg); return ESUCCESS; }
void message_post_ping_response(char *data) { message_t *message = message_create(MESSAGE_PING_RESPONSE); message->message.ping_response.data = data; message_post(message); message_destroy(message); }
void message_post_session_closed(uint16_t session_id) { message_t *message = message_create(MESSAGE_CLOSE_SESSION); message->message.session_created.session_id = session_id; message_post(message); message_destroy(message); }
void amqpmanagement_destroy(AMQP_MANAGEMENT_HANDLE amqp_management) { if (amqp_management != NULL) { (void)amqpmanagement_close(amqp_management); if (amqp_management->operation_message_count > 0) { size_t i; for (i = 0; i < amqp_management->operation_message_count; i++) { message_destroy(amqp_management->operation_messages[i]->message); amqpalloc_free(amqp_management->operation_messages[i]); } amqpalloc_free(amqp_management->operation_messages); } link_destroy(amqp_management->sender_link); link_destroy(amqp_management->receiver_link); messagesender_destroy(amqp_management->message_sender); messagereceiver_destroy(amqp_management->message_receiver); amqpalloc_free(amqp_management); } }
static void remove_pending_message_by_index(MESSAGE_SENDER_INSTANCE* message_sender_instance, size_t index) { MESSAGE_WITH_CALLBACK** new_messages; if (message_sender_instance->messages[index]->message != NULL) { message_destroy(message_sender_instance->messages[index]->message); message_sender_instance->messages[index]->message = NULL; } amqpalloc_free(message_sender_instance->messages[index]); if (message_sender_instance->message_count - index > 1) { (void)memmove(&message_sender_instance->messages[index], &message_sender_instance->messages[index + 1], sizeof(MESSAGE_WITH_CALLBACK*) * (message_sender_instance->message_count - index - 1)); } message_sender_instance->message_count--; if (message_sender_instance->message_count > 0) { new_messages = (MESSAGE_WITH_CALLBACK**)amqpalloc_realloc(message_sender_instance->messages, sizeof(MESSAGE_WITH_CALLBACK*) * (message_sender_instance->message_count)); if (new_messages != NULL) { message_sender_instance->messages = new_messages; } } else { amqpalloc_free(message_sender_instance->messages); message_sender_instance->messages = NULL; } }
void messagesender_destroy(MESSAGE_SENDER_HANDLE message_sender) { if (message_sender != NULL) { MESSAGE_SENDER_INSTANCE* message_sender_instance = (MESSAGE_SENDER_INSTANCE*)message_sender; size_t i; messagesender_close(message_sender_instance); for (i = 0; i < message_sender_instance->message_count; i++) { if (message_sender_instance->messages[i]->on_message_send_complete != NULL) { message_sender_instance->messages[i]->on_message_send_complete(message_sender_instance->messages[i]->context, MESSAGE_SEND_ERROR); } message_destroy(message_sender_instance->messages[i]->message); amqpalloc_free(message_sender_instance->messages[i]); } if (message_sender_instance->messages != NULL) { amqpalloc_free(message_sender_instance->messages); } amqpalloc_free(message_sender); } }
static void _ipip_msg_destroy(void ** payload_ref) { net_msg_t * msg= *((net_msg_t **) payload_ref); ___ipip_debug("_ipip_msg_destroy msg=%m\n", msg); message_destroy(&msg); }
int32_t session_end( struct session * self, sid_t id ) { // 由于会话已经从管理器中删除了 // 会话中的ID已经非法 // 清空发送队列 uint32_t count = session_sendqueue_count(self); if ( count > 0 ) { syslog(LOG_WARNING, "%s(SID=%ld)'s Out-Message-List (%d) is not empty .", __FUNCTION__, id, count ); for ( ; count > 0; --count ) { struct message * msg = NULL; QUEUE_POP(sendqueue)( &self->sendqueue, &msg ); // 检查消息是否可以销毁了 message_add_failure( msg, id ); if ( message_is_complete(msg) ) { message_destroy( msg ); } } } // 停止会话 _stop( self ); _del_session( self ); return 0; }
static MESSAGE build_request(gchar * req_name, void *body, gsize body_size, GError ** error) { MESSAGE req = NULL; /*create a request and serializes it */ if (!message_create(&req, error)) { GSETERROR(error, "Failed to create a new message"); goto error_create; } if (body && !message_set_BODY(req, body, body_size, error)) { GSETERROR(error, "Failed to set message body"); goto error_set_body; } /*sets the request name */ if (!message_set_NAME(req, req_name, strlen(req_name), error)) { GSETERROR(error, "Failed to set message name"); goto error_set_name; } return (req); error_set_name: error_set_body: message_destroy(req, NULL); error_create: return (NULL); }
void message_post_ping_request(char *data) { message_t *message = message_create(MESSAGE_PING_REQUEST); message->message.ping_request.data = data; message_post(message); message_destroy(message); }
uint16_t message_post_create_session(message_options_t options[]) { uint16_t session_id; /* Create the message structure */ message_t *message = message_create(MESSAGE_CREATE_SESSION); /* Loop through the options */ if(options) { size_t i = 0; while(options[i].name) { if(!strcmp(options[i].name, "name")) message->message.create_session.name = options[i].value.s; if(!strcmp(options[i].name, "download")) message->message.create_session.download = options[i].value.s; if(!strcmp(options[i].name, "first_chunk")) message->message.create_session.first_chunk = options[i].value.i; if(!strcmp(options[i].name, "is_command")) message->message.create_session.is_command = options[i].value.i; i++; } } message_post(message); session_id = message->message.create_session.out.session_id; message_destroy(message); return session_id; }
void message_post_packet_in(uint8_t *data, size_t length) { message_t *message = message_create(MESSAGE_PACKET_IN); message->message.packet_out.data = data; message->message.packet_out.length = length; message_post(message); message_destroy(message); }
gint gcluster_push_services(addr_info_t * addr, long timeout, GSList * services_list, gboolean lock_action, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; buf = service_info_marshall_gba(services_list, error); if (!buf) { GSETERROR(error, "Failed to marshall services list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_PUSH_SRV, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_PUSH_SRV); goto error_buildreq; } if (lock_action) message_add_field(req, "LOCK", sizeof("LOCK") - 1, "true", sizeof("true") - 1, NULL); /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_PUSH_SRV); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: return (0); }
void message_post_data_in(uint16_t session_id, uint8_t *data, size_t length) { message_t *message = message_create(MESSAGE_DATA_IN); message->message.data_in.session_id = session_id; message->message.data_in.data = data; message->message.data_in.length = length; message_post(message); message_destroy(message); }
void message_post_config_string(char *name, char *value) { message_t *message = message_create(MESSAGE_CONFIG); message->message.config.name = name; message->message.config.type = CONFIG_STRING; message->message.config.value.string_value = value; message_post(message); message_destroy(message); }
void message_post_config_int(char *name, int value) { message_t *message = message_create(MESSAGE_CONFIG); message->message.config.name = name; message->message.config.type = CONFIG_INT; message->message.config.value.int_value = value; message_post(message); message_destroy(message); }
void game_object_clear_messages(game_object_t *obj) { int i; for(i=0; i<obj->messages_len; i++) message_destroy(obj->messages[i]); obj->messages_len = 0; }
gint gcluster_rm_broken_container(addr_info_t * addr, long timeout, GSList * container_list, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; buf = meta2_maintenance_names_marshall(container_list, error); if (!buf) { GSETERROR(error, "Failed to marshall container list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_RM_BROKEN_CONT, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_RM_BROKEN_CONT); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_RM_BROKEN_CONT); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: return (0); }
static GError * _client_manage_reply_data(struct gridd_client_s *client) { gsize s = 0; MESSAGE reply = NULL; GError *err = NULL; s = client->reply->len; message_create(&reply, NULL); if (!message_unmarshall(reply, client->reply->data, &s, &err)) { g_prefix_error(&err, "Decoding error: "); (void) message_destroy(reply, NULL); return err; } err = _client_manage_reply(client, reply); (void) message_destroy(reply, NULL); return err; }
GByteArray* sqlx_pack_DUMP(struct sqlx_name_s *name) { MESSAGE req; GByteArray *gba; req = make_request("SQLX_DUMP", name); gba = message_marshall_gba(req, NULL); (void) message_destroy(req, NULL); return gba; }
/** * This handler is used when an IPIP packet is delivered for * processing to the destination node. This is not the expected way * to receive IPIP packets. The normal way is through the tunnel * endpoint, i.e. a tunnel interface on the destination node. * * When a packet is received by this function it is discarded. It's * main purpose is to free IPIP packets from memory. */ static int _ipip_proto_handle(simulator_t * sim, void * handler, net_msg_t * msg) { ___ipip_debug("_ipip_proto_handle msg=%m\n", msg); net_msg_t * inner_msg= (net_msg_t *) msg->payload; message_destroy(&inner_msg); return ESUCCESS; }
GByteArray* sqlx_pack_PIPETO(struct sqlx_name_s *name, const gchar *target) { MESSAGE req; GByteArray *gba; req = make_request("SQLX_PIPETO", name); message_add_fields_str(req, "DST", target, NULL); gba = message_marshall_gba(req, NULL); (void) message_destroy(req, NULL); return gba; }
GByteArray* sqlx_pack_PIPEFROM(struct sqlx_name_s *name, const gchar *source) { MESSAGE req; GByteArray *gba; req = make_request("SQLX_PIPEFROM", name); message_add_fields_str(req, "SRC", source, NULL); gba = message_marshall_gba(req, NULL); (void) message_destroy(req, NULL); return gba; }
GByteArray* sqlx_pack_RESTORE(struct sqlx_name_s *name, const guint8 *raw, gsize rawsize) { MESSAGE req; GByteArray *gba; req = make_request("SQLX_RESTORE", name); (void) message_set_BODY(req, raw, rawsize, NULL); gba = message_marshall_gba(req, NULL); (void) message_destroy(req, NULL); return gba; }