int
main(
    int                                     argc,
    char **                                 argv)
{
    globus_xio_driver_t                     tcp_driver;
    globus_xio_driver_t                     ftp_driver;
    globus_xio_stack_t                      stack;
    globus_xio_handle_t                     xio_handle;
    char *                                  cs;
    globus_result_t                         res;
    char                                    line[LINE_LEN];
    globus_bool_t                           done = GLOBUS_FALSE;
    globus_size_t                           nbytes;
    globus_xio_server_t                     server_handle;

    globus_module_activate(GLOBUS_XIO_MODULE);
    globus_xio_stack_init(&stack, NULL);

    res = globus_xio_driver_load("tcp", &tcp_driver);
    test_res(res, __LINE__);
    res = globus_xio_stack_push_driver(stack, tcp_driver);
    test_res(res, __LINE__);
    res = globus_xio_driver_load("gssapi_ftp", &ftp_driver);
    test_res(res, __LINE__);
    res = globus_xio_stack_push_driver(stack, ftp_driver);
    test_res(res, __LINE__);

    globus_xio_server_create(&server_handle, NULL, stack);

    globus_xio_server_get_contact_string(server_handle, &cs);
    fprintf(stdout, "Contact: %s\n", cs);

    globus_xio_server_accept(&xio_handle, server_handle);

    res = globus_xio_open(xio_handle, NULL, NULL);
    test_res(res, __LINE__);
    res = globus_xio_write(xio_handle, "220 hello\r\n", strlen("220 hello\r\n"),
        strlen("220 hello\r\n"), &nbytes, NULL);
    test_res(res, __LINE__);

    while(!done)
    {
        res = globus_xio_read(
            xio_handle, line, LINE_LEN, 1, &nbytes, NULL);
        test_res(res, __LINE__);
        line[nbytes] = '\0';

        fprintf(stdout, "%s", line);
    }

    globus_xio_close(xio_handle, NULL);

    globus_module_activate(GLOBUS_XIO_MODULE);

    return 0;
}
int
main(
    int                                     argc,
    char **                                 argv)
{
    globus_xio_driver_t                     driver;
    globus_xio_driver_t                     transport_driver = NULL;
    globus_xio_stack_t                      stack;
    globus_xio_handle_t                     xio_handle;
    char *                                  cs;
    globus_result_t                         res;
    char                                    line[LINE_LEN];
    char				    writeline[LINE_LEN];
    int					    len;
    int                                     ctr;
    globus_bool_t                           done = GLOBUS_FALSE;
    globus_size_t                           nbytes;
    globus_size_t			    pbytes;
    globus_xio_server_t                     server_handle;
    globus_xio_attr_t			    attr=NULL;
    globus_size_t			    port;

    /*if(argc < 2)
    {
        help();
        return 1;
    }*/

    globus_module_activate(GLOBUS_XIO_MODULE);
    globus_xio_stack_init(&stack, NULL);
    for(ctr = 1; ctr < argc; ctr++)
    {
        if(strcmp(argv[ctr], "-h") == 0)
        {
            help();
            return 0;
        }
	else if(strcmp(argv[ctr], "-p") == 0 && ctr + 1 < argc)
	{
            port = atoi(argv[ctr+1]);       
	    globus_xio_driver_load("bidi", &driver);
	    globus_xio_attr_init(&attr);
            res = globus_xio_attr_cntl( 
		       		    attr, 
				    driver, 
				    GLOBUS_XIO_BIDI_SET_PORT, 
				    port);
	}
    }
    
    globus_xio_stack_push_driver(stack, driver);

    globus_xio_server_create(&server_handle, attr, stack);

    globus_xio_server_get_contact_string(server_handle, &cs);
    fprintf(stdout, "\n\n %s\n\n", cs);

    globus_xio_server_accept(&xio_handle, server_handle);

    globus_xio_open(xio_handle, NULL, NULL);

    while(!done)
    {
        res = globus_xio_read(
            xio_handle, line, LINE_LEN, 1, &nbytes, NULL);

        if(res != GLOBUS_SUCCESS)
        {
            done = 1;
        }

        line[nbytes] = '\0';
        fprintf(stdout, "%s", line);
        sprintf(writeline, "%s", line);
	len=strlen(line);
	res = globus_xio_write(
		xio_handle, writeline, len, len, &pbytes, NULL);

	if(res != GLOBUS_SUCCESS)
	{
	    done = 1;
	}

    }

    globus_xio_close(xio_handle, NULL);

    globus_module_activate(GLOBUS_XIO_MODULE);

    return 0;
}
int
framework_main(
    int                                     argc,
    char **                                 argv)
{
    int                                     rc;
    globus_xio_stack_t                      stack;
    globus_xio_handle_t                     handle;
    globus_xio_attr_t                       attr;
    globus_result_t                         res;
    globus_xio_server_t                     server;

    globus_l_closed = GLOBUS_FALSE;
    globus_l_accepted = GLOBUS_FALSE;

    rc = globus_module_activate(GLOBUS_XIO_MODULE);
    globus_assert(rc == 0);

    globus_mutex_init(&globus_l_mutex, NULL);
    globus_cond_init(&globus_l_cond, NULL);

    res = globus_xio_attr_init(&attr);
    test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);

    res = globus_xio_stack_init(&stack, NULL);
    test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);

    parse_parameters(argc, argv, stack, attr);

    if(globus_l_test_info.server)
    {
        res = globus_xio_server_create(&server, attr, stack);
        test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);

        res = globus_xio_server_register_accept(
                  server,
                  accept_cb,
                  &handle);
        test_res(GLOBUS_XIO_TEST_FAIL_PASS_ACCEPT, res, __LINE__, __FILE__);

        globus_mutex_lock(&globus_l_mutex);
        {
            while(!globus_l_accepted)
            {
                globus_cond_wait(&globus_l_cond, &globus_l_mutex);
            }
        }
        globus_mutex_unlock(&globus_l_mutex);

    }
    else
    {
        res = globus_xio_handle_create(&handle, stack);
        test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
    }

    res = globus_xio_register_open(
              handle,
              "whatever",
              attr,
              open_cb,
              (void *)&globus_l_test_info);
    test_res(GLOBUS_XIO_TEST_FAIL_PASS_OPEN, res, __LINE__, __FILE__);

    globus_mutex_lock(&globus_l_mutex);
    {
        while(!globus_l_closed)
        {
            globus_cond_wait(&globus_l_cond, &globus_l_mutex);
        }
    }
    globus_mutex_unlock(&globus_l_mutex);

    globus_xio_attr_destroy(attr);
    globus_xio_stack_destroy(stack);

    if(globus_l_test_info.server)
    {
        res = globus_xio_server_close(server);
        test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
    }

    test_common_end();

    rc = globus_module_deactivate(GLOBUS_XIO_MODULE);
    globus_assert(rc == 0);

    fprintf(stdout, "Success.\n");

    return 0;
}
示例#4
0
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    result = globus_xio_attr_init(
            &xio_attr);

    result = globus_xio_attr_cntl(
            xio_attr,
            NULL,
            GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT,
            NULL,
            &(globus_reltime_t) { .tv_sec = 1 },
            NULL);

    result = globus_xio_server_create(&xio_server, xio_attr, xio_stack);
    if (result != GLOBUS_SUCCESS)
    {
        goto server_create_fail;
    }
    result = globus_xio_server_get_contact_string(xio_server, contact);
    if (result != GLOBUS_SUCCESS)
    {
        goto contact_string_fail;
    }

    globus_thread_create(&thread, NULL, server_thread, xio_server);

    if (result != GLOBUS_SUCCESS)
    {
contact_string_fail:
int
main(
    int                                     argc,
    char **                                 argv)
{
    globus_xio_driver_t                     tcp_driver;
    globus_xio_stack_t                      stack;
    globus_xio_handle_t                     xio_handle;
    globus_xio_server_t                     xio_server;
    globus_result_t                         res;
    char *                                  cs;
    globus_gridftp_server_control_attr_t    ftp_attr;
    globus_gridftp_server_control_t         ftp_server;
    globus_xio_system_socket_t              system_handle;

    globus_module_activate(GLOBUS_XIO_MODULE);
    globus_module_activate(GLOBUS_GRIDFTP_SERVER_CONTROL_MODULE);

    globus_mutex_init(&gs_l_mutex, NULL);
    globus_cond_init(&gs_l_cond, NULL);

    /*
     *  set up the xio handle
     */
    res = globus_xio_driver_load("tcp", &tcp_driver);
    test_res(res, __LINE__);

    res = globus_xio_stack_init(&stack, NULL);
    test_res(res, __LINE__);

    res = globus_xio_stack_push_driver(stack, tcp_driver);
    test_res(res, __LINE__);

    res = globus_xio_server_create(&xio_server, NULL, stack);
    test_res(res, __LINE__);

    globus_xio_stack_destroy(stack);

    res = globus_xio_server_get_contact_string(xio_server, &cs);
    test_res(res, __LINE__);
    fprintf(stdout, "%s\n", cs);
    globus_free(cs);

    res = globus_xio_server_accept(&xio_handle, xio_server);
    test_res(res, __LINE__);

    fprintf(stdout, "xio connection esstablished.\n");
    /*
     *  server connection is all set up, hand it to server_lib
     */
    res = globus_gridftp_server_control_init(&ftp_server);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_init(&ftp_attr);
    test_res(res, __LINE__);

    globus_xio_server_close(xio_server);

    if(argc > 1)
    {
        globus_gridftp_server_control_attr_set_security(
            ftp_attr, GLOBUS_GRIDFTP_SERVER_LIBRARY_GSSAPI | 
                GLOBUS_GRIDFTP_SERVER_LIBRARY_NONE);
    }
    else
    {
        globus_gridftp_server_control_attr_set_security(
            ftp_attr, GLOBUS_GRIDFTP_SERVER_LIBRARY_NONE);
    }

    res = globus_gridftp_server_control_attr_set_auth(
        ftp_attr, auth_func, NULL);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_resource(
        ftp_attr, globus_l_resource_cb, NULL);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_list(
        ftp_attr, list_cb, NULL);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_idle_time(
        ftp_attr, 900, 60);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_banner(
        ftp_attr, "This is 1 line of banner\nthis is line 2\nline 3");
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_message(
        ftp_attr, "Setting the message after login, 1 line\n");
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_set_log(
        ftp_attr, logging_func, GLOBUS_GRIDFTP_SERVER_CONTROL_LOG_ALL, NULL);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_data_functions(
        ftp_attr, active_connect, NULL, 
        passive_connect, NULL, data_destroy_cb, NULL);

    res = globus_gridftp_server_control_attr_add_send(
        ftp_attr, NULL, transfer, NULL);
    test_res(res, __LINE__);

    res = globus_gridftp_server_control_attr_add_recv(
        ftp_attr, NULL, transfer, NULL);
    test_res(res, __LINE__);

    res = globus_xio_handle_cntl(xio_handle, tcp_driver,
            GLOBUS_XIO_TCP_GET_HANDLE, &system_handle);
    test_res(res, __LINE__);

    globus_gsc_959_command_add(
        ftp_server,
        "SITE MINE",
        globus_gs_cmd_site,
        GLOBUS_GSC_COMMAND_POST_AUTH,
        2,
        2,
        "SITE <sp> MINE!!!!",
        NULL);

    globus_mutex_lock(&globus_l_mutex);
    {
        res = globus_gridftp_server_control_start(
            ftp_server, ftp_attr, system_handle, 
            globus_l_done_cb, FTP_USER_ARG);
        test_res(res, __LINE__);

        while(!globus_l_done)
        {
            globus_cond_wait(&globus_l_cond, &globus_l_mutex);
        }
    }
    globus_mutex_unlock(&globus_l_mutex);

    globus_xio_close(xio_handle, NULL);
    fprintf(stdout, "Ending...\n");
    res = globus_gridftp_server_control_attr_destroy(ftp_attr);
    test_res(res, __LINE__);
    res = globus_gridftp_server_control_destroy(ftp_server);
    test_res(res, __LINE__);

    globus_module_deactivate(GLOBUS_GRIDFTP_SERVER_CONTROL_MODULE);
    globus_module_deactivate(GLOBUS_XIO_MODULE);

    return 0;
}
int
main(
    int                                     argc,
    char **                                 argv)
{
    globus_xio_stack_t                      stack;
    globus_xio_stack_t                      mode_e_stack;
    globus_xio_handle_t                     xio_handle;
    globus_xio_server_t			    server;	
    globus_xio_attr_t                       attr = NULL;
    char *                                  cs = NULL;
    globus_result_t                         res;
    int                                     ctr;
    int					    num_streams = 1;
    globus_bool_t                           be_server = GLOBUS_FALSE;
    int                                     rc;
    char				    filename[FILE_NAME_LEN];
    FILE *				    fp;

    rc = globus_module_activate(GLOBUS_XIO_MODULE);
    globus_assert(rc == GLOBUS_SUCCESS);

    res = globus_xio_driver_load("mode_e", &mode_e_driver);
    test_res(res);
    res = globus_xio_driver_load("ordering", &ordering_driver);
    test_res(res);
    res = globus_xio_stack_init(&stack, NULL);
    test_res(res);
    res = globus_xio_stack_push_driver(stack, mode_e_driver);
    test_res(res);
    res = globus_xio_stack_push_driver(stack, ordering_driver);
    test_res(res);
    res = globus_xio_driver_load("tcp", &tcp_driver);
    test_res(res);                      
    res = globus_xio_stack_init(&mode_e_stack, NULL);
    test_res(res);
    res = globus_xio_stack_push_driver(mode_e_stack, tcp_driver);
    test_res(res);

    if (argc < 4)
    {
        help();
        exit(1);
    }
    test_res(globus_xio_attr_init(&attr));
    test_res(globus_xio_attr_cntl(
        attr,
        mode_e_driver,
        GLOBUS_XIO_MODE_E_SET_STACK,
        mode_e_stack));
    for(ctr = 1; ctr < argc; ctr++)
    {
        if(strcmp(argv[ctr], "-h") == 0)
        {
            help();
            return 0;
        }
        else if(strcmp(argv[ctr], "-c") == 0)
        {
	    if (argc < 5)
	    {
		help();
		exit(1);
	    }
            cs = argv[ctr + 1];
            ctr++;
        }
        else if(strcmp(argv[ctr], "-s") == 0)
        {
            be_server = GLOBUS_TRUE;
        }
        else if(strcmp(argv[ctr], "-p") == 0)
        {
            if (argc < 6)
            {
                help();
                exit(1);
            }
            port = atoi(argv[ctr+1]);
        /*    test_res(globus_xio_attr_cntl(
                attr,
                mode_e_driver,
                GLOBUS_XIO_MODE_E_APPLY_ATTR_CNTLS,
                attr_cntl_cb));*/
        }
        else if(strcmp(argv[ctr], "-P") == 0)
        {
	    if (argc < 6)
	    {
		help();
		exit(1);
	    }
            num_streams = atoi(argv[ctr+1]);
            test_res(globus_xio_attr_init(&attr));
            test_res(globus_xio_attr_cntl(
                attr,
                ordering_driver,
		GLOBUS_XIO_ORDERING_SET_MAX_READ_COUNT,
                num_streams));
            test_res(globus_xio_attr_cntl(
                attr,
                mode_e_driver,
                GLOBUS_XIO_MODE_E_SET_NUM_STREAMS,
                num_streams));
        } 
	else if(strcmp(argv[ctr], "-f") == 0)
	{
	    if (ctr + 1 < argc)
	    {
	        strcpy(filename, argv[ctr + 1]);
	    }
	    else	
	    {
		help();
		exit(1);
	    }
	}
    }
    
    if (!be_server && (!cs || !*cs))
    {
        help();
        exit(1);
    }
    
    if(be_server)
    {
	globus_size_t size = CHUNK_SIZE + 1;
	int i, nbytes;
	res = globus_xio_server_create(&server, attr, stack);
    	test_res(res);
        globus_xio_server_get_contact_string(server, &cs);
        fprintf(stdout, "Contact: %s\n", cs);   
	res = globus_xio_server_accept(&xio_handle, server);
    	test_res(res);
	res = globus_xio_open(xio_handle, NULL, attr);
	test_res(res);
 	fp = fopen(filename, "w");
        while(1)
        {
	    char * buffer;
	    buffer = (char *) globus_malloc(size);
            for (i=0; i<size; i++)
		buffer[i] = '\0';
            res = globus_xio_read(
                xio_handle,
                buffer,
                size - 1,
		1,
		&nbytes,
                NULL);
	    fputs(buffer, fp);
	    if (res != GLOBUS_SUCCESS)
		break;
	}
	res = globus_xio_close(xio_handle, NULL);
	test_res(res);
        res = globus_xio_server_close(server);
	test_res(res);
	res = globus_xio_driver_unload(mode_e_driver);
	test_res(res);
	rc = globus_module_deactivate(GLOBUS_XIO_MODULE);
	globus_assert(rc == GLOBUS_SUCCESS);
        
    }
    else
    {
	globus_size_t 			size = CHUNK_SIZE + 1;
        int	                        nbytes;
        int				i,x;
        res = globus_xio_handle_create(&xio_handle, stack);
        test_res(res);
        res = globus_xio_stack_destroy(stack);
        test_res(res);
   	res = globus_xio_open(xio_handle, cs, attr);
   	test_res(res);
        globus_mutex_init(&mutex, NULL);
        globus_cond_init(&cond, NULL);

        fp = fopen(filename, "r");
        globus_mutex_lock(&mutex);
        while(!feof(fp))
	{
            char * buffer;
	    buffer = (char *) globus_malloc(size);
 	    for (i = 0; i < size; i++)
                buffer[i] = '\0';
	    x = fread(buffer, CHUNK_SIZE, 1, fp);
            nbytes = strlen(buffer);
            res = globus_xio_register_write(
                xio_handle,
                buffer,
                nbytes,
                nbytes,
                NULL,
		write_cb,
		NULL);
            test_res(res); 
	    ++y;
        } 
        fclose(fp);
/*        test_res(globus_xio_data_descriptor_init(&dd, xio_handle));
        test_res(globus_xio_data_descriptor_cntl(
            dd,
            mode_e_driver,
            GLOBUS_XIO_MODE_E_SEND_EOD,
            GLOBUS_TRUE));
        res = globus_xio_write(
                xio_handle,
                buffer,
                nbytes,
                nbytes,
                &nbytes,
                NULL);
        test_res(res); */
        while(y)
        {
            globus_cond_wait(&mutex, &cond);
        }
        globus_mutex_unlock(&mutex);
	res = globus_xio_close(xio_handle, attr);
	test_res(res);
	res = globus_xio_driver_unload(mode_e_driver);
	test_res(res);
	res = globus_xio_driver_unload(ordering_driver);
	test_res(res);
	rc = globus_module_deactivate(GLOBUS_XIO_MODULE);
	globus_assert(rc == GLOBUS_SUCCESS);
        globus_mutex_destroy(&mutex);
        globus_cond_destroy(&cond);

    }
    return 0;
}
/*
 * Timeout test:
 *  -t server|client
 *     Configure the server or client to cause a timeout. If server is
 *     selected, then it will delay its part of the operation longer than the
 *     timeout value, causing the client to time out (and vice versa).
 *  -T timeout-in-ms
 *     Set the timeout value in ms
 *  -a
 *     Expect / cause the accept operation to delay longer than the timeout.
 *  -r
 *     Expect / cause a read operation to delay longer than the timeout.
 *
 */
int
main(
    int                                 argc,
    char *                              argv[])
{
    int                                 rc;
    char *                              contact = NULL;
    globus_result_t                     result;
    globus_l_timeout_info_t             client_timeout_info;
    globus_l_timeout_info_t             server_timeout_info;
    globus_reltime_t                    timeout;

    client_timeout_info.cause_timeout = GLOBUS_TRUE;
    client_timeout_info.expect_timeout = GLOBUS_FALSE;
    server_timeout_info.cause_timeout = GLOBUS_FALSE;
    server_timeout_info.expect_timeout = GLOBUS_TRUE;

    client_timeout_info.timeout_state =
        GLOBUS_XIO_OPERATION_TYPE_ACCEPT;
    server_timeout_info.timeout_state =
        GLOBUS_XIO_OPERATION_TYPE_ACCEPT;
    client_timeout_info.timeout = 1000;
    server_timeout_info.timeout = 1000;

    while ((rc = getopt(argc, argv, "t:T:arh")) != EOF)
    {
        switch (rc)
        {
            case 'h':
                usage(argv[0]);
                exit(0);
            case 't':
                if (strcmp(optarg, "client") == 0)
                {
                    client_timeout_info.cause_timeout = GLOBUS_TRUE;
                    client_timeout_info.expect_timeout = GLOBUS_FALSE;
                    server_timeout_info.cause_timeout = GLOBUS_FALSE;
                    server_timeout_info.expect_timeout = GLOBUS_TRUE;
                }
                else if (strcmp(optarg, "server") == 0)
                {
                    client_timeout_info.cause_timeout = GLOBUS_FALSE;
                    client_timeout_info.expect_timeout = GLOBUS_TRUE;
                    server_timeout_info.cause_timeout = GLOBUS_TRUE;
                    server_timeout_info.expect_timeout = GLOBUS_FALSE;
                }
                else
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'T':
                client_timeout_info.timeout = atoi(optarg);
                server_timeout_info.timeout = atoi(optarg);
                break;
            case 'a':
                client_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_ACCEPT;
                server_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_ACCEPT;
                break;
            case 'r':
                client_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_READ;
                server_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_READ;
                break;
            default:
                usage(argv[0]);
                exit(1);
        }
    }

    rc = http_test_initialize(
            &globus_l_tcp_driver,
            &globus_l_http_driver,
            &globus_l_http_stack);

    if (rc != GLOBUS_SUCCESS)
    {
        exit(2);
    }

    globus_mutex_init(&lock, NULL);
    globus_cond_init(&cond, NULL);

    GlobusTimeReltimeSet(timeout,
            0,
            (server_timeout_info.timeout * 1000));

    globus_xio_attr_init(&client_timeout_info.attr);
    globus_xio_attr_init(&server_timeout_info.attr);
    switch (server_timeout_info.timeout_state)
    {
        case GLOBUS_XIO_OPERATION_TYPE_ACCEPT:
            if (client_timeout_info.cause_timeout)
            {
                globus_xio_attr_cntl(
                        server_timeout_info.attr,
                        NULL,
                        GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT,
                        globus_l_timeout_callback,
                        &timeout,
                        NULL);
            }
            else
            {
                fprintf(stderr,
                        "Unable to handle server-caused accept timeout\n");
                exit(6);
            }
            break;

        case GLOBUS_XIO_OPERATION_TYPE_READ:
            if (client_timeout_info.cause_timeout)
            {
                globus_xio_attr_cntl(
                        server_timeout_info.attr,
                        NULL,
                        GLOBUS_XIO_ATTR_SET_TIMEOUT_READ,
                        globus_l_timeout_callback,
                        &timeout,
                        NULL);
            }
            else
            {
                globus_xio_attr_cntl(
                        client_timeout_info.attr,
                        NULL,
                        GLOBUS_XIO_ATTR_SET_TIMEOUT_READ,
                        globus_l_timeout_callback,
                        &timeout,
                        NULL);
            }
            break;

        default:
            fprintf(stderr, "Error: invalid timeout state\n");
            exit(3);
    }

    /* Set up client attributes */
    globus_xio_attr_cntl(
            client_timeout_info.attr,
            globus_l_http_driver,
            GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_METHOD,
            "POST");

    /* Modulate timeout state to causer's related state for delaying */
    if (client_timeout_info.cause_timeout)
    {
        switch (client_timeout_info.timeout_state)
        {
            case GLOBUS_XIO_OPERATION_TYPE_ACCEPT:
                client_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_OPEN;
                break;

            case GLOBUS_XIO_OPERATION_TYPE_READ:
                client_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_WRITE;
                break;

            case GLOBUS_XIO_OPERATION_TYPE_WRITE:
            case GLOBUS_XIO_OPERATION_TYPE_OPEN:
            case GLOBUS_XIO_OPERATION_TYPE_CLOSE:
            case GLOBUS_XIO_OPERATION_TYPE_FINISHED:
            case GLOBUS_XIO_OPERATION_TYPE_NONE:
            case GLOBUS_XIO_OPERATION_TYPE_DRIVER:
            case GLOBUS_XIO_OPERATION_TYPE_DD:
            case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT:
                fprintf(stderr,
                        "Error: unexpected state: %d\n",
                        client_timeout_info.state);
                exit(4);
        }
    }
    else
    {
        globus_assert(server_timeout_info.cause_timeout);
        switch (server_timeout_info.timeout_state)
        {
            case GLOBUS_XIO_OPERATION_TYPE_ACCEPT:
                fprintf(stderr,
                        "Invalid option (server-caused accept timeout)\n");
                exit(5);

            case GLOBUS_XIO_OPERATION_TYPE_READ:
                server_timeout_info.timeout_state =
                    GLOBUS_XIO_OPERATION_TYPE_WRITE;
                break;

            case GLOBUS_XIO_OPERATION_TYPE_WRITE:
            case GLOBUS_XIO_OPERATION_TYPE_OPEN:
            case GLOBUS_XIO_OPERATION_TYPE_CLOSE:
            case GLOBUS_XIO_OPERATION_TYPE_FINISHED:
            case GLOBUS_XIO_OPERATION_TYPE_NONE:
            case GLOBUS_XIO_OPERATION_TYPE_DRIVER:
            case GLOBUS_XIO_OPERATION_TYPE_DD:
            case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT:
                fprintf(stderr,
                        "Error: unexpected state: %d\n",
                        server_timeout_info.state);
                exit(4);
        }
    }

    /* create server */
    server_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT;
    server_timeout_info.handle = NULL;
    server_timeout_info.result = GLOBUS_SUCCESS;
    server_timeout_info.contact = NULL;
    result = globus_xio_server_create(
            &server_timeout_info.server,
            server_timeout_info.attr,
            globus_l_http_stack);

    result = globus_xio_server_get_contact_string(
            server_timeout_info.server,
            &contact);

    client_timeout_info.contact = globus_common_create_string("http://%s/%s",
            contact,
            "ok");

    /* create client handle */
    client_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_OPEN;
    client_timeout_info.handle = NULL;
    client_timeout_info.result = GLOBUS_SUCCESS;
    client_timeout_info.server = NULL;

    result = globus_xio_handle_create(
            &client_timeout_info.handle,
            globus_l_http_stack);

    /* oneshot to start server state machine */
    result = globus_callback_register_oneshot(
            NULL,
            &globus_i_reltime_zero,
            state_machine,
            &server_timeout_info);

    /* oneshot to start client state machine */
    result = globus_callback_register_oneshot(
            NULL,
            &globus_i_reltime_zero,
            state_machine,
            &client_timeout_info);

    /* wait for both state machines to terminate */
    globus_mutex_lock(&lock);
    while (client_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE &&
           server_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE)
    {
        globus_cond_wait(&cond, &lock);
    }
    globus_mutex_unlock(&lock);
    globus_mutex_destroy(&lock);

    globus_module_deactivate_all();

    return (client_timeout_info.result ||
            server_timeout_info.result ||
            client_timeout_info.expect_timeout ||
            server_timeout_info.expect_timeout);
}
示例#8
0
/*************************************************************************
 *  start
 *  -----
 *  This function is called when a new session is initialized, ie a user 
 *  connects to the server.  This hook gives the dsi an opportunity to
 *  set internal state that will be threaded through to all other
 *  function calls associated with this session.  And an opportunity to
 *  reject the user.
 *
 *  finished_info.info.session.session_arg should be set to an DSI
 *  defined data structure.  This pointer will be passed as the void *
 *  user_arg parameter to all other interface functions.
 * 
 *  NOTE: at nice wrapper function should exist that hides the details 
 *        of the finished_info structure, but it currently does not.  
 *        The DSI developer should jsut follow this template for now
 ************************************************************************/
static
void
globus_l_dsi_rest_start(
    globus_gfs_operation_t              op,
    globus_gfs_session_info_t *         session_info)
{
    globus_l_dsi_rest_handle_t         *dsi_rest_handle;
    globus_result_t                     result = GLOBUS_SUCCESS;

    dsi_rest_handle = malloc(sizeof(globus_l_dsi_rest_handle_t));
    if (dsi_rest_handle == NULL)
    {
        result = GlobusGFSErrorMemory("dsi_rest_handle");
        goto handle_malloc_fail;
    }

    result = globus_xio_driver_load("tcp", &dsi_rest_handle->tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto tcp_load_fail;
    }
    result = globus_xio_driver_load("http", &dsi_rest_handle->http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto http_load_fail;
    }
    result = globus_xio_stack_init(&dsi_rest_handle->server_stack, NULL);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_init_fail;
    }

    globus_mutex_init(&dsi_rest_handle->mutex, NULL);
    globus_cond_init(&dsi_rest_handle->cond, NULL);

    dsi_rest_handle->terminate = false;
    dsi_rest_handle->terminate_complete = false;

    result = globus_xio_stack_push_driver(
            dsi_rest_handle->server_stack,
            dsi_rest_handle->tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    result = globus_xio_stack_push_driver(
            dsi_rest_handle->server_stack,
            dsi_rest_handle->http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    globus_xio_attr_t attr;
    result = globus_xio_attr_init(&attr);

    globus_reltime_t delay;
    GlobusTimeReltimeSet(delay, 1,0);

    result = globus_xio_attr_cntl(
            attr,
            NULL,
            GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT,
            NULL,
            &delay,
            NULL);

    result = globus_xio_server_create(
            &dsi_rest_handle->xio_server,
            attr,
            dsi_rest_handle->server_stack);
    if (result != GLOBUS_SUCCESS)
    {
        goto server_create_fail;
    }
    result = globus_xio_server_get_contact_string(
            dsi_rest_handle->xio_server,
            &dsi_rest_handle->contact_string);
    if (result != GLOBUS_SUCCESS)
    {
        goto get_contact_fail;
    }
    globus_gridftp_server_get_config_string(
            op,
            &dsi_rest_handle->root);
    if (dsi_rest_handle->root == NULL)
    {
        result = GlobusGFSErrorMemory("root");
        goto get_root_fail;
    }
    globus_thread_create(
            &dsi_rest_handle->server_thread,
            NULL,
            globus_l_dsi_rest_thread,
            dsi_rest_handle);

    if (result != GLOBUS_SUCCESS)
    {
get_root_fail:
        free(dsi_rest_handle->contact_string);
get_contact_fail:
        globus_xio_server_close(dsi_rest_handle->xio_server);
server_create_fail:
stack_push_fail:
        globus_xio_stack_destroy(dsi_rest_handle->server_stack);
stack_init_fail:
        globus_xio_driver_unload(dsi_rest_handle->http_driver);
http_load_fail:
        globus_xio_driver_unload(dsi_rest_handle->tcp_driver);
tcp_load_fail:
handle_malloc_fail:
        free(dsi_rest_handle);
        dsi_rest_handle = NULL;
    }

    globus_gridftp_server_finished_session_start(
            op,
            result,
            dsi_rest_handle,
            NULL,
            NULL);
}