static void data_cb_read( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err, globus_byte_t * buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { if(err) { fprintf(stderr, "%s", globus_object_printable_to_string(err)); } else { FILE* fd = (FILE*) user_arg; int rc = fwrite(buffer, 1, length, fd); if (ferror(fd)) { printf("Read error in function data_cb_read; errno = %d\n", errno); return; } if (!eof) { globus_ftp_client_register_read(handle, buffer, MAX_BUFFER_SIZE_R, data_cb_read, (void*) fd); } } return; }
static void writediscontig_data_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error, globus_byte_t *buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { globus_size_t *bytes_written; bytes_written=(globus_size_t *)myargs; if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } *bytes_written+=length; /* I don't understand why the data callback has to keep recalling register_read, but everything I've done and all the examples I've seen seem to require that behavior to work... */ if ( !eof ) globus_ftp_client_register_write(handle, buffer, length, offset, eof, writediscontig_data_cb, (void *)(bytes_written)); FPRINTF(stderr,"wrote %Ld bytes...",(long long)length); return; }
static void touch_data_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error, globus_byte_t *buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { if (error) FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); globus_ftp_client_register_read(handle,buffer,length,touch_data_cb,myargs); return; }
static globus_result_t globus_l_xio_test_write_buffer( globus_xio_handle_t handle, globus_byte_t * message, globus_size_t message_size, globus_size_t buffer_size) { globus_byte_t * ptr = message; globus_size_t left = message_size; globus_size_t to_write; globus_size_t nbytes; globus_result_t result = GLOBUS_SUCCESS; GlobusXIOName(globus_l_xio_test_write_buffer); if (buffer_size == 0) { buffer_size = 1024; } while ((left > 0) && (result == GLOBUS_SUCCESS)) { to_write = (left > buffer_size) ? buffer_size : left; result = globus_xio_write( handle, ptr, to_write, to_write, &nbytes, NULL); if (result == GLOBUS_SUCCESS) { if (nbytes != to_write) { fprintf(stderr, "Didn't write all I expected.\n"); result = GlobusXIOErrorEOF(); } left -= nbytes; ptr += nbytes; } else { fprintf(stderr, "Error writing data: %s\n", globus_object_printable_to_string(globus_error_peek(result))); } } globus_xio_handle_cntl( handle, http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY); return result; }
void mdsip_test_result(globus_xio_handle_t xio_handle,globus_result_t res,mdsip_client_t *ctx,char *msg) { if(res != GLOBUS_SUCCESS) { fprintf(stderr, "ERROR:%s ---\n %s\n", msg,globus_object_printable_to_string(globus_error_get(res))); if (xio_handle != NULL) globus_xio_register_close(xio_handle,NULL,mdsip_close_cb,ctx); } }
static void touch_ctl_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error) { if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } globus_mutex_lock(&lock); touch_ctl_done=GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); }
void globus_err_handler(const char *routine, const char *caller, globus_result_t result) { int myrank,nprocs; globus_object_t *err; MPI_Comm_rank(MPI_COMM_WORLD,&myrank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); err = globus_error_get(result); FPRINTF(stderr, "[%d/%d] %s error \"%s\", called from %s\n", myrank,nprocs,routine,globus_object_printable_to_string(err),caller); }
static void exists_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error) { if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } else { file_exists=GLOBUS_TRUE; } exists_done=GLOBUS_TRUE; }
static void delete_cb(void *myarg, globus_ftp_client_handle_t *handle, globus_object_t *error) { if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } else { delete_success=GLOBUS_TRUE; } delete_done=GLOBUS_TRUE; }
static void writediscontig_ctl_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error) { if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } globus_mutex_lock(&writediscontig_ctl_lock); if ( writediscontig_ctl_done!=GLOBUS_TRUE ) writediscontig_ctl_done=GLOBUS_TRUE; globus_cond_signal(&writediscontig_ctl_cond); globus_mutex_unlock(&writediscontig_ctl_lock); return; }
void test_res( globus_result_t res) { if(res == GLOBUS_SUCCESS) { return; } fprintf(stderr, "ERROR: %s\n", globus_object_printable_to_string( globus_error_get(res))); globus_assert(0); }
static void done_cb( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { if(err){ fprintf(stderr, "%s", globus_object_printable_to_string(err)); } globus_mutex_lock(&lock); done = GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); return; }
static void writecontig_ctl_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error) { if (error) { FPRINTF(stderr, "%s\n", globus_object_printable_to_string(error)); } globus_mutex_lock(&writecontig_ctl_lock); if ( writecontig_ctl_done!=GLOBUS_TRUE ) writecontig_ctl_done=GLOBUS_TRUE; globus_cond_signal(&writecontig_ctl_cond); globus_mutex_unlock(&writecontig_ctl_lock); #ifdef PRINT_ERR_MSG FPRINTF(stderr,"finished with contig write transaction\n"); #endif /* PRINT_ERR_MSG */ return; }
static globus_result_t globus_l_xio_test_read_buffer( globus_xio_handle_t handle, globus_byte_t * msg, globus_size_t msg_size) { globus_size_t nbytes; globus_result_t result = GLOBUS_SUCCESS; globus_byte_t * temp; int i; GlobusXIOName(globus_l_xio_test_read_buffer); temp = globus_libc_malloc(msg_size+1); for (i=0; i<=msg_size; i++) temp[i] = '\0'; result = globus_xio_read( handle, temp, msg_size, msg_size, &nbytes, NULL); if (result != GLOBUS_SUCCESS) { fprintf(stderr, "Error reading from http: %s\n", globus_object_printable_to_string(globus_error_peek(result))); } result = globus_xio_read( handle, msg, msg_size, 1, &nbytes, NULL); if (http_is_eof(result)) { result = GLOBUS_SUCCESS; } return result; }
int main() { globus_object_t * err; char * s; static char * myname = "main"; globus_module_activate(GLOBUS_COMMON_MODULE); err = globus_error_construct_string(GLOBUS_COMMON_MODULE, GLOBUS_ERROR_NO_INFO, "[%s]: Error doing something hard at %s:%d\n", GLOBUS_COMMON_MODULE->module_name, myname, __LINE__); s = globus_object_printable_to_string(err); globus_libc_printf("%s",s); return globus_module_deactivate_all(); }
static void done_cb( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { char * tmpstr; if(err) { tmpstr = globus_object_printable_to_string(err); printf("done with error: %s\n", tmpstr); error = GLOBUS_TRUE; globus_libc_free(tmpstr); } globus_mutex_lock(&lock); done = GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); }
int coDetach(void) { int32 data = COMM_DETACH; sendData((void *)&data, sizeof(int32)); close(coSimLibData.soc); coSimLibData.soc = -1; fprintf(stderr, "Simulation detached from COVISE\n"); #ifdef HAVE_GLOBUS { xsd_any *fault; int fault_type; int err; setStatusType setStatus; setStatusResponseType *statusResponse; setStatusResponseType_init(&statusResponse); setStatus.user = getenv("USER"); setStatus.id = simulationID; setStatus.status = 1; // detach if ((err = SimulationPortType_setStatus_epr(client_handle, epr, &setStatus, &statusResponse, (SimulationPortType_setStatus_fault_t *)&fault_type, &fault)) == GLOBUS_SUCCESS) { fprintf(stderr, "globus set status: %d\n", statusResponse->result); } else { fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err))); } setStatusResponseType_destroy(statusResponse); } #endif return 0; }
static globus_result_t globus_l_xio_test_write_buffer( globus_xio_handle_t handle, globus_byte_t * msg, globus_size_t msg_size, globus_xio_driver_t http_driver) { globus_size_t nbytes; globus_result_t result; GlobusXIOName(globus_l_xio_test_write_buffer); result = globus_xio_write( handle, msg, msg_size, msg_size, &nbytes, NULL); if (result == GLOBUS_SUCCESS) { if (nbytes != msg_size) { fprintf(stderr, "Didn't write all I expected.\n"); result = GlobusXIOErrorEOF(); } } else { fprintf(stderr, "Error writing data: %s\n", globus_object_printable_to_string(globus_error_peek(result))); } globus_xio_handle_cntl( handle, http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY); return result; }
static void done_cb( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { char * tmpstr; if(err) tmpstr = " an"; else tmpstr = "out"; if(err) { printf("done with%s error: %s\n", tmpstr, globus_object_printable_to_string(err)); error++; } globus_mutex_lock(&lock); done = GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); }
int COEXIT() { int32 data = COMM_EXIT; #ifdef HAVE_GLOBUS xsd_any *fault; int fault_type; int err; unregisterSimulationType unregSimulation; unregisterSimulationResponseType *unregResponse; unregisterSimulationResponseType_init(&unregResponse); unregSimulation.user = getenv("USER"); unregSimulation.id = simulationID; if ((err = SimulationPortType_unregisterSimulation_epr(client_handle, epr, &unregSimulation, &unregResponse, (SimulationPortType_unregisterSimulation_fault_t *)&fault_type, &fault)) == GLOBUS_SUCCESS) { fprintf(stderr, "globus unregistered: %d\n", unregResponse->result); } else { fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err))); } unregisterSimulationResponseType_destroy(unregResponse); #endif sendData((void *)&data, sizeof(int32)); close(coSimLibData.soc); coSimLibData.soc = -1; return 0; }
static void globus_l_io_authorization_test_connect_callback( void * arg, globus_io_handle_t * handle, globus_result_t result) { globus_l_io_authorization_test_monitor_t * monitor; monitor = (globus_l_io_authorization_test_monitor_t *) arg; if(result != GLOBUS_SUCCESS) { printf("# %s\n", globus_object_printable_to_string( globus_error_get(result))); exit(1); } globus_mutex_lock(&monitor->mutex); monitor->connected = GLOBUS_TRUE; globus_cond_signal(&monitor->cond); globus_mutex_unlock(&monitor->mutex); }
static void data_cb_write( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err, globus_byte_t * buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { int curr_offset; if(err) { fprintf(stderr, "%s", globus_object_printable_to_string(err)); } else { if (!eof) { FILE* fd = (FILE*) user_arg; int rc; globus_mutex_lock(&lock); curr_offset = global_offset; rc = fread(buffer, 1, MAX_BUFFER_SIZE_W, fd); global_offset += rc; globus_mutex_unlock(&lock); if (ferror(fd)) { printf("Read error in function data_cb_write; errno = %d\n", errno); return; } globus_ftp_client_register_write(handle, buffer, rc, curr_offset, feof(fd) != 0, data_cb_write, (void*) fd); } else { globus_libc_free(buffer); } } return; }
int main() { globus_object_t * err; char * s; char * t; static char * myname = "main"; printf("1..1\n"); globus_module_activate(GLOBUS_COMMON_MODULE); #line myline err = globus_error_construct_string(GLOBUS_COMMON_MODULE, GLOBUS_ERROR_NO_INFO, "[%s]: Error doing something hard at %s:%d\n", GLOBUS_COMMON_MODULE->module_name, myname, __LINE__); s = globus_object_printable_to_string(err); #line myline t = globus_common_create_string( "[%s]: Error doing something hard at %s:%d\n", GLOBUS_COMMON_MODULE->module_name, myname, __LINE__); ok(strcmp(s, t) == 0, "globus_common_error_string"); free(s); free(t); return TEST_EXIT_CODE; }
void authenticate_callback( void * callback_arg, globus_ftp_control_handle_t * handle, globus_object_t * error, globus_ftp_control_response_t * ftp_response) { globus_result_t result; if(error != GLOBUS_NULL) { verbose_printf(1, "Error : %s\n", globus_object_printable_to_string(error)); exit(1); } if (ftp_response->code == 230) { verbose_printf(2, "%s\n", ftp_response->response_buffer); result = globus_ftp_control_send_command( handle, "PWD\r\n", send_command_callback, GLOBUS_NULL); if (result != GLOBUS_SUCCESS) { verbose_printf(1, "send_command PWD failed\n"); exit(1); } } else { verbose_printf(1, "Error : %s\n", ftp_response->response_buffer); exit(1); } }
static void readdiscontig_data_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error, globus_byte_t *buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { globus_size_t *bytes_read; bytes_read=(globus_size_t *)myargs; if (error) { fprintf(stderr, "%s\n", globus_object_printable_to_string(error)); } *bytes_read+=length; /* I don't understand why the data callback has to keep recalling register_read, but everything I've done and all the examples I've seen seem to require that behavior to work... */ if ( !eof ) globus_ftp_client_register_read(handle, buffer, length, readdiscontig_data_cb, (void *)(bytes_read)); return; }
static void readcontig_data_cb(void *myargs, globus_ftp_client_handle_t *handle, globus_object_t *error, globus_byte_t *buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { globus_size_t *bytes_read; bytes_read=(globus_size_t *)myargs; if (error) { fprintf(stderr, "%s\n", globus_object_printable_to_string(error)); } *bytes_read+=length; /* I don't understand why the data callback has to keep recalling register_read, but everything I've done and all the examples I've seen seem to require that behavior to work... */ /* * Using buffer+length seems to work, but is probably not the correct * solution. A big read of 256kB chunks will have lines like this: readcontig_data_cb: buffer 0x404e0008 length 0 offset 31719424 eof 1 readcontig_data_cb: buffer 0x404a0008 length 65536 offset 31981568 eof 0 readcontig_data_cb: buffer 0x404b0008 length 65536 offset 32047104 eof 0 readcontig_data_cb: buffer 0x404c0008 length 65536 offset 32112640 eof 0 readcontig_data_cb: buffer 0x404d0008 length 65536 offset 32178176 eof 0 */ #if 0 fprintf(stderr, "%s: buffer %p length %d offset %Ld eof %d\n", __func__, buffer, length, offset, eof); #endif if ( !eof ) globus_ftp_client_register_read(handle, buffer+length, length, readcontig_data_cb, (void *)(bytes_read)); return; }
/* * Function: main * * Description: * * Parameters: * * Returns: */ int main(int argc, char **argv) { int rc; globus_result_t result; globus_object_t * error = NULL; char * errstring; globus_io_handle_t handle; globus_io_handle_t stdout_handle; globus_size_t bytes; globus_size_t i; globus_byte_t buf[1024]; #ifdef TARGET_ARCH_WIN32 HANDLE outputFile; globus_io_handle_t write_handle; if ( argc < 3 ) { usage( argv[0] ); return -1; } #endif globus_module_activate(GLOBUS_COMMON_MODULE); globus_module_activate(GLOBUS_IO_MODULE); #ifndef TARGET_ARCH_WIN32 result = globus_io_file_open("/etc/group", O_RDONLY, 0600, GLOBUS_NULL, &handle); #else result = globus_io_file_open( argv[1], O_RDONLY, 0600, GLOBUS_NULL, &handle); #endif if(result != GLOBUS_SUCCESS) { error = globus_error_get(result); errstring = globus_object_printable_to_string(error); #ifndef TARGET_ARCH_WIN32 globus_libc_printf("test failed to open /etc/group: %s\n", errstring); #else globus_libc_printf("test failed to open %s: %s\n", argv[1], errstring); #endif goto done; } #ifndef TARGET_ARCH_WIN32 result = globus_io_file_posix_convert( fileno(stdout), GLOBUS_NULL, &stdout_handle); #else outputFile= CreateFile( argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_OVERLAPPED, NULL ); if ( outputFile == INVALID_HANDLE_VALUE ) { printf( "An error occurred while trying to create the output file (error is %d)...exiting\n", GetLastError() ); return -1; } result= globus_io_file_windows_convert( outputFile, GLOBUS_NULL, &write_handle); #endif if(result != GLOBUS_SUCCESS) { error = globus_error_get(result); errstring = globus_object_printable_to_string(error); globus_libc_printf("test failed to convert stdout to io handle: %s\n", errstring); goto done; } do { result = globus_io_read(&handle, buf, sizeof(buf), sizeof(buf), &bytes); if(result == GLOBUS_SUCCESS || ((error = globus_error_get(result)) && (globus_object_type_match(globus_object_get_type(error), GLOBUS_IO_ERROR_TYPE_EOF)))) { globus_size_t nbytes2; #ifndef TARGET_ARCH_WIN32 globus_io_write(&stdout_handle, buf, bytes, &nbytes2); #else globus_io_write( &write_handle, buf, bytes, &nbytes2); #endif } else { errstring = globus_object_printable_to_string(error); globus_libc_printf("test failed to read /etc/group: %s\n", errstring); goto done; } } while(result == GLOBUS_SUCCESS); done: if(error) { globus_object_free(error); } globus_io_close(&handle); #ifndef TARGET_ARCH_WIN32 globus_io_close(&stdout_handle); #else globus_io_close( &write_handle); #endif globus_module_deactivate(GLOBUS_IO_MODULE); globus_module_deactivate(GLOBUS_COMMON_MODULE); return 0; }
void ADIOI_GRIDFTP_Open(ADIO_File fd, int *error_code) { static char myname[]="ADIOI_GRIDFTP_Open"; int myrank, nprocs, keyfound; char hintval[MPI_MAX_INFO_VAL+1]; globus_ftp_client_handleattr_t hattr; globus_result_t result; MPI_Comm_size(fd->comm, &nprocs); MPI_Comm_rank(fd->comm, &myrank); /* activate Globus ftp client module -- can be called multiple times, so it's safest to call once per file/connection */ globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); fd->fd_sys = num_gridftp_handles; /* No shared file pointers for now */ fd->shared_fp_fname = NULL; *error_code = MPI_SUCCESS; /* Access modes here mean something very different here than they would on a "real" filesystem... As a result, the amode and hint processing here is intermingled and a little weird because many of them have to do with the connection rather than the file itself. The thing that sucks about this is that read and write ops will have to check themselves if the file is being accessed rdonly, rdwr, or wronly. */ result=globus_ftp_client_handleattr_init(&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handleattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result = globus_ftp_client_operationattr_init(&(oattr[fd->fd_sys])); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_operationattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Always use connection caching unless told otherwise */ result=globus_ftp_client_handleattr_set_cache_all(&hattr,GLOBUS_TRUE); if ( result !=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_set_cache_all",myname,result); /* Assume that it's safe to cache a file if it's read-only */ if ( (fd->access_mode&ADIO_RDONLY) && (result=globus_ftp_client_handleattr_add_cached_url(&hattr,fd->filename))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_add_cached_url",myname,result); /* Since we're (almost by definition) doing things that FTP S (stream) control mode can't handle, default to E (extended block) control mode for gsiftp:// URLs. ftp:// URLs use standard stream control mode by default. This behavior can be overridden by the ftp_control_mode hint. */ /* if ( !strncmp(fd->filename,"gsiftp:",7) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strncmp(fd->filename,"ftp:",4) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); */ /* Set append mode if necessary */ if ( (fd->access_mode&ADIO_APPEND) && ((result=globus_ftp_client_operationattr_set_append(&(oattr[fd->fd_sys]),GLOBUS_TRUE))!=GLOBUS_SUCCESS) ) globus_err_handler("globus_ftp_client_operationattr_set_append",myname,result); /* Other hint and amode processing that would affect hattr and/or oattr[] (eg. parallelism, striping, etc.) goes here */ if ( fd->info!=MPI_INFO_NULL ) { ADIOI_Info_get(fd->info,"ftp_control_mode",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { if ( ( !strcmp(hintval,"extended") || !strcmp(hintval,"extended_block") ) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"block") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"compressed") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_COMPRESSED))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"stream") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); } ADIOI_Info_get(fd->info,"parallelism",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int nftpthreads; if ( sscanf(hintval,"%d",&nftpthreads)==1 ) { globus_ftp_control_parallelism_t parallelism; parallelism.mode = GLOBUS_FTP_CONTROL_PARALLELISM_FIXED; parallelism.fixed.size = nftpthreads; if ( (result=globus_ftp_client_operationattr_set_parallelism(&(oattr[fd->fd_sys]), ¶llelism))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_parallelism",myname,result); } } ADIOI_Info_get(fd->info,"striped_ftp",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* if set to "true" or "enable", set up round-robin block layout */ if ( !strncmp("true",hintval,4) || !strncmp("TRUE",hintval,4) || !strncmp("enable",hintval,4) || !strncmp("ENABLE",hintval,4) ) { ADIOI_Info_get(fd->info,"striping_factor",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int striping_factor; if ( sscanf(hintval,"%d",&striping_factor)==1 ) { globus_ftp_control_layout_t layout; layout.mode = GLOBUS_FTP_CONTROL_STRIPING_BLOCKED_ROUND_ROBIN; layout.round_robin.block_size = striping_factor; if ( (result=globus_ftp_client_operationattr_set_layout(&(oattr[fd->fd_sys]), &layout))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_layout", myname,result); } } } } ADIOI_Info_get(fd->info,"tcp_buffer",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* set tcp buffer size */ int buffer_size; if ( sscanf(hintval,"%d",&buffer_size)==1 ) { globus_ftp_control_tcpbuffer_t tcpbuf; tcpbuf.mode = GLOBUS_FTP_CONTROL_TCPBUFFER_FIXED; tcpbuf.fixed.size = buffer_size; if ( (result=globus_ftp_client_operationattr_set_tcp_buffer(&(oattr[fd->fd_sys]), &tcpbuf))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_tcp_buffer",myname,result); } } ADIOI_Info_get(fd->info,"transfer_type",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { globus_ftp_control_type_t filetype; /* set transfer type (i.e. ASCII or binary) */ if ( !strcmp("ascii",hintval) || !strcmp("ASCII",hintval) ) { filetype=GLOBUS_FTP_CONTROL_TYPE_ASCII; } else { filetype=GLOBUS_FTP_CONTROL_TYPE_IMAGE; } if ( (result=globus_ftp_client_operationattr_set_type(&(oattr[fd->fd_sys]),filetype))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_type",myname,result); } } else FPRINTF(stderr,"no MPI_Info object associated with %s\n",fd->filename); /* Create the ftp handle */ result=globus_ftp_client_handle_init(&(gridftp_fh[fd->fd_sys]),&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handle_init",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Check for existence of the file */ globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); file_exists=GLOBUS_FALSE; exists_done=GLOBUS_FALSE; if ( myrank==0 ) { if ( (result=globus_ftp_client_exists(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), exists_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_exists",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* wait till the callback completes */ globus_mutex_lock(&lock); while ( exists_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); MPI_Bcast(&file_exists,1,MPI_INT,0,fd->comm); /* It turns out that this is handled by MPI_File_open() directly */ if ( (file_exists!=GLOBUS_TRUE) && (fd->access_mode&ADIO_CREATE) && !(fd->access_mode&ADIO_EXCL) && !(fd->access_mode&ADIO_RDONLY) ) { if ( myrank==0 ) { /* if the file doesn't exist, write a single NULL to it */ globus_byte_t touchbuf=(globus_byte_t)'\0'; touch_ctl_done=GLOBUS_FALSE; if ( (result=globus_ftp_client_put(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), GLOBUS_NULL, touch_ctl_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_put",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result=globus_ftp_client_register_write(&(gridftp_fh[fd->fd_sys]), (globus_byte_t *)&touchbuf, 0, (globus_off_t)0, GLOBUS_TRUE, touch_data_cb, GLOBUS_NULL); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_register_write",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } globus_mutex_lock(&lock); while ( touch_ctl_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); } else if ( (fd->access_mode&ADIO_EXCL) && (file_exists==GLOBUS_TRUE) ) { fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", 0); return; } else if ( (fd->access_mode&ADIO_RDONLY) && (file_exists!=GLOBUS_TRUE) ) { if ( myrank==0 ) { FPRINTF(stderr,"WARNING: read-only file %s does not exist!\n",fd->filename); } } num_gridftp_handles++; }
static void globus_l_xio_test_server_request_callback( void * user_arg, globus_result_t result, const char * method, const char * uri, globus_xio_http_version_t http_version, globus_hashtable_t headers) { http_test_server_t * test_server; http_test_info_t * info; globus_xio_http_header_t response_headers[2]; globus_size_t header_cnt=0; char content_length_buffer[64]; int rc=0; int i; size_t nbytes; test_server = (http_test_server_t*) user_arg; info = test_server->info; if (result == GLOBUS_SUCCESS && method != NULL && uri != NULL && (strcmp(method, "POST") == 0) && (strcmp(uri, "/post-test") == 0)) { for (i = 0; i < info->iterations; i++) { result = globus_xio_read( test_server->handle, info->buffer, info->size, info->size, &nbytes, NULL); if (result != GLOBUS_SUCCESS || nbytes != info->size) { fprintf(stderr, "Error reading from http: %s\n", globus_object_printable_to_string( globus_error_peek(result))); } } } else { rc = 404; goto error_respond_exit; } result = globus_xio_read( test_server->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))); } if (info->transfer_encoding != NULL) { response_headers[header_cnt].name = "Transfer-Encoding"; response_headers[header_cnt].value = info->transfer_encoding; header_cnt++; } if ((http_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); response_headers[header_cnt].name = "Content-Length"; response_headers[header_cnt].value = &content_length_buffer[0]; header_cnt++; } result = http_test_server_respond( test_server, rc, NULL, response_headers, header_cnt); if (result != GLOBUS_SUCCESS) { goto error_exit; } result = globus_xio_write( test_server->handle, info->buffer, 1, 1, &nbytes, NULL); globus_xio_handle_cntl( test_server->handle, info->http_driver, GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY); info->size = throughput_next_size(info->size); if (info->size == -1) { http_test_server_close_handle(test_server); http_test_server_shutdown(test_server); } return; error_respond_exit: http_test_server_respond( test_server, rc, NULL, NULL, 0); error_exit: http_test_server_close_handle(test_server); http_test_server_shutdown(test_server); }
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; }