globus_result_t gfork_i_make_xio_handle( globus_xio_handle_t * xio_handle, int fd) { globus_result_t res; globus_xio_attr_t attr; globus_xio_handle_t handle; res = globus_xio_attr_init(&attr); if(res != GLOBUS_SUCCESS) { goto error_copy; } res = globus_xio_attr_cntl(attr, gfork_i_file_driver, GLOBUS_XIO_FILE_SET_HANDLE, fd); if(res != GLOBUS_SUCCESS) { goto error_attr; } res = globus_xio_handle_create(&handle, gfork_i_file_stack); if(res != GLOBUS_SUCCESS) { goto error_create; } /* the way the stack is set up xio should not poll. */ res = globus_xio_open( handle, NULL, attr); if(res != GLOBUS_SUCCESS) { goto error_open; } globus_xio_attr_destroy(attr); *xio_handle = handle; return GLOBUS_SUCCESS; error_open: error_create: error_attr: globus_xio_attr_destroy(attr); error_copy: return res; }
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; char * subject; globus_result_t res; char line[LINE_LEN]; globus_bool_t done = GLOBUS_FALSE; globus_size_t nbytes; globus_xio_attr_t attr; int len; if(argc < 2) { fprintf(stderr, "arg error: <contact string> <subject>\n"); return 1; } 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__); cs = argv[argc - 1]; subject = argv[argc - 2]; res = globus_xio_handle_create(&xio_handle, stack); test_res(res, __LINE__); res = globus_xio_attr_init(&attr); test_res(res, __LINE__); res = globus_xio_attr_cntl(attr, ftp_driver, GLOBUS_XIO_GSSAPI_ATTR_TYPE_SUBJECT, subject); test_res(res, __LINE__); res = globus_xio_open(xio_handle, cs, attr); test_res(res, __LINE__); while(!done) { if(fgets(line, LINE_LEN, stdin) == NULL) { done = GLOBUS_TRUE; } else { len = strlen(line); line[len] = '\r'; len++; line[len] = '\n'; len++; res = globus_xio_write( xio_handle, line, len, len, &nbytes, NULL); test_res(res, __LINE__); } } globus_xio_close(xio_handle, NULL); globus_module_deactivate(GLOBUS_XIO_MODULE); return 0; }
int space_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_result_t res; globus_xio_attr_t attr; globus_condattr_t condattr; globus_l_closed = GLOBUS_FALSE; globus_l_close_called = GLOBUS_FALSE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); 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); globus_callback_space_init(&globus_l_space, NULL); globus_condattr_init(&condattr); globus_condattr_setspace(&condattr, globus_l_space); globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, &condattr); res = globus_xio_handle_create(&handle, stack); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_SPACE, globus_l_space); res = globus_xio_register_open( handle, "whatever", attr, open_cb, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, 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); test_common_end(); globus_callback_space_destroy(globus_l_space); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); 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; }
void *mdsip_connect(char *host) { static int activated=0; int status; static globus_xio_stack_t stack_tcp; static globus_xio_stack_t stack_gsi; static globus_xio_driver_t tcp_driver; static globus_xio_driver_t gsi_driver; globus_result_t result; globus_xio_handle_t xio_handle; globus_xio_attr_t attr; char *contact_string; int is_gsi; mdsip_message_t *m; if (activated == 0) { result = globus_module_activate(GLOBUS_XIO_MODULE); mdsip_test_status(0,result,"mdsip_connect globus_module_activate"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_driver_load("tcp",&tcp_driver); mdsip_test_status(0,result,"mdsip_connect load tcp driver"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_driver_load("gsi",&gsi_driver); mdsip_test_status(0,result,"mdsip_connect load gsi driver"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_stack_init(&stack_tcp, NULL); mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_init"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_stack_init(&stack_gsi, NULL); mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_init"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_stack_push_driver(stack_tcp, tcp_driver); mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_stack_push_driver(stack_gsi, tcp_driver); mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_stack_push_driver(stack_gsi, gsi_driver); mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver"); if (result != GLOBUS_SUCCESS) return 0; activated = 1; } if (host == NULL || strlen(host) == 0) return 0; is_gsi = host[0] == '_'; result = globus_xio_handle_create(&xio_handle, is_gsi ? stack_gsi : stack_tcp); mdsip_test_status(0,result,"mdsip_connect globus_xio_handle_create"); if (result != GLOBUS_SUCCESS) return 0; contact_string = strcpy((char *)malloc(strlen(host)+10),&host[is_gsi ? 1 : 0]); if (strstr(contact_string,":") == NULL) strcat(contact_string,is_gsi ? ":8200" : ":8000"); result = globus_xio_attr_init(&attr); mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_init"); if (result != GLOBUS_SUCCESS) return 0; if (is_gsi) { result = globus_xio_attr_cntl(attr,gsi_driver,GLOBUS_XIO_GSI_SET_DELEGATION_MODE, GLOBUS_XIO_GSI_DELEGATION_MODE_FULL); mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_cntl"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_attr_cntl(attr, gsi_driver, GLOBUS_XIO_GSI_SET_AUTHORIZATION_MODE, GLOBUS_XIO_GSI_HOST_AUTHORIZATION); mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_cntl"); if (result != GLOBUS_SUCCESS) return 0; } result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_SNDBUF,MDSIP_SNDBUF); mdsip_test_status(0,result,"mdsip_connect SET_SNDBUF"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_RCVBUF,MDSIP_RCVBUF); mdsip_test_status(0,result,"mdsip_connect SET_RCVBUF"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_NODELAY,GLOBUS_TRUE); mdsip_test_status(0,result,"mdsip_connect SET_NODELAY"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_KEEPALIVE,GLOBUS_TRUE); mdsip_test_status(0,result,"mdsip_connect SET_KEEPALIVE"); if (result != GLOBUS_SUCCESS) return 0; result = globus_xio_open(xio_handle, contact_string, attr); mdsip_test_status(0,result,"mdsip_connect globus_xio_open"); if (result != GLOBUS_SUCCESS) xio_handle = 0; else { #ifdef _WIN32 static char user[128]; int bsize=128; char *user_p = GetUserName(user,&bsize) ? user : "******"; #elif __MWERKS__ static char user[128]; int bsize=128; char *user_p = "Macintosh User"; #elif __APPLE__ char *user_p; struct passwd *pwd; pwd = getpwuid(geteuid()); user_p = pwd->pw_name; #else char *user_p; #ifdef HAVE_VXWORKS_H user_p = "vxWorks"; #else user_p = (getpwuid(geteuid()))->pw_name; #endif #endif m = malloc(sizeof(mdsip_message_header_t)+strlen(user_p)+1); memset(m,0,sizeof(mdsip_message_header_t)); m->h.length=strlen(user_p); m->h.msglen=sizeof(mdsip_message_header_t)+m->h.length; m->h.dtype=DTYPE_CSTRING; m->h.status=0; m->h.ndims=0; strcpy(m->bytes,user_p); mdsip_send_message(xio_handle,m,0); free(m); m = NULL; m = mdsip_get_message(xio_handle,&status); if (!(status & 1)) { fprintf(stderr,"ERROR: mdsip_connect\n"); return NULL; } else { if (!(m->h.status & 1)) { fprintf(stderr,"ERROR: mdsip_connect - Access Denied\n"); globus_xio_close(xio_handle,NULL); return NULL; } } if (m != NULL) free(m); } return (void *)xio_handle; }
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; }
static globus_result_t gfs_l_dynclient_xio_setup() { globus_result_t result; globus_xio_attr_t attr; globus_xio_stack_t stack; result = globus_xio_attr_init(&attr); if(result != GLOBUS_SUCCESS) { goto error_attr_init; } result = globus_xio_stack_init(&stack, NULL); if(result != GLOBUS_SUCCESS) { goto error_stack_init; } result = globus_xio_driver_load("tcp", &g_tcp_driver); if(result != GLOBUS_SUCCESS) { goto error_tcp; } result = globus_xio_stack_push_driver(stack, g_tcp_driver); if(result != GLOBUS_SUCCESS) { goto error_tcp_push; } if(g_use_gsi) { result = globus_xio_driver_load("gsi", &g_gsi_driver); if(result != GLOBUS_SUCCESS) { goto error_gsi; } result = globus_xio_stack_push_driver(stack, g_gsi_driver); if(result != GLOBUS_SUCCESS) { goto error_gsi_push; } } result = globus_xio_handle_create(&g_xio_handle, stack); if(result != GLOBUS_SUCCESS) { goto error_handle; } return GLOBUS_SUCCESS; error_handle: error_gsi_push: error_gsi: error_tcp_push: error_tcp: error_stack_init: error_attr_init: return result; }
/* * 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); }
int main( int argc, char ** argv) { globus_xio_driver_t driver; globus_xio_stack_t stack; globus_xio_handle_t xio_handle; char * cs; globus_result_t res; char line[LINE_LEN]; int ctr; globus_bool_t done = GLOBUS_FALSE; globus_size_t nbytes; if(argc < 2) { help(); return 1; } globus_module_activate(GLOBUS_XIO_MODULE); globus_xio_stack_init(&stack, NULL); for(ctr = 1; ctr < argc - 1; ctr++) { if(strcmp(argv[ctr], "-h") == 0) { help(); return 0; } else if(strcmp(argv[ctr], "-D") == 0 && ctr + 1 < argc - 1) { ctr++; globus_xio_driver_load(argv[ctr], &driver); globus_xio_stack_push_driver(stack, driver); } } cs = argv[argc - 1]; res = globus_xio_handle_create(&xio_handle, stack); test_res(res); globus_xio_open(xio_handle, cs, NULL); while(!done) { if(fgets(line, LINE_LEN, stdin) == NULL) { done = GLOBUS_TRUE; } else { int len; len = strlen(line); res = globus_xio_write( xio_handle, line, len, len, &nbytes, NULL); test_res(res); } } globus_xio_close(xio_handle, NULL); globus_module_activate(GLOBUS_XIO_MODULE); return 0; }
static int globus_l_seg_stdout_activate(void) { globus_result_t result; globus_xio_attr_t out_attr; globus_xio_attr_t in_attr; int rc; globus_l_seg_output_handle = NULL; globus_l_seg_input_handle = NULL; globus_l_seg_file_stack = NULL; globus_l_seg_file_driver = NULL; globus_l_seg_timestamp = 0; globus_l_seg_write_registered = GLOBUS_FALSE; globus_l_seg_shutdown = 0; rc = globus_module_activate(GLOBUS_COMMON_MODULE); if (rc != GLOBUS_SUCCESS) { goto error; } rc = globus_module_activate(GLOBUS_SCHEDULER_EVENT_GENERATOR_MODULE); if (rc != GLOBUS_SUCCESS) { goto deactivate_common_error; } rc = globus_fifo_init(&globus_l_seg_buffers); if (rc != GLOBUS_SUCCESS) { goto deactivate_seg_error; } rc = globus_module_activate(GLOBUS_XIO_MODULE); if (rc != GLOBUS_SUCCESS) { goto destroy_fifo_error; } result = globus_xio_driver_load("file", &globus_l_seg_file_driver); if (result != GLOBUS_SUCCESS) { goto deactivate_xio_error; } result = globus_xio_stack_init(&globus_l_seg_file_stack, NULL); if (result != GLOBUS_SUCCESS) { goto unload_driver_error; } result = globus_xio_stack_push_driver(globus_l_seg_file_stack, globus_l_seg_file_driver); if (result != GLOBUS_SUCCESS) { goto destroy_stack_error; } result = globus_xio_attr_init(&out_attr); if (result != GLOBUS_SUCCESS) { goto destroy_stack_error; } result = globus_xio_attr_cntl( out_attr, globus_l_seg_file_driver, GLOBUS_XIO_FILE_SET_FLAGS, GLOBUS_XIO_FILE_WRONLY); if (result != GLOBUS_SUCCESS) { goto destroy_out_attr_error; } result = globus_xio_attr_cntl( out_attr, globus_l_seg_file_driver, GLOBUS_XIO_FILE_SET_HANDLE, fileno(stdout)); if (result != GLOBUS_SUCCESS) { goto destroy_out_attr_error; } result = globus_xio_attr_init(&in_attr); if (result != GLOBUS_SUCCESS) { goto destroy_out_attr_error; } result = globus_xio_attr_cntl( in_attr, globus_l_seg_file_driver, GLOBUS_XIO_FILE_SET_FLAGS, GLOBUS_XIO_FILE_RDONLY); if (result != GLOBUS_SUCCESS) { goto destroy_in_attr_error; } result = globus_xio_attr_cntl( in_attr, globus_l_seg_file_driver, GLOBUS_XIO_FILE_SET_HANDLE, fileno(stdin)); if (result != GLOBUS_SUCCESS) { goto destroy_in_attr_error; } result = globus_xio_handle_create( &globus_l_seg_output_handle, globus_l_seg_file_stack); if (result != GLOBUS_SUCCESS) { goto destroy_in_attr_error; } result = globus_xio_open(globus_l_seg_output_handle, "", out_attr); if (result != GLOBUS_SUCCESS) { goto close_out_handle_error; } result = globus_xio_handle_create( &globus_l_seg_input_handle, globus_l_seg_file_stack); if (result != GLOBUS_SUCCESS) { goto close_out_handle_error; } result = globus_xio_open(globus_l_seg_input_handle, "", in_attr); if (result != GLOBUS_SUCCESS) { goto close_in_handle_error; } rc = globus_mutex_init(&globus_l_seg_mutex, NULL); if (rc != GLOBUS_SUCCESS) { goto close_in_handle_error; } rc = globus_cond_init(&globus_l_seg_cond, NULL); if (rc != GLOBUS_SUCCESS) { goto destroy_mutex_error; } result = globus_xio_register_read( globus_l_seg_input_handle, globus_l_seg_input_buffer, sizeof(globus_l_seg_input_buffer), 1, NULL, globus_l_xio_read_eof_callback, NULL); if (result != GLOBUS_SUCCESS) { goto destroy_cond_error; } globus_xio_attr_destroy(in_attr); globus_xio_attr_destroy(out_attr); return 0; destroy_cond_error: globus_cond_destroy(&globus_l_seg_cond); destroy_mutex_error: globus_mutex_destroy(&globus_l_seg_mutex); close_in_handle_error: globus_xio_close(globus_l_seg_input_handle, NULL); close_out_handle_error: globus_xio_close(globus_l_seg_output_handle, NULL); destroy_in_attr_error: globus_xio_attr_destroy(in_attr); destroy_out_attr_error: globus_xio_attr_destroy(out_attr); destroy_stack_error: globus_xio_stack_destroy(globus_l_seg_file_stack); unload_driver_error: globus_xio_driver_unload(globus_l_seg_file_driver); deactivate_xio_error: globus_module_deactivate(GLOBUS_XIO_MODULE); destroy_fifo_error: globus_fifo_destroy(&globus_l_seg_buffers); deactivate_seg_error: globus_module_deactivate(GLOBUS_SCHEDULER_EVENT_GENERATOR_MODULE); deactivate_common_error: globus_module_deactivate(GLOBUS_COMMON_MODULE); error: return 1; }
int cancel_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_result_t res; globus_xio_attr_t attr; int opt_offset; int secs; int usecs; globus_l_closed = GLOBUS_FALSE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); 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); GlobusTimeReltimeGet(globus_l_test_info.delay, secs, usecs); if(secs == 0 && usecs < USEC_THRESHHOLD) { fprintf(stderr, "ERROR: delay time must be at least %d usecs.\n", USEC_THRESHHOLD); return 1; } globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, NULL); 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, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); if(strcmp(argv[argc-1], "O") == 0) { res = globus_xio_handle_cancel_operations( handle, GLOBUS_XIO_CANCEL_OPEN); } 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); test_common_end(); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); return 0; }
int timeout_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_result_t res; globus_xio_attr_t attr; int secs; int usecs; globus_reltime_t delay; int div = 5; globus_l_closed = GLOBUS_FALSE; globus_l_timeout = GLOBUS_TRUE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); 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); GlobusTimeReltimeGet(globus_l_test_info.delay, secs, usecs); if(secs == 0 && usecs < USEC_THRESHHOLD) { fprintf(stderr, "ERROR: delay time must be at least %d usecs.\n", USEC_THRESHHOLD); return 1; } GlobusTimeReltimeSet(delay, secs/div, usecs/div); /* set up timeouts */ if(strcmp(argv[argc-1], "O") == 0) { res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_OPEN, timeout_cb, &delay, NULL); } else if(strcmp(argv[argc-1], "D") == 0) { res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_READ, timeout_cb, &delay, NULL); res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_WRITE, timeout_cb, &delay, NULL); } else if(strcmp(argv[argc-1], "C") == 0) { res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_CLOSE, timeout_cb, &delay, NULL); } else { fprintf(stderr, "ERROR: No timeout registered.\n"); return 1; } test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, NULL); 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, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, 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); /* run again with an ignored time out */ globus_l_closed = GLOBUS_FALSE; globus_l_timeout = GLOBUS_FALSE; 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, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, 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); /* shut it down */ globus_xio_attr_destroy(attr); globus_xio_stack_destroy(stack); test_common_end(); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); return 0; }
globus_result_t globus_usage_stats_handle_init( globus_usage_stats_handle_t * handle, uint16_t code, uint16_t version, const char * targets) { globus_result_t result = GLOBUS_SUCCESS; #ifndef TARGET_ARCH_ARM globus_i_usage_stats_handle_t * new_handle; char * targets_env; globus_list_t * targets_list; char * contact; globus_sockaddr_t addr; int host[16]; int count; char hostname[255]; int rc = 0; int i; new_handle = globus_calloc(1, sizeof(globus_i_usage_stats_handle_t)); if(!new_handle) { return globus_error_put( globus_error_construct_error( GLOBUS_USAGE_MODULE, NULL, GLOBUS_USAGE_STATS_ERROR_TYPE_OOM, __FILE__, _globus_func_name, __LINE__, "Out of memory")); } new_handle->optout = getenv("GLOBUS_USAGE_OPTOUT"); if(new_handle->optout) { *handle = new_handle; return GLOBUS_SUCCESS; } globus_mutex_init(&new_handle->mutex, NULL); new_handle->inuse = GLOBUS_FALSE; new_handle->code = htons(code); new_handle->version = htons(version); memset(new_handle->data, 0, PACKET_SIZE); memcpy(new_handle->data + new_handle->data_length, (void *)&new_handle->code, 2); new_handle->data_length += 2; memcpy(new_handle->data + new_handle->data_length, (void *)&new_handle->version, 2); new_handle->data_length += 2; rc = globus_libc_gethostaddr(&addr); if(rc != 0) { return globus_error_put( globus_error_construct_error( GLOBUS_USAGE_MODULE, NULL, GLOBUS_USAGE_STATS_ERROR_TYPE_UNKNOWN_HOSTNAME, __FILE__, _globus_func_name, __LINE__, "Unable to get hostaddr.")); } result = globus_libc_addr_to_contact_string( &addr, GLOBUS_LIBC_ADDR_NUMERIC, &contact); if(result != GLOBUS_SUCCESS) { return result; } result = globus_libc_contact_string_to_ints( contact, host, &count, NULL); if(result != GLOBUS_SUCCESS) { return result; } globus_libc_free(contact); if(count == 4) { memset(new_handle->data + new_handle->data_length, 0, 12); new_handle->data_length += 12; } for (i = 0; i < count; i++) { new_handle->data[new_handle->data_length++] = (unsigned char) host[i]; } /* timestamp will go here */ new_handle->data_length += 4; if(globus_libc_gethostname(hostname, 255) == 0) { new_handle->data_length += sprintf((char *) new_handle->data + new_handle->data_length, "HOSTNAME=%s", hostname); } new_handle->header_length = new_handle->data_length; if(targets) { globus_l_usage_stats_split_targets(targets, &new_handle->targets); } else if((targets_env = getenv("GLOBUS_USAGE_TARGETS")) != NULL) { globus_l_usage_stats_split_targets( targets_env, &new_handle->targets); } else { globus_l_usage_stats_split_targets( GLOBUS_L_USAGE_STATS_DEFAULT_TARGETS, &new_handle->targets); } result = globus_xio_handle_create( &new_handle->xio_handle, globus_l_usage_stats_stack); if(result != GLOBUS_SUCCESS) { return result; } result = globus_xio_open( new_handle->xio_handle, NULL, NULL); if(result != GLOBUS_SUCCESS) { return result; } targets_list = new_handle->targets; while(targets_list) { globus_xio_data_descriptor_t * dd; dd = (globus_xio_data_descriptor_t *) globus_malloc( sizeof(globus_xio_data_descriptor_t)); result = globus_xio_data_descriptor_init( dd, new_handle->xio_handle); if(result != GLOBUS_SUCCESS) { return result; } result = globus_xio_data_descriptor_cntl( *dd, globus_l_usage_stats_udp_driver, GLOBUS_XIO_UDP_SET_CONTACT, (char *)globus_list_first(targets_list)); if(result != GLOBUS_SUCCESS) { goto exit; } globus_list_insert(&new_handle->xio_desc_list, dd); targets_list = globus_list_rest(targets_list); } *handle = new_handle; return GLOBUS_SUCCESS; exit: #endif return result; }