Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Revision:
1:9190c0f4d23a
Parent:
0:fa2de1b79154
Child:
6:c55b013dfc2a
--- a/socketio_mbed.c	Fri Apr 08 12:01:36 2016 -0700
+++ b/socketio_mbed.c	Sun Apr 24 16:41:14 2016 -0700
@@ -12,8 +12,10 @@
 #include "azure_c_shared_utility/socketio.h"
 #include "azure_c_shared_utility/list.h"
 #include "azure_c_shared_utility/tcpsocketconnection_c.h"
+#include "azure_c_shared_utility/iot_logging.h"
 
 #define UNABLE_TO_COMPLETE -2
+#define MBED_RECEIVE_BYTES_VALUE    128
 
 typedef enum IO_STATE_TAG
 {
@@ -401,15 +403,24 @@
 
             while (received > 0)
             {
-                unsigned char recv_bytes[128];
-                received = tcpsocketconnection_receive(socket_io_instance->tcp_socket_connection, (char*)recv_bytes, sizeof(recv_bytes));
-                if (received > 0)
+                unsigned char* recv_bytes = malloc(MBED_RECEIVE_BYTES_VALUE);
+                if (recv_bytes == NULL)
+                {
+                    LogError("Socketio_Failure: NULL allocating input buffer.");
+                    indicate_error(socket_io_instance);
+                }
+                else
                 {
-                    if (socket_io_instance->on_bytes_received != NULL)
+                    received = tcpsocketconnection_receive(socket_io_instance->tcp_socket_connection, (char*)recv_bytes, MBED_RECEIVE_BYTES_VALUE);
+                    if (received > 0)
                     {
-                        /* explictly ignoring here the result of the callback */
-                        (void)socket_io_instance->on_bytes_received(socket_io_instance->on_bytes_received_context, recv_bytes, received);
+                        if (socket_io_instance->on_bytes_received != NULL)
+                        {
+                            /* explictly ignoring here the result of the callback */
+                            (void)socket_io_instance->on_bytes_received(socket_io_instance->on_bytes_received_context, recv_bytes, received);
+                        }
                     }
+                    free(recv_bytes);
                 }
             }
         }