A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
46:01f7ca900e07
Parent:
45:83b4eda4891c
diff -r 83b4eda4891c -r 01f7ca900e07 connection.c
--- a/connection.c	Thu Jul 12 18:09:41 2018 -0700
+++ b/connection.c	Tue Sep 11 11:13:43 2018 -0700
@@ -837,7 +837,6 @@
                 else
                 {
                     AMQP_VALUE descriptor = amqpvalue_get_inplace_descriptor(performative);
-                    uint64_t performative_ulong;
 
                     if (connection->is_trace_on == 1)
                     {
@@ -990,89 +989,96 @@
                     }
                     else
                     {
-                        amqpvalue_get_ulong(descriptor, &performative_ulong);
+                        uint64_t performative_ulong;
 
-                        switch (performative_ulong)
+                        if (amqpvalue_get_ulong(descriptor, &performative_ulong) != 0)
+                        {
+                            LogError("Failed getting ulong amqp performative");
+                        }
+                        else
                         {
-                        default:
-                            LogError("Bad performative: %02x", performative);
-                            break;
+                            switch (performative_ulong)
+                            {
+                            default:
+                                LogError("Bad performative: %02x", performative);
+                                break;
 
-                        case AMQP_BEGIN:
-                        {
-                            BEGIN_HANDLE begin;
-
-                            if (amqpvalue_get_begin(performative, &begin) != 0)
+                            case AMQP_BEGIN:
                             {
-                                LogError("Cannot get begin performative");
-                            }
-                            else
-                            {
-                                uint16_t remote_channel;
-                                ENDPOINT_HANDLE new_endpoint = NULL;
-                                bool remote_begin = false;
+                                BEGIN_HANDLE begin;
+
+                                if (amqpvalue_get_begin(performative, &begin) != 0)
+                                {
+                                    LogError("Cannot get begin performative");
+                                }
+                                else
+                                {
+                                    uint16_t remote_channel;
+                                    ENDPOINT_HANDLE new_endpoint = NULL;
+                                    bool remote_begin = false;
 
-                                if (begin_get_remote_channel(begin, &remote_channel) != 0)
-                                {
-                                    remote_begin = true;
-                                    if (connection->on_new_endpoint != NULL)
+                                    if (begin_get_remote_channel(begin, &remote_channel) != 0)
                                     {
-                                        new_endpoint = connection_create_endpoint(connection);
-                                        if (!connection->on_new_endpoint(connection->on_new_endpoint_callback_context, new_endpoint))
+                                        remote_begin = true;
+                                        if (connection->on_new_endpoint != NULL)
                                         {
-                                            connection_destroy_endpoint(new_endpoint);
-                                            new_endpoint = NULL;
+                                            new_endpoint = connection_create_endpoint(connection);
+                                            if (!connection->on_new_endpoint(connection->on_new_endpoint_callback_context, new_endpoint))
+                                            {
+                                                connection_destroy_endpoint(new_endpoint);
+                                                new_endpoint = NULL;
+                                            }
                                         }
                                     }
-                                }
 
-                                if (!remote_begin)
-                                {
-                                    ENDPOINT_INSTANCE* session_endpoint = find_session_endpoint_by_outgoing_channel(connection, remote_channel);
-                                    if (session_endpoint == NULL)
+                                    if (!remote_begin)
                                     {
-                                        LogError("Cannot create session endpoint");
+                                        ENDPOINT_INSTANCE* session_endpoint = find_session_endpoint_by_outgoing_channel(connection, remote_channel);
+                                        if (session_endpoint == NULL)
+                                        {
+                                            LogError("Cannot create session endpoint");
+                                        }
+                                        else
+                                        {
+                                            session_endpoint->incoming_channel = channel;
+                                            session_endpoint->on_endpoint_frame_received(session_endpoint->callback_context, performative, payload_size, payload_bytes);
+                                        }
                                     }
                                     else
                                     {
-                                        session_endpoint->incoming_channel = channel;
-                                        session_endpoint->on_endpoint_frame_received(session_endpoint->callback_context, performative, payload_size, payload_bytes);
+                                        if (new_endpoint != NULL)
+                                        {
+                                            new_endpoint->incoming_channel = channel;
+                                            new_endpoint->on_endpoint_frame_received(new_endpoint->callback_context, performative, payload_size, payload_bytes);
+                                        }
                                     }
+
+                                    begin_destroy(begin);
+                                }
+
+                                break;
+                            }
+
+                            case AMQP_FLOW:
+                            case AMQP_TRANSFER:
+                            case AMQP_DISPOSITION:
+                            case AMQP_END:
+                            case AMQP_ATTACH:
+                            case AMQP_DETACH:
+                            {
+                                ENDPOINT_INSTANCE* session_endpoint = find_session_endpoint_by_incoming_channel(connection, channel);
+                                if (session_endpoint == NULL)
+                                {
+                                    LogError("Cannot find session endpoint for channel %u", (unsigned int)channel);
                                 }
                                 else
                                 {
-                                    if (new_endpoint != NULL)
-                                    {
-                                        new_endpoint->incoming_channel = channel;
-                                        new_endpoint->on_endpoint_frame_received(new_endpoint->callback_context, performative, payload_size, payload_bytes);
-                                    }
+                                    session_endpoint->on_endpoint_frame_received(session_endpoint->callback_context, performative, payload_size, payload_bytes);
                                 }
 
-                                begin_destroy(begin);
+                                break;
                             }
-
-                            break;
-                        }
-
-                        case AMQP_FLOW:
-                        case AMQP_TRANSFER:
-                        case AMQP_DISPOSITION:
-                        case AMQP_END:
-                        case AMQP_ATTACH:
-                        case AMQP_DETACH:
-                        {
-                            ENDPOINT_INSTANCE* session_endpoint = find_session_endpoint_by_incoming_channel(connection, channel);
-                            if (session_endpoint == NULL)
-                            {
-                                LogError("Cannot find session endpoint for channel %u", (unsigned int)channel);
                             }
-                            else
-                            {
-                                session_endpoint->on_endpoint_frame_received(session_endpoint->callback_context, performative, payload_size, payload_bytes);
-                            }
-
-                            break;
-                        }
                         }
                     }
                 }