debug(D_CHIRP,"couldn't talk to %s: %s\n",file->host,strerror(errno)); \ current = time(0); \ nexttry = MIN(stoptime,current+delay); \ debug(D_CHIRP,"try again in %d seconds\n",(int)(nexttry-current)); \ sleep_until(nexttry); \ if(delay==0) {\ delay = 1;\ } else {\ delay = MIN(delay*2,MAX_DELAY); \ }\ } INT64_T chirp_reli_pread_unbuffered( struct chirp_file *file, void *data, INT64_T length, INT64_T offset, time_t stoptime ) { RETRY_FILE( result = chirp_client_pread(client,file->fd,data,length,offset,stoptime); ) } static INT64_T chirp_reli_pread_buffered( struct chirp_file *file, void *data, INT64_T length, INT64_T offset, time_t stoptime ) { if(file->buffer_valid) { if(offset >= file->buffer_offset && offset < (file->buffer_offset+file->buffer_valid) ) { INT64_T blength; blength = MIN(length,file->buffer_offset+file->buffer_valid-offset); memcpy(data,&file->buffer[offset-file->buffer_offset],blength); return blength; } } chirp_reli_flush(file,stoptime);
int chirp_read(int argc, char **argv) { int fileOffset = 2; int offset = 0; int stride_length = 0; int stride_skip = 0; bool more = true; while (more && fileOffset + 1 < argc) { if (strcmp(argv[fileOffset], "-offset") == 0) { offset = strtol(argv[fileOffset + 1], NULL, 10); fileOffset += 2; more = true; } else if (strcmp(argv[fileOffset], "-stride") == 0 && fileOffset + 2 < argc) { stride_length = strtol(argv[fileOffset + 1], NULL, 10); stride_skip = strtol(argv[fileOffset + 2], NULL, 10); fileOffset += 3; more = true; } else { more = false; } } if(fileOffset + 2 != argc) { printf("condor_chirp read [-offset offset] [-stride length skip] " "remotepath length\n"); return -1; } char *path = argv[fileOffset]; int length = strtol(argv[fileOffset + 1], NULL, 10); struct chirp_client *client = 0; CONNECT_STARTER(client); int fd = chirp_client_open(client, path, "r", 0); if(fd < 0) { DISCONNECT_AND_RETURN(client, fd); } void* buf = malloc(length+1); int ret_val = -1; // Use read if(offset == 0 && stride_length == 0 && stride_skip == 0) { ret_val = chirp_client_read(client, fd, buf, length); } // Use pread else if(offset != 0 && stride_length == 0 && stride_skip == 0) { ret_val = chirp_client_pread(client, fd, buf, length, offset); } // Use sread else { ret_val = chirp_client_sread(client, fd, buf, length, offset, stride_length, stride_skip); } if(ret_val >= 0) { char* to_print = (char*)buf; to_print[length] = '\0'; printf("%s\n", to_print); } free(buf); CLOSE_DISCONNECT_AND_RETURN(client, fd, ret_val); }