int MultiFileCurlPlugin::UploadMultipleFiles( const std::string &input_filename ) { std::vector<std::pair<std::string, transfer_request>> requested_files; auto rval = BuildTransferRequests(input_filename, requested_files); if (rval) {return rval;} classad::ClassAdUnParser unparser; if ( _diagnostic ) { fprintf( stderr, "Uploading multiple files.\n" ); } for (const auto &file_pair : requested_files) { const auto &local_file_name = file_pair.second.local_file_name; const auto &url = file_pair.first; int retry_count = 0; int file_rval = -1; // Initialize the stats structure for this transfer. _this_file_stats.reset(new FileTransferStats()); InitializeStats( url ); _this_file_stats->TransferStartTime = time(NULL); _this_file_stats->TransferFileName = local_file_name; // Enter the loop that will attempt/retry the curl request for ( ;; ) { std::this_thread::sleep_for(std::chrono::seconds(retry_count++)); // Everything prior to the first '+' is the credential name. std::string full_scheme = getURLType(url.c_str(), false); auto offset = full_scheme.find_last_of("+"); auto cred = (offset == std::string::npos) ? "" : full_scheme.substr(0, offset); // The actual transfer should only be everything after the last '+' std::string full_url = url; if (offset != std::string::npos) { full_url = full_url.substr(offset + 1); } file_rval = UploadFile( full_url, local_file_name, cred ); // If curl request is successful, break out of the loop if( file_rval == CURLE_OK ) { break; } // If we have not exceeded the maximum number of retries, and we encounter // a non-fatal error, stay in the loop and try again else if( retry_count <= MAX_RETRY_ATTEMPTS && ShouldRetryTransfer(file_rval) ) { continue; } // On fatal errors, break out of the loop else { break; } } _this_file_stats->TransferEndTime = time(NULL); // Regardless of success/failure, update the stats classad::ClassAd stats_ad; _this_file_stats->Publish( stats_ad ); std::string stats_string; unparser.Unparse( stats_string, &stats_ad ); _all_files_stats += stats_string; stats_ad.Clear(); // Note that we attempt to upload all files, even if one fails! // The upload protocol demands that all attempted files have a corresponding ad. if ( ( file_rval != CURLE_OK ) && ( rval != -1 ) ) { rval = file_rval; } } return rval; }
int MultiFileCurlPlugin::DownloadMultipleFiles( const std::string &input_filename ) { int rval = 0; std::vector<std::pair<std::string, transfer_request>> requested_files; rval = BuildTransferRequests(input_filename, requested_files); // If BuildTransferRequests failed, exit immediately if ( rval != 0 ) { return rval; } classad::ClassAdUnParser unparser; // Iterate over the map of files to transfer. for ( const auto &file_pair : requested_files ) { const auto &local_file_name = file_pair.second.local_file_name; const auto &url = file_pair.first; if ( _diagnostic ) { fprintf( stderr, "Will download %s to %s.\n", url.c_str(), local_file_name.c_str() ); } int retry_count = 0; // Initialize the stats structure for this transfer. _this_file_stats.reset( new FileTransferStats() ); InitializeStats( url ); _this_file_stats->TransferStartTime = time(NULL); _this_file_stats->TransferFileName = local_file_name; long partial_bytes = 0; // Enter the loop that will attempt/retry the curl request for ( ;; ) { if ( _diagnostic && retry_count ) { fprintf( stderr, "Retry count #%d\n", retry_count ); } std::this_thread::sleep_for(std::chrono::seconds(retry_count++)); // Everything prior to the first '+' is the credential name. std::string full_scheme = getURLType(url.c_str(), false); auto offset = full_scheme.find_last_of("+"); auto cred = (offset == std::string::npos) ? "" : full_scheme.substr(0, offset); // The actual transfer should only be everything after the last '+' std::string full_url = url; if (offset != std::string::npos) { full_url = full_url.substr(offset + 1); } // partial_bytes are updated if the file downloaded partially. rval = DownloadFile( full_url, local_file_name, cred, partial_bytes ); // If curl request is successful, break out of the loop if( rval == CURLE_OK ) { break; } // If we have not exceeded the maximum number of retries, and we encounter // a non-fatal error, stay in the loop and try again else if( retry_count <= MAX_RETRY_ATTEMPTS && ShouldRetryTransfer(rval) ) { continue; } // On fatal errors, break out of the loop else { break; } } _this_file_stats->TransferEndTime = time(NULL); // Regardless of success/failure, update the stats classad::ClassAd stats_ad; _this_file_stats->Publish( stats_ad ); std::string stats_string; unparser.Unparse( stats_string, &stats_ad ); _all_files_stats += stats_string; stats_ad.Clear(); // If the transfer did fail, break out of the loop immediately if ( rval > 0 ) break; } return rval; }
void NewGame(void) { short l, c, p, max_opening_sequence; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; #endif compptr = oppptr = 0; stage = 0; stage2 = -1; /* the game is not yet started */ flag.illegal = flag.mate = flag.post = flag.quit = flag.reverse = flag.bothsides = flag.onemove = flag.force = false; flag.material = flag.coords = flag.hash = flag.easy = flag.beep = flag.rcptr = true; flag.stars = flag.shade = flag.back = flag.musttimeout = false; flag.gamein = false; flag.rv = true; mycnt1 = mycnt2 = 0; GenCnt = NodeCnt = et0 = dither = XCmore = 0; znodes = ZNODES; WAwindow = WAWNDW; WBwindow = WBWNDW; BAwindow = BAWNDW; BBwindow = BBWNDW; xwndw = BXWNDW; if (!MaxSearchDepth) MaxSearchDepth = MAXDEPTH - 1; contempt = 0; GameCnt = 0; Game50 = 1; CptrFlag[0] = TesujiFlag[0] = false; hint = OPENING_HINT; ZeroRPT(); GameType[0] = GameType[1] = UNKNOWN; Pscore[0] = Tscore[0] = (SCORE_LIMIT + 3000); opponent = player = black; computer = white; for (l = 0; l < TREE; l++) Tree[l].f = Tree[l].t = 0; gsrand((unsigned int) 1); if (!InitFlag) { for (c = black; c <= white; c++) { for (p = pawn; p <= king; p++) { for (l = 0; l < NO_SQUARES; l++) { (*hashcode)[c][p][l].key = (((unsigned long) urand())); (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 16); (*hashcode)[c][p][l].bd = (((unsigned long) urand())); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 16); #if SIZEOF_LONG == 8 /* 64-bit long i.e. 8 bytes */ (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 32); (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 48); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 32); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 48); #endif } } } for (c = black; c <= white; c++) { for (p = pawn; p <= king; p++) { for (l = 0; l < MAX_CAPTURED; l++) { (*drop_hashcode)[c][p][l].key = (((unsigned long) urand())); (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 16); (*drop_hashcode)[c][p][l].bd = (((unsigned long) urand())); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 16); #if SIZEOF_LONG == 8 /* 64-bit long i.e. 8 bytes */ (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 32); (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 48); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 32); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 48); #endif } } } } for (l = 0; l < NO_SQUARES; l++) { board[l] = Stboard[l]; color[l] = Stcolor[l]; Mvboard[l] = 0; } ClearCaptured(); ClearScreen(); InitializeStats(); #ifdef HAVE_GETTIMEOFDAY gettimeofday(&tv, NULL); time0 = tv.tv_sec*100 + tv.tv_usec/10000; #else time0 = time((long *) 0); #endif /* resetting reference time */ ElapsedTime(COMPUTE_AND_INIT_MODE); flag.regularstart = true; Book = BOOKFAIL; if (!InitFlag) { char sx[256]; strcpy(sx, CP[169]); if (TCflag) SetTimeControl(); else if (MaxResponseTime == 0) SelectLevel(sx); UpdateDisplay(0, 0, 1, 0); GetOpenings(); GetOpeningPatterns(&max_opening_sequence); InitFlag = true; } #if ttblsz if (TTadd) { ZeroTTable(); TTadd = 0; } #endif /* ttblsz */ hashbd = hashkey = 0; return; }