static int globus_l_seg_stdout_deactivate(void) { globus_mutex_lock(&globus_l_seg_mutex); globus_l_seg_shutdown = 1; if (globus_l_seg_write_registered) { while (globus_l_seg_shutdown == 1) { globus_cond_wait(&globus_l_seg_mutex, &globus_l_seg_cond); } } globus_fifo_destroy(&globus_l_seg_buffers); globus_mutex_unlock(&globus_l_seg_mutex); globus_xio_close(globus_l_seg_output_handle, NULL); globus_xio_close(globus_l_seg_input_handle, NULL); globus_mutex_destroy(&globus_l_seg_mutex); globus_cond_destroy(&globus_l_seg_cond); globus_module_deactivate(GLOBUS_XIO_MODULE); globus_module_deactivate(GLOBUS_SCHEDULER_EVENT_GENERATOR_MODULE); globus_module_deactivate(GLOBUS_COMMON_MODULE); return 0; }
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) { unsigned char buffer[LINE_LEN]; globus_size_t nbytes; globus_result_t res; globus_xio_attr_t attr; char * opts = NULL; if(argc < 2) { fprintf(stderr, "usage: %s url\n", argv[0]); return -1; } if(argc > 2) { opts = argv[2]; } globus_module_activate(GLOBUS_XIO_MODULE); globus_xio_attr_init(&attr); globus_xio_handle_t myhandle; res = globus_xio_handle_create_from_url( &myhandle, argv[1], attr, opts); test_res(res, __LINE__); res = globus_xio_open(myhandle, argv[1], attr); test_res(res, __LINE__); while(res == GLOBUS_SUCCESS) { res = globus_xio_read(myhandle, buffer, LINE_LEN, 1, &nbytes, NULL); buffer[nbytes] = '\0'; printf("%s", buffer); } if(!globus_xio_error_is_eof(res)) { printf("Error before EOF\n"); test_res(res, __LINE__); } globus_xio_close(myhandle, NULL); globus_xio_attr_destroy(attr); globus_module_deactivate(GLOBUS_XIO_MODULE); return 0; }
void globus_usage_stats_handle_destroy( globus_usage_stats_handle_t vhandle) { #ifndef TARGET_ARCH_ARM globus_i_usage_stats_handle_t * handle = (globus_i_usage_stats_handle_t *) vhandle; if(handle) { if(handle->targets) { globus_list_destroy_all(handle->targets, globus_libc_free); } if(handle->xio_desc_list) { globus_xio_data_descriptor_t * dd; while (!globus_list_empty (handle->xio_desc_list)) { if((dd = globus_list_remove( &handle->xio_desc_list, handle->xio_desc_list)) != NULL) { globus_xio_data_descriptor_destroy(*dd); globus_free(dd); } } } if(handle->xio_handle) { globus_xio_close(handle->xio_handle, NULL); } globus_mutex_destroy(&handle->mutex); globus_free(handle); } #endif }
static void data_cb( globus_xio_handle_t handle, globus_result_t result, globus_byte_t * buffer, globus_size_t len, globus_size_t nbytes, globus_xio_data_descriptor_t data_desc, void * user_arg) { globus_result_t res; globus_mutex_lock(&globus_l_mutex); { res = globus_xio_close( handle, NULL); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); globus_l_closed = GLOBUS_TRUE; globus_cond_signal(&globus_l_cond); } globus_mutex_unlock(&globus_l_mutex); }
mdsip_message_t *mdsip_get_message(void *io_handle, int *status) { mdsip_message_header_t header; globus_result_t result; mdsip_message_t *msg = NULL; int msglen = 0; globus_size_t nbytes; *status = 0; result = globus_xio_read(io_handle, (globus_byte_t *)&header, sizeof(header),sizeof(header),&nbytes, NULL); mdsip_test_status(io_handle,result,"mdsip_get_message, globus_xio_read"); if (result != GLOBUS_SUCCESS) return NULL; if ( Endian(header.client_type) != Endian(mdsip_client_type()) ) mdsip_flip_header(&header); if ( CType(header.client_type) > CRAY_CLIENT || header.ndims > MAX_DIMS || header.msglen < sizeof(header)) { globus_xio_close(io_handle,NULL); fprintf(stderr,"ERROR: mdsip_get_message, bad message header - closing connection\n"); return NULL; } msglen = header.msglen; msg = malloc(header.msglen); msg->h = header; if (msglen > sizeof(header)) { result = globus_xio_read(io_handle,msg->bytes,msglen - sizeof(header),msglen - sizeof(header),&nbytes,NULL); mdsip_test_status(io_handle,result,"mdsip_get_message, globus_xio_read"); } if (result != GLOBUS_SUCCESS) { free(msg); return NULL; } if (Endian(header.client_type) != Endian(mdsip_client_type())) mdsip_flip_data(msg); *status = 1; return msg; }
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; size_t nbytes; globus_xio_data_descriptor_t descriptor; 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; 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; } for (i = 0; i < info->iterations; i++) { result = globus_xio_write( handle, info->buffer, info->size, info->size, &nbytes, NULL); if (result == GLOBUS_SUCCESS) { if (nbytes != info->size) { fprintf(stderr, "Didn't write all I expected.\n"); } } else { fprintf(stderr, "Error writing data: %s\n", globus_object_printable_to_string(globus_error_peek(result))); } } globus_xio_handle_cntl( handle, info->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY); /* READ RESPONSE */ result = globus_xio_data_descriptor_init(&descriptor, handle); if (result != GLOBUS_SUCCESS) { rc = 51; goto close_exit; } result = globus_xio_read( handle, info->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_xio_read( handle, info->buffer, info->size, 1, &nbytes, NULL); if (result && !http_is_eof(result)) { fprintf(stderr, "Error reading eof from http: %s\n", globus_error_print_friendly(globus_error_get(result))); } close_exit: globus_xio_close(handle, NULL); globus_utp_stop_timer(timer); error_exit: return rc; }
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 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; }
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_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; }
static globus_result_t globus_l_gfork_child_start( gfork_child_handle_t * out_handle, const char * in_env_suffix, globus_gfork_open_func_t open_cb, globus_gfork_closed_func_t close_cb, globus_gfork_incoming_cb_t incoming_cb, globus_gfork_error_func_t error_cb, void * user_arg, globus_bool_t master) { globus_result_t result; gfork_i_lib_handle_t * handle; char * env; char * env_suffix; int read_fd; int write_fd; handle = (gfork_i_lib_handle_t *) globus_calloc(1, sizeof(gfork_i_lib_handle_t)); handle->state = GFORK_STATE_OPEN; handle->open_cb = open_cb; handle->close_cb = close_cb; handle->error_cb = error_cb; handle->incoming_cb = incoming_cb; handle->user_arg = user_arg; handle->master = master; globus_mutex_init(&handle->mutex, NULL); globus_fifo_init(&handle->write_q); if(in_env_suffix == NULL) { env_suffix = ""; } else { env_suffix = (char *) in_env_suffix; } env = globus_common_create_string("%s%s", GFORK_CHILD_READ_ENV, env_suffix); result = gfork_l_get_env_fd(env, &read_fd); globus_free(env); if(result != GLOBUS_SUCCESS) { goto error_read_env; } env = globus_common_create_string("%s%s",GFORK_CHILD_WRITE_ENV,env_suffix); result = gfork_l_get_env_fd(env, &write_fd); globus_free(env); if(result != GLOBUS_SUCCESS) { goto error_write_env; } result = gfork_i_make_xio_handle(&handle->read_xio, read_fd); if(result != GLOBUS_SUCCESS) { goto error_read_convert; } result = gfork_i_make_xio_handle(&handle->write_xio, write_fd); if(result != GLOBUS_SUCCESS) { goto error_write_convert; } globus_mutex_lock(&handle->mutex); { result = globus_xio_register_read( handle->read_xio, (globus_byte_t *)&handle->header, sizeof(gfork_i_msg_header_t), sizeof(gfork_i_msg_header_t), NULL, gfork_l_child_read_header_cb, handle); if(result != GLOBUS_SUCCESS) { goto error_post; } } globus_mutex_unlock(&handle->mutex); *out_handle = handle; return GLOBUS_SUCCESS; error_post: gfork_l_child_error(handle, result); globus_mutex_unlock(&handle->mutex); error_write_convert: globus_xio_close(handle->read_xio, NULL); error_read_convert: error_write_env: error_read_env: globus_fifo_destroy(&handle->write_q); globus_mutex_destroy(&handle->mutex); globus_free(handle); return result; }
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; }
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; }
static void * globus_l_dsi_rest_thread( void *arg) { globus_l_dsi_rest_handle_t *dsi_rest_handle = arg; globus_xio_data_descriptor_t descriptor; size_t buf_size = 256; unsigned char *buf = malloc(buf_size); globus_size_t nbytes; char *encoded_uri; globus_mutex_lock(&dsi_rest_handle->mutex); while (!dsi_rest_handle->terminate) { char *method; char *uri; globus_xio_http_version_t http_version; globus_hashtable_t headers; globus_result_t result; globus_mutex_unlock(&dsi_rest_handle->mutex); result = globus_xio_server_accept( &dsi_rest_handle->xio_handle, dsi_rest_handle->xio_server); globus_mutex_lock(&dsi_rest_handle->mutex); if (result != GLOBUS_SUCCESS) { continue; } result = globus_xio_open( dsi_rest_handle->xio_handle, NULL, NULL); if (result != GLOBUS_SUCCESS) { goto end_this_socket; } result = globus_xio_data_descriptor_init(&descriptor, dsi_rest_handle->xio_handle); if (result != GLOBUS_SUCCESS) { goto end_this_socket; } result = globus_xio_read( dsi_rest_handle->xio_handle, buf, 0, 0, &nbytes, descriptor); if (result != GLOBUS_SUCCESS) { goto end_this_socket; } result = globus_xio_data_descriptor_cntl( descriptor, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_GET_REQUEST, &method, &uri, &http_version, &headers); globus_dsi_rest_uri_escape(uri, &encoded_uri); char *uripath = globus_common_create_string("%s/%s", dsi_rest_handle->root, encoded_uri); if (strcmp(method, "GET") == 0) { int fd; fd = open(uripath, O_RDONLY); if (fd < 0) { globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Connection", "Close"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Content-Length", "0"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE, 404); } else { globus_size_t read_amt = 0; globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Connection", "Close"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE, 200); do { read_amt = read(fd, buf, buf_size); if (read_amt > 0) { globus_size_t written_amt = 0; while (written_amt < read_amt) { globus_size_t this_write; result = globus_xio_write( dsi_rest_handle->xio_handle, buf+written_amt, read_amt-written_amt, read_amt-written_amt, &this_write, NULL); if (this_write > 0) { written_amt += this_write; } else if (result != GLOBUS_SUCCESS) { break; } } } } while (read_amt > 0); close(fd); } } else { int fd = open(uripath, O_WRONLY|O_CREAT, 0700); if (fd < 0) { globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE, 500); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Content-Length", "0"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Connection", "Close"); } else { off_t total_written=0; if (nbytes > 0) { globus_size_t written_amt = 0; while (written_amt < nbytes) { globus_size_t this_write; this_write = write(fd, buf+written_amt, nbytes-written_amt); if (this_write > 0) { written_amt += this_write; total_written += this_write; } } } do { result = globus_xio_read( dsi_rest_handle->xio_handle, buf, buf_size, 1, &nbytes, NULL); if (nbytes > 0) { globus_size_t written_amt = 0; while (written_amt < nbytes) { globus_size_t this_write; this_write = write(fd, buf+written_amt, nbytes-written_amt); if (this_write > 0) { written_amt += this_write; total_written += this_write; } } } if (result != GLOBUS_SUCCESS) { if (globus_error_match( globus_error_peek(result), GLOBUS_XIO_MODULE, GLOBUS_XIO_ERROR_EOF) || globus_xio_driver_error_match( dsi_rest_handle->http_driver, globus_error_peek(result), GLOBUS_XIO_HTTP_ERROR_EOF)) { result = GLOBUS_SUCCESS; break; } else { globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE, 500); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Content-Length", "0"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Connection", "Close"); goto xio_error; } } } while (nbytes > 0); close(fd); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE, 204); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Content-Length", "0"); globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER, "Connection", "Close"); } } xio_error: free(uripath); result = globus_xio_handle_cntl( dsi_rest_handle->xio_handle, dsi_rest_handle->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY); end_this_socket: result = globus_xio_close( dsi_rest_handle->xio_handle, NULL); dsi_rest_handle->xio_handle = NULL; } dsi_rest_handle->terminate_complete = true; globus_cond_signal(&dsi_rest_handle->cond); globus_mutex_unlock(&dsi_rest_handle->mutex); return NULL; }
int main( int argc, char ** argv) { globus_result_t result; int rc; globus_byte_t buffer[GF_DYN_PACKET_LEN]; uint32_t tmp32; char * be_cs; char * reg_cs; globus_size_t nbytes; LTDL_SET_PRELOADED_SYMBOLS(); rc = globus_module_activate(GLOBUS_XIO_MODULE); if(rc != 0) { goto error_activate; } result = gfs_l_dynclient_master_options(argc, argv); if(result != GLOBUS_SUCCESS) { goto error_opts; } if(argc < 3) { fprintf(stderr, "%s [options] <backend contact string>" " <frontend contact string>\n", argv[0]); fprintf(stderr, "Use -help for more information\n"); exit(0); } be_cs = argv[argc - 2]; reg_cs = argv[argc - 1]; result = gfs_l_dynclient_xio_setup(); if(result != GLOBUS_SUCCESS) { goto error_xio; } memset(buffer, '\0', GF_DYN_PACKET_LEN); buffer[GF_VERSION_NDX] = GF_VERSION; buffer[GF_MSG_TYPE_NDX] = GFS_GFORK_MSG_TYPE_DYNBE; tmp32 = htonl(g_at_once); memcpy(&buffer[GF_DYN_AT_ONCE_NDX], &tmp32, sizeof(uint32_t)); tmp32 = htonl(g_total_cons); memcpy(&buffer[GF_DYN_TOTAL_NDX], &tmp32, sizeof(uint32_t)); tmp32 = htonl(1); memcpy(&buffer[GF_DYN_ENTRY_COUNT_NDX], &tmp32, sizeof(uint32_t)); strncpy((char *) &buffer[GF_DYN_CS_NDX], be_cs, GF_DYN_CS_LEN); result = globus_xio_open(g_xio_handle, reg_cs, NULL); if(result != GLOBUS_SUCCESS) { goto error_open; } result = globus_xio_write( g_xio_handle, buffer, GF_DYN_PACKET_LEN, GF_DYN_PACKET_LEN, &nbytes, NULL); if(result != GLOBUS_SUCCESS) { goto error_write; } /* read reply */ result = globus_xio_read( g_xio_handle, buffer, GF_DYN_PACKET_LEN, GF_DYN_PACKET_LEN, &nbytes, NULL); if(result != GLOBUS_SUCCESS) { gfs_l_dynclient_log(GLOBUS_SUCCESS, 0, "Read failed\n"); goto error_read; } result = globus_xio_close(g_xio_handle, NULL); if(result != GLOBUS_SUCCESS) { gfs_l_dynclient_log(GLOBUS_SUCCESS, 0, "Close failed\n"); goto error_close; } gfs_l_dynclient_log(GLOBUS_SUCCESS, 1, "proper net commication with %s\n", reg_cs); if(buffer[GF_MSG_TYPE_NDX] == GFS_GFORK_MSG_TYPE_ACK) { gfs_l_dynclient_log(GLOBUS_SUCCESS, 0, "SUCCESS: registered %s to %s", be_cs, reg_cs); rc = 0; } else { gfs_l_dynclient_log(GLOBUS_SUCCESS, 0, "ERROR: %s rejected registration of %s", reg_cs, be_cs); rc = 1; } return rc; error_close: error_read: error_write: error_open: error_xio: error_opts: error_activate: gfs_l_dynclient_log(result, 0, ""); return 2; }
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; }
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; }
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; }