A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
Diff: message_sender.c
- Revision:
- 2:64b4feb67cd3
- Parent:
- 1:eab586236bfe
- Child:
- 5:ae49385aff34
--- a/message_sender.c Sun Apr 24 16:40:31 2016 -0700 +++ b/message_sender.c Mon May 09 14:37:14 2016 -0700 @@ -430,6 +430,30 @@ } } +static void indicate_all_messages_as_error(MESSAGE_SENDER_INSTANCE* message_sender_instance) +{ + size_t i; + + 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) + { + message_sender_instance->message_count = 0; + + amqpalloc_free(message_sender_instance->messages); + message_sender_instance->messages = NULL; + } +} + static void on_link_state_changed(void* context, LINK_STATE new_link_state, LINK_STATE previous_link_state) { MESSAGE_SENDER_INSTANCE* message_sender_instance = (MESSAGE_SENDER_INSTANCE*)context; @@ -447,6 +471,7 @@ (message_sender_instance->message_sender_state == MESSAGE_SENDER_STATE_CLOSING)) { /* User initiated transition, we should be good */ + indicate_all_messages_as_error(message_sender_instance); set_message_sender_state(message_sender_instance, MESSAGE_SENDER_STATE_IDLE); } else if (message_sender_instance->message_sender_state != MESSAGE_SENDER_STATE_IDLE) @@ -458,6 +483,7 @@ case LINK_STATE_ERROR: if (message_sender_instance->message_sender_state != MESSAGE_SENDER_STATE_ERROR) { + indicate_all_messages_as_error(message_sender_instance); set_message_sender_state(message_sender_instance, MESSAGE_SENDER_STATE_ERROR); } break; @@ -492,25 +518,10 @@ 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); - } + indicate_all_messages_as_error(message_sender_instance); amqpalloc_free(message_sender); }