void uhttp_client_dowork()

in src/uhttp.c [1424:1475]


void uhttp_client_dowork(HTTP_CLIENT_HANDLE handle)
{
    if (handle != NULL)
    {
        /* Codes_SRS_UHTTP_07_037: [http_client_dowork shall call the underlying xio_dowork function. ] */
        HTTP_CLIENT_HANDLE_DATA* http_data = (HTTP_CLIENT_HANDLE_DATA*)handle;
        xio_dowork(http_data->xio_handle);

        // Wait till I'm connected
        if (handle->connected == 1)
        {
            LIST_ITEM_HANDLE pending_list_item;
            /* Codes_SRS_UHTTP_07_016: [http_client_dowork shall iterate through the queued Data using the xio interface to send the http request in the following ways...] */
            while ((pending_list_item = singlylinkedlist_get_head_item(http_data->data_list)) != NULL)
            {
                HTTP_SEND_DATA* send_data = (HTTP_SEND_DATA*)singlylinkedlist_item_get_value(pending_list_item);
                if (send_data != NULL)
                {
                    size_t content_len = BUFFER_length(send_data->content);
                    /* Codes_SRS_UHTTP_07_052: [uhttp_client_dowork shall call xio_send to transmits the header information... ] */
                    if (send_http_data(http_data, send_data->request_type, STRING_c_str(send_data->relative_path), send_data->header_line) != 0)
                    {
                        LogError("Failure writing content buffer");
                        if (http_data->on_error)
                        {
                            http_data->on_error(http_data->error_user_ctx, HTTP_CALLBACK_REASON_SEND_FAILED);
                        }
                    }
                    else if (content_len > 0)
                    {
                        /* Codes_SRS_UHTTP_07_053: [ Then uhttp_client_dowork shall use xio_send to transmit the content of the http request. ] */
                        if (write_data_line(http_data, BUFFER_u_char(send_data->content), content_len) != 0)
                        {
                            LogError("Failure writing content buffer");
                            if (http_data->on_error)
                            {
                                http_data->on_error(http_data->error_user_ctx, HTTP_CALLBACK_REASON_SEND_FAILED);
                            }
                        }
                    }

                    /* Codes_SRS_UHTTP_07_046: [ http_client_dowork shall free resouces queued to send to the http endpoint. ] */
                    STRING_delete(send_data->relative_path);
                    BUFFER_delete(send_data->content);
                    STRING_delete(send_data->header_line);
                    free(send_data);
                }
                (void)singlylinkedlist_remove(http_data->data_list, pending_list_item);
            }
        }
    }
}