void uhttp_client_close()

in src/uhttp.c [1240:1284]


void uhttp_client_close(HTTP_CLIENT_HANDLE handle, ON_HTTP_CLOSED_CALLBACK on_close_callback, void* callback_ctx)
{
    HTTP_CLIENT_HANDLE_DATA* http_data = (HTTP_CLIENT_HANDLE_DATA*)handle;
    /* Codes_SRS_UHTTP_07_009: [If handle is NULL then http_client_close shall do nothing] */
    /* Codes_SRS_UHTTP_07_049: [ If the state has been previously set to state_closed, uhttp_client_close shall do nothing. ] */
    if (http_data != NULL && http_data->recv_msg.recv_state != state_closed && http_data->recv_msg.recv_state != state_closing)
    {
        http_data->on_close_callback = on_close_callback;
        http_data->close_user_ctx = callback_ctx;
        /* Codes_SRS_UHTTP_07_010: [If the xio_handle is NOT NULL http_client_close shall call xio_close to close the handle] */
        (void)xio_close(http_data->xio_handle, on_xio_close_complete, http_data);

        LIST_ITEM_HANDLE pending_list_item;
        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)
            {
                STRING_delete(send_data->relative_path);
                BUFFER_delete(send_data->content);
                STRING_delete(send_data->header_line);
                free(send_data);
            }
            singlylinkedlist_remove(http_data->data_list, pending_list_item);
        }

        http_data->recv_msg.status_code = 0;
        http_data->recv_msg.recv_state = state_closed;
        http_data->recv_msg.total_body_len = 0;
        free(http_data->host_name);
        http_data->host_name = NULL;

        /* Codes_SRS_UHTTP_07_011: [http_client_close shall free any HTTPHeader object that has not been freed] */
        if (http_data->recv_msg.resp_header != NULL)
        {
            HTTPHeaders_Free(http_data->recv_msg.resp_header);
            http_data->recv_msg.resp_header = NULL;
        }
        if (http_data->recv_msg.msg_body != NULL)
        {
            BUFFER_delete(http_data->recv_msg.msg_body);
            http_data->recv_msg.msg_body = NULL;
        }
    }
}