diff options
Diffstat (limited to 'segget')
-rw-r--r-- | segget/connection.cpp | 19 | ||||
-rw-r--r-- | segget/distfile.cpp | 11 | ||||
-rw-r--r-- | segget/distfile.h | 7 | ||||
-rw-r--r-- | segget/pkg.cpp | 2 | ||||
-rw-r--r-- | segget/scriptserver.cpp | 2 | ||||
-rw-r--r-- | segget/ui_server.cpp | 16 |
6 files changed, 38 insertions, 19 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp index 5aa8453..25e3d79 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -49,9 +49,7 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme gettimeofday(&start_time,NULL); debug("Connecting network"+toString(network_num)); - segment->parent_distfile->active_connections_num++; - - segment->parent_distfile->status=DDOWNLOADING; + segment->parent_distfile->set_status(DDOWNLOADING); if (network_array[network_num].network_mode==MODE_PROXY_FETCHER){ connection_start_time_network_phase_for_pf_networks=segment->parent_distfile->network_distfile_brokers_array[network_num].phase; @@ -77,8 +75,13 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme debug(" URL:"+url); if (run_user_python_script(connection_num)){ + if (segment->parent_distfile->active_connections_num<=0){ + segment->parent_distfile->set_status(DSCRIPTREJECTED); + } return REJECTED_BY_USER_PYTHON_SCRIPT; } + + segment->parent_distfile->active_connections_num++; active=true; debug("aaaaa"); Pcurr_mirror->start(); @@ -188,7 +191,7 @@ void Tconnection::stop(CURLcode connection_result){ debug(toString(connection_result)+"]- Failed download "+segment->url); if (segment->try_num>=settings.max_tries){ segment->status=SFAILED; - segment->parent_distfile->status=DFAILED; + segment->parent_distfile->set_status(DFAILED); error_log("Segget failed to download distfile: "+segment->parent_distfile->name); error_log("Segment:"+segment->file_name+" has reached max_tries limit - segment.status set to FAILED"); } @@ -199,14 +202,14 @@ void Tconnection::stop(CURLcode connection_result){ debug(" Successful download "+segment->url); // already done earlier in this function Pcurr_mirror=find_mirror(strip_mirror_name(segment->url)); segment->status=SDOWNLOADED; - if (segment->parent_distfile->status!=DFAILED){ + segment->parent_distfile->inc_dld_segments_count(segment); + if ((segment->parent_distfile->get_status()!=DFAILED) and (segment->parent_distfile->get_status()!=DDOWNLOADED)){ if (segment->parent_distfile->active_connections_num>0){ - segment->parent_distfile->status=DDOWNLOADING; + segment->parent_distfile->set_status(DDOWNLOADING); }else{ - segment->parent_distfile->status=DWAITING; + segment->parent_distfile->set_status(DWAITING); } } - segment->parent_distfile->inc_dld_segments_count(segment); }; }catch(...){ error_log("Error in connection.cpp: stop()"); diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 9276af7..21d90c8 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -59,6 +59,15 @@ using namespace std; #define ALLOW_LOWER_PRIORITY_NETWORKS 205 */ +void Tdistfile::set_status(Tdistfile_status new_status){ + try{ + status=new_status; + ui_server.send_distfile_progress_msg_to_all_clients(get_distfile_progress_str()); + }catch(...){ + error_log("Error: distfile.cpp: set_status()"); + } +} + int Tdistfile::request(ulong network_num, string msg){ gettimeofday(&network_distfile_brokers_array[network_num].last_request_time, NULL); int sockfd; @@ -681,11 +690,11 @@ string Tdistfile::get_distfile_progress_str(){ void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){ try{ + stats.dld_segments_count++; stats.inc_dld_size(current_segment->segment_size); if (++dld_segments_count==segments_count){ combine_segments(); } - stats.dld_segments_count++; dld_bytes+=current_segment->segment_size; ui_server.send_distfile_progress_msg_to_all_clients(get_distfile_progress_str()); }catch(...){ diff --git a/segget/distfile.h b/segget/distfile.h index 5654848..56e2b79 100644 --- a/segget/distfile.h +++ b/segget/distfile.h @@ -81,6 +81,7 @@ enum Tdistfile_status{ DPROXY_DOWNLOADED, DPROXY_FAILED, DWAITING, + DSCRIPTREJECTED, DDOWNLOADING, DDOWNLOADED, DFAILED @@ -92,13 +93,13 @@ class Tdistfile{ private: bool choose_best_local_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num); bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num); + Tdistfile_status status; public: uint dld_segments_count; ulong dld_bytes; Tnetwork_distfile_broker network_distfile_brokers_array[MAX_NETWORKS]; string json_data; // bool downloaded; - Tdistfile_status status; uint active_connections_num; string *url_list; uint url_num; @@ -118,11 +119,11 @@ class Tdistfile{ uint url_count; uint segment_size; Tdistfile(): + status(DNEW), dld_segments_count(0), dld_bytes(0), json_data(""), // downloaded(0), - status(DNEW), active_connections_num(0), url_list(0), url_num(0), @@ -148,6 +149,8 @@ class Tdistfile{ ~Tdistfile(); int request(ulong network_num, string msg); void init(); + void set_status(Tdistfile_status new_status); + Tdistfile_status get_status(){return status;}; bool allows_new_actions(); bool load_distfile_from_json(json_object* json_obj_distfile); void load_url_list(json_object* json_array_distfile_urllist); diff --git a/segget/pkg.cpp b/segget/pkg.cpp index 20cf0c0..737bb5d 100644 --- a/segget/pkg.cpp +++ b/segget/pkg.cpp @@ -58,7 +58,7 @@ int Tpkg::find_distfile(string distfile_name){ try{ for (ulong distfile_num=0; distfile_num<distfile_count; distfile_num++){ if (Pdistfile_list[distfile_num]->name==distfile_name){ - switch (Pdistfile_list[distfile_num]->status){ + switch (Pdistfile_list[distfile_num]->get_status()){ case DDOWNLOADED: { debug("find_distfile(): distfile: "+distfile_name+" was downloaded"); return R_PF_DOWNLOADED; diff --git a/segget/scriptserver.cpp b/segget/scriptserver.cpp index 44173d7..d257745 100644 --- a/segget/scriptserver.cpp +++ b/segget/scriptserver.cpp @@ -234,7 +234,7 @@ bool run_user_python_script(uint connection_num){ } } - error_log("Created pid:"+toString(pID)); + debug("Launched python script, pid:"+toString(pID)); // parent //Now wait for clients and requests. Because you have passed a null pointer as the timeout parameter, no timeout will occur. The program will exit and report an error if select returns a value less than 1: struct timeval user_script_start_time; diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp index 967112e..8fb48e6 100644 --- a/segget/ui_server.cpp +++ b/segget/ui_server.cpp @@ -170,7 +170,7 @@ void *run_ui_server(void * ){ debug("Client parted from fd:"+toString(fd)); }else{ error_log("reading buffer"); - char buffer[1000]; + char buffer[1000]=""; if (nread!=read(fd, &buffer, nread)){ debug("Not all data has been read from ui_client()"); } @@ -184,7 +184,7 @@ void *run_ui_server(void * ){ if (distfile_by_name_lookup_request.length()>0){ for (ulong distfile_num=0; distfile_num<request_server_pkg.distfile_count; distfile_num++){ if (distfile_by_name_lookup_request==request_server_pkg.Pdistfile_list[distfile_num]->name){ - if (request_server_pkg.Pdistfile_list[distfile_num]->status==DDOWNLOADED){ + if (request_server_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){ distfile_search_result=DOWNLOADED; }else{ distfile_search_result=IN_QUEUE; @@ -195,7 +195,7 @@ void *run_ui_server(void * ){ if (distfile_search_result==NOT_FOUND){ for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.distfile_count; distfile_num++){ if (distfile_by_name_lookup_request==proxy_fetcher_pkg.Pdistfile_list[distfile_num]->name){ - if (proxy_fetcher_pkg.Pdistfile_list[distfile_num]->status==DDOWNLOADED){ + if (proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){ distfile_search_result=DOWNLOADED; }else{ distfile_search_result=IN_QUEUE; @@ -219,18 +219,22 @@ void *run_ui_server(void * ){ case IN_QUEUE: string err_msg="Found distfile by name:"; err_msg=err_msg+buffer; - error_log(err_msg); + error_log_no_msg(err_msg); ui_server.send_to_fd(fd, "<m>y<t><.>"); //distfile is in the list continue // Get this info to catch up! for (uint line_num=0; line_num<=max_published_screenline_num;line_num++){ ui_server.send_connection_msg_to_fd(fd, line_num, screenlines[line_num]); + error_log_no_msg("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]); debug_no_msg("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]); } - for (ulong distfile_num=0; distfile_num<request_server_pkg.distfile_count; distfile_num++){ + error_log_no_msg("Sending to client distfiles_num:"+toString(request_server_pkg.Pdistfile_list.size())); + for (ulong distfile_num=0; distfile_num<request_server_pkg.Pdistfile_list.size(); distfile_num++){ ui_server.send_distfile_progress_msg_to_fd(fd, request_server_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str()); + error_log_no_msg("Sending to client:"+request_server_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str()); } - for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.distfile_count; distfile_num++){ + for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.Pdistfile_list.size(); distfile_num++){ ui_server.send_distfile_progress_msg_to_fd(fd, proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str()); + error_log_no_msg("Sending to client:"+proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str()); } } } |