int
client_test(
    http_test_info_t *			info,
    int					timer)	
{
    int                                 rc = 0;
    globus_result_t                     result;
    int                                 header_cnt = 0;
    char                                content_length_buffer[64];
    globus_xio_http_header_t            headers[2];
    globus_xio_handle_t                 handle;
    int                                 i;
    globus_xio_data_descriptor_t        descriptor;
    globus_byte_t                       buffer[1];
    int                                 status_code;
    char *                              reason_phrase;
    globus_utp_start_timer(timer);
    if (info->transfer_encoding != NULL)
    {
        headers[header_cnt].name = "Transfer-Encoding";
        headers[header_cnt].value = info->transfer_encoding;

        header_cnt++;

    }

    if ((info->version == GLOBUS_XIO_HTTP_VERSION_1_0) ||
            ((info->transfer_encoding != NULL)
                && strcmp(info->transfer_encoding, IDENTITY) == 0))
    {
        sprintf(content_length_buffer, "%lu", (unsigned long) info->size);

        headers[header_cnt].name = "Content-Length";
        headers[header_cnt].value = &content_length_buffer[0];

        header_cnt++;
    }

    handle = NULL;
    for (i = 0; i < info->iterations; i++)
    {

        if (handle != NULL)
        {
            globus_xio_close(handle, NULL);
        }
        result = http_test_client_request(
                &handle,
                info->tcp_driver,
                info->http_driver,
                info->stack,
                info->contact,
                "%2fpost-test",
                "POST",
                info->version,
                headers,
                header_cnt);

        if (result != GLOBUS_SUCCESS)
        {
            fprintf(stderr, "Error making request: %s\n",
                    globus_object_printable_to_string(
                    globus_error_get(result)));
            rc = 50;
            goto error_exit;
        }

        result = globus_l_xio_test_write_buffer(
                handle,
                info->buffer,
                info->size,
		info->http_driver);

        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            break;
        }
        /* READ RESPONSE */
        result = globus_xio_data_descriptor_init(&descriptor, handle);
        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            goto close_exit;
        }
        result = globus_xio_read(
                handle,
                buffer,
                0,
                0,
                NULL,
                descriptor);
        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            goto close_exit;
        }
        result = globus_xio_data_descriptor_cntl(
                descriptor,
                info->http_driver,
                GLOBUS_XIO_HTTP_GET_RESPONSE,
                &status_code,
                &reason_phrase,
                NULL,
                NULL);
        if (result != GLOBUS_SUCCESS || status_code < 200 || status_code > 299)
        {
            fprintf(stderr, "Get failed with \"%03d %s\"\n",
                    status_code,
                    reason_phrase);
            rc = 51;
            goto close_exit;
        }

        result = globus_l_xio_test_read_buffer(
                handle,
                info->buffer,
                info->size);
        if (result != GLOBUS_SUCCESS)
        {
            rc = 52;
        }
        info->done = 0;

        if (rc != 0)
        {
            break;
        }
    }

close_exit:
    globus_xio_close(handle, NULL);
    globus_utp_stop_timer(timer);
error_exit:

    return rc;
}
Example #2
0
int
client_main(
    const char *                        filename,
    const char *                        contact,
    globus_xio_http_version_t           http_version)
{
    int                                 rc;
    globus_result_t                     result;
    int                                 header_cnt = 0;
    char                                content_length_buffer[64];
    globus_xio_http_header_t            headers[2];
    globus_xio_handle_t                 handle;
    int                                 i;
    globus_xio_data_descriptor_t        descriptor;
    globus_byte_t                       buffer[1];
    int                                 status_code;
    char *                              reason_phrase;

    rc = globus_l_xio_test_read_file(filename);
    if (rc != 0)
    {
        goto error_exit;
    }

    if (transfer_encoding != NULL)
    {
        headers[header_cnt].name = "Transfer-Encoding";
        headers[header_cnt].value = transfer_encoding;

        header_cnt++;

    }

    if ((http_version == GLOBUS_XIO_HTTP_VERSION_1_0) ||
            ((transfer_encoding != NULL)
                && strcmp(transfer_encoding, IDENTITY) == 0))
    {
        sprintf(content_length_buffer, "%ld", file_size);

        headers[header_cnt].name = "Content-Length";
        headers[header_cnt].value = &content_length_buffer[0];

        header_cnt++;
    }

    handle = NULL;
    for (i = 0; i < iterations; i++)
    {

        if (handle != NULL)
        {
            globus_xio_close(handle, NULL);
        }
        result = http_test_client_request(
                &handle,
                tcp_driver,
                http_driver,
                stack,
                contact,
                "%2fpost-test",
                "POST",
                http_version,
                headers,
                header_cnt);

        if (result != GLOBUS_SUCCESS)
        {
            fprintf(stderr, "Error making request: %s\n",
                    globus_object_printable_to_string(
                    globus_error_get(result)));
            rc = 50;
            goto error_exit;
        }

        result = globus_l_xio_test_write_buffer(
                handle,
                message_body,
                file_size,
                buffer_size);

        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            break;
        }

        /* READ RESPONSE */
        result = globus_xio_data_descriptor_init(&descriptor, handle);
        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            goto close_exit;
        }
        result = globus_xio_read(
                handle,
                buffer,
                0,
                0,
                NULL,
                descriptor);
        if (result != GLOBUS_SUCCESS)
        {
            rc = 51;
            goto close_exit;
        }
        result = globus_xio_data_descriptor_cntl(
                descriptor,
                http_driver,
                GLOBUS_XIO_HTTP_GET_RESPONSE,
                &status_code,
                &reason_phrase,
                NULL,
                NULL);
        if (result != GLOBUS_SUCCESS || status_code < 200 || status_code > 299)
        {
            fprintf(stderr, "Get failed with \"%03d %s\"\n",
                    status_code,
                    reason_phrase);
            rc = 51;
            goto close_exit;
        }

        result = globus_l_xio_test_read_buffer(
                handle,
                message_body,
                file_size,
                buffer_size);

        if (result != GLOBUS_SUCCESS)
        {
            rc = 52;
        }

        if (rc != 0)
        {
            break;
        }
    }

close_exit:
    globus_xio_close(handle, NULL);
error_exit:
    if (rc == 0)
    {
        printf("Success\n");
    }
    else
    {
        printf("Error\n");
    }

    return rc;
}