A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
Diff: link.c
- Revision:
- 23:1111ee8bcba4
- Parent:
- 21:f9c433d8e6ca
- Child:
- 24:2c59c2d43ebf
--- a/link.c Thu Apr 06 14:11:27 2017 -0700 +++ b/link.c Fri Apr 21 14:50:32 2017 -0700 @@ -80,7 +80,7 @@ { if (indicate_settled && (delivery_instance->on_delivery_settled != NULL)) { - delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, NULL); + delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, LINK_DELIVERY_SETTLE_REASON_NOT_DELIVERED, NULL); } free(delivery_instance); } @@ -229,7 +229,10 @@ attach_set_role(attach, role); attach_set_source(attach, link->source); attach_set_target(attach, link->target); - attach_set_properties(attach, link->attach_properties); + if (link->attach_properties != NULL) + { + attach_set_properties(attach, link->attach_properties); + } if (role == role_sender) { @@ -471,7 +474,7 @@ } else { - delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, delivery_state); + delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, LINK_DELIVERY_SETTLE_REASON_DISPOSITION_RECEIVED, delivery_state); free(delivery_instance); if (singlylinkedlist_remove(link_instance->pending_deliveries, pending_delivery) != 0) { @@ -559,13 +562,13 @@ } else if (new_session_state == SESSION_STATE_DISCARDING) { - remove_all_pending_deliveries(link_instance, true); - set_link_state(link_instance, LINK_STATE_DETACHED); + set_link_state(link_instance, LINK_STATE_DETACHED); + remove_all_pending_deliveries(link_instance, true); } else if (new_session_state == SESSION_STATE_ERROR) { - remove_all_pending_deliveries(link_instance, true); - set_link_state(link_instance, LINK_STATE_ERROR); + set_link_state(link_instance, LINK_STATE_ERROR); + remove_all_pending_deliveries(link_instance, true); } } @@ -586,7 +589,7 @@ (void)send_result; if (link_instance->snd_settle_mode == sender_settle_mode_settled) { - delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, NULL); + delivery_instance->on_delivery_settled(delivery_instance->callback_context, delivery_instance->delivery_id, LINK_DELIVERY_SETTLE_REASON_SETTLED, NULL); free(delivery_instance); (void)singlylinkedlist_remove(link_instance->pending_deliveries, delivery_instance_list_item); } @@ -594,7 +597,7 @@ LINK_HANDLE link_create(SESSION_HANDLE session, const char* name, role role, AMQP_VALUE source, AMQP_VALUE target) { - LINK_INSTANCE* result = malloc(sizeof(LINK_INSTANCE)); + LINK_INSTANCE* result = (LINK_INSTANCE*)malloc(sizeof(LINK_INSTANCE)); if (result != NULL) { result->link_state = LINK_STATE_DETACHED; @@ -624,7 +627,8 @@ } else { - result->name = malloc(strlen(name) + 1); + size_t name_length = strlen(name); + result->name = (char*)malloc(name_length + 1); if (result->name == NULL) { singlylinkedlist_destroy(result->pending_deliveries); @@ -637,7 +641,7 @@ result->callback_context = NULL; set_link_state(result, LINK_STATE_DETACHED); - (void)strcpy(result->name, name); + (void)memcpy(result->name, name, name_length + 1); result->link_endpoint = session_create_link_endpoint(session, name); if (result->link_endpoint == NULL) { @@ -655,7 +659,7 @@ LINK_HANDLE link_create_from_endpoint(SESSION_HANDLE session, LINK_ENDPOINT_HANDLE link_endpoint, const char* name, role role, AMQP_VALUE source, AMQP_VALUE target) { - LINK_INSTANCE* result = malloc(sizeof(LINK_INSTANCE)); + LINK_INSTANCE* result = (LINK_INSTANCE*)malloc(sizeof(LINK_INSTANCE)); if (result != NULL) { result->link_state = LINK_STATE_DETACHED; @@ -692,7 +696,8 @@ } else { - result->name = malloc(strlen(name) + 1); + size_t name_length = strlen(name); + result->name = (char*)malloc(name_length + 1); if (result->name == NULL) { singlylinkedlist_destroy(result->pending_deliveries); @@ -701,7 +706,7 @@ } else { - (void)strcpy(result->name, name); + (void)memcpy(result->name, name, name_length + 1); result->on_link_state_changed = NULL; result->callback_context = NULL; result->link_endpoint = link_endpoint; @@ -1074,7 +1079,7 @@ } else { - DELIVERY_INSTANCE* pending_delivery = malloc(sizeof(DELIVERY_INSTANCE)); + DELIVERY_INSTANCE* pending_delivery = (DELIVERY_INSTANCE*)malloc(sizeof(DELIVERY_INSTANCE)); if (pending_delivery == NULL) { result = LINK_TRANSFER_ERROR; @@ -1183,4 +1188,4 @@ } } return result; -} \ No newline at end of file +}