From 4f5401188c6fed3bbdd6e2faacd28b3b5c7f218d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 17 Jul 2006 22:18:17 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=10659 --- checkin_notes | 17 +++++++++ client/acct_setup.C | 4 +- client/client_state.C | 59 ------------------------------ client/client_state.h | 16 -------- client/cs_account.C | 1 - client/cs_scheduler.C | 2 +- client/gui_rpc_server_ops.C | 6 +-- client/http_curl.C | 14 +------ client/net_stats.C | 73 +++++++++++++++++++++++++++++++++++++ client/net_stats.h | 27 ++++++++++++++ client/pers_file_xfer.C | 2 +- client/scheduler_op.C | 2 +- lib/app_ipc.C | 3 +- 13 files changed, 128 insertions(+), 98 deletions(-) diff --git a/checkin_notes b/checkin_notes index 6cab15bd20..15f45b05ea 100755 --- a/checkin_notes +++ b/checkin_notes @@ -7592,3 +7592,20 @@ David 17 July 2006 gui_rpc_server.C,h sched/ trickle_handler.C + +David 17 July 2006 + - moved stuff related to network status out of CLIENT_STATE + and into a new class, NET_STATUS. + + client/ + acct_setup.C + client_state.C,h + cs_account.C + cs_scheduler.C + gui_rpc_server_ops.C + http_curl.C + net_stats.C,h + pers_file_xfer.C + scheduler_ops.C + lib/ + app_ipc.C diff --git a/client/acct_setup.C b/client/acct_setup.C index cc0cc9dcaa..160dad0744 100644 --- a/client/acct_setup.C +++ b/client/acct_setup.C @@ -219,7 +219,7 @@ int LOOKUP_WEBSITE_OP::do_rpc(string& url) { retval = gstate.gui_http.do_rpc(this, url, LOOKUP_WEBSITE_FILENAME); if (retval) { error_num = retval; - gstate.need_physical_connection = true; + net_status.need_physical_connection = true; msg_printf(0, MSG_ERROR, "Access to reference web site failed - check network connection or proxy configuration." ); @@ -238,7 +238,7 @@ void LOOKUP_WEBSITE_OP::handle_reply(int http_op_retval) { // Set a flag that will signal the Manager to that effect // if (http_op_retval) { - gstate.need_physical_connection = true; + net_status.need_physical_connection = true; msg_printf(0, MSG_ERROR, "Access to reference site failed - check network connection or proxy configuration." ); diff --git a/client/client_state.C b/client/client_state.C index a2390accb6..1d25cfb438 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -102,8 +102,6 @@ CLIENT_STATE::CLIENT_STATE() { total_wall_cpu_time_this_period = 0; must_schedule_cpus = true; must_enforce_cpu_schedule = true; - need_physical_connection = false; - have_sporadic_connection = false; no_gui_rpc = false; have_tentative_project = false; new_version_check_time = 0; @@ -1344,63 +1342,6 @@ int CLIENT_STATE::detach_project(PROJECT* project) { return 0; } -// Return: -// 0 if we have network connections open -// 1 if we need a physical connection -// 2 if we don't have any connections, and don't need any -// 3 if a website lookup is pending (try again later) -// -// There's a 10-second slop factor; -// if we've done network comm in the last 10 seconds, -// we act as if we're doing it now. -// (so that polling mechanisms have a change to trigger) -// -int CLIENT_STATE::network_status() { - static double last_comm_time=0; - - if (http_ops->nops()) { - last_comm_time = now; - } - if (now - last_comm_time < 10) { - //msg_printf(0, MSG_INFO, "nops %d; return 0", http_ops->nops()); - return 0; - } - if (lookup_website_op.error_num == ERR_IN_PROGRESS) { - return 3; - } - if (need_physical_connection) { - //msg_printf(0, MSG_INFO, "need phys conn; return 1"); - return 1; - } - if (active_tasks.want_network()) { - return 1; - } - have_sporadic_connection = false; - //msg_printf(0, MSG_INFO, "returning 2"); - return 2; -} - -// There's now a network connection, after some period of disconnection. -// Do all communication that we can. -// -void CLIENT_STATE::network_available() { - unsigned int i; - - have_sporadic_connection = true; - for (i=0; ipers_file_xfers.size(); i++) { - PERS_FILE_XFER* pfx = pers_file_xfers->pers_file_xfers[i]; - pfx->next_request_time = 0; - } - for (i=0; imin_rpc_time = 0; - } - - // tell active tasks that network is available (for Folding@home) - // - active_tasks.network_available(); -} - // Quit running applications, quit benchmarks, // write the client_state.xml file // (in principle we could also terminate net_xfers here, diff --git a/client/client_state.h b/client/client_state.h index 64083d32a4..29d07e1aca 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -227,22 +227,6 @@ public: int detach_project(PROJECT*); int report_result_error(RESULT&, const char *format, ...); int reset_project(PROJECT*); - bool need_physical_connection; - // client wants to do network comm and no physical connection exists. - // Initially false; set whenever a Curl operation - // returns CURLE_COULDNT_RESOLVE_HOST, - // and a subsequent request to a highly-available site - // also returns CURLE_COULDNT_RESOLVE_HOST. - // cleared whenever we transfer data, or an operation - // returns some other value - // - bool have_sporadic_connection; - // we have a network connection, but it's likely to go away soon, - // so do as much network comm as possible - // (e.g. report completed results) - // - int network_status(); - void network_available(); bool no_gui_rpc; private: int link_app(PROJECT*, APP*); diff --git a/client/cs_account.C b/client/cs_account.C index ce87c721aa..2626edd86b 100644 --- a/client/cs_account.C +++ b/client/cs_account.C @@ -90,7 +90,6 @@ int PROJECT::write_account_file() { int PROJECT::parse_account(FILE* in) { char buf[256]; int retval; - bool got_venue_prefs = false; strcpy(master_url, ""); strcpy(authenticator, ""); diff --git a/client/cs_scheduler.C b/client/cs_scheduler.C index 2b6bcc6310..5cee067125 100644 --- a/client/cs_scheduler.C +++ b/client/cs_scheduler.C @@ -446,7 +446,7 @@ PROJECT* CLIENT_STATE::find_project_with_overdue_results() { if (p->suspended_via_gui) continue; if (!r->ready_to_report) continue; - if (have_sporadic_connection) { + if (net_status.have_sporadic_connection) { return p; } double cushion = std::max( diff --git a/client/gui_rpc_server_ops.C b/client/gui_rpc_server_ops.C index 6b2e5f584a..4fc579b730 100644 --- a/client/gui_rpc_server_ops.C +++ b/client/gui_rpc_server_ops.C @@ -534,7 +534,7 @@ static void handle_get_statistics(char*, MIOFILE& fout) { } static void handle_network_status(char*, MIOFILE& fout) { - fout.printf("%d\n", gstate.network_status()); + fout.printf("%d\n", net_status.network_status()); } static void handle_get_cc_status(MIOFILE& fout) { @@ -543,13 +543,13 @@ static void handle_get_cc_status(MIOFILE& fout) { " %d\n" " %d\n" "\n", - gstate.network_status(), + net_status.network_status(), gstate.acct_mgr_info.password_error?1:0 ); } static void handle_network_available(char*, MIOFILE&) { - gstate.network_available(); + net_status.network_available(); } static void handle_get_project_init_status(char*, MIOFILE& fout) { diff --git a/client/http_curl.C b/client/http_curl.C index 9805fe42c6..47ebba4f28 100644 --- a/client/http_curl.C +++ b/client/http_curl.C @@ -974,21 +974,11 @@ void HTTP_OP_SET::got_select(FDSET_GROUP&, double timeout) { sprintf(hop->error_msg, "HTTP error %d", hop->response); } } - gstate.need_physical_connection = false; + net_status.need_physical_connection = false; } else { strcpy(hop->error_msg, curl_easy_strerror(hop->CurlResult)); - // If operation failed, - // it could be because there's no physical network connection. - // Find out for sure by trying to contact google - // - if ((gstate.lookup_website_op.error_num != ERR_IN_PROGRESS) - && !gstate.need_physical_connection - ) { - std::string url = "http://www.google.com"; - //msg_printf(0, MSG_ERROR, "need_phys_conn %d trying google", gstate.need_physical_connection); - gstate.lookup_website_op.do_rpc(url); - } hop->http_op_retval = ERR_HTTP_ERROR; + net_status.got_http_error(); } if (!hop->http_op_retval && hop->http_op_type == HTTP_OP_POST2) { diff --git a/client/net_stats.C b/client/net_stats.C index 00c44aac24..61db643914 100644 --- a/client/net_stats.C +++ b/client/net_stats.C @@ -48,6 +48,8 @@ #define EXP_DECAY_RATE (1./3600) +NET_STATUS net_status; + NET_STATS::NET_STATS() { last_time = 0; memset(&up, 0, sizeof(up)); @@ -141,4 +143,75 @@ int NET_STATS::parse(MIOFILE& in) { return ERR_XML_PARSE; } +// Return: +// 0 if we have network connections open +// 1 if we need a physical connection +// 2 if we don't have any connections, and don't need any +// 3 if a website lookup is pending (try again later) +// +// There's a 10-second slop factor; +// if we've done network comm in the last 10 seconds, +// we act as if we're doing it now. +// (so that polling mechanisms have a change to trigger) +// +int NET_STATUS::network_status() { + static double last_comm_time=0; + + if (gstate.http_ops->nops()) { + last_comm_time = gstate.now; + } + if (gstate.now - last_comm_time < 10) { + //msg_printf(0, MSG_INFO, "nops %d; return 0", http_ops->nops()); + return 0; + } + if (gstate.lookup_website_op.error_num == ERR_IN_PROGRESS) { + return 3; + } + if (need_physical_connection) { + //msg_printf(0, MSG_INFO, "need phys conn; return 1"); + return 1; + } + if (gstate.active_tasks.want_network()) { + return 1; + } + have_sporadic_connection = false; + //msg_printf(0, MSG_INFO, "returning 2"); + return 2; +} + +// There's now a network connection, after some period of disconnection. +// Do all communication that we can. +// +void NET_STATUS::network_available() { + unsigned int i; + + have_sporadic_connection = true; + for (i=0; ipers_file_xfers.size(); i++) { + PERS_FILE_XFER* pfx = gstate.pers_file_xfers->pers_file_xfers[i]; + pfx->next_request_time = 0; + } + for (i=0; imin_rpc_time = 0; + } + + // tell active tasks that network is available (for Folding@home) + // + gstate.active_tasks.network_available(); +} + +// An HTTP operation failed; +// it could be because there's no physical network connection. +// Find out for sure by trying to contact google +// +void NET_STATUS::got_http_error() { + if ((gstate.lookup_website_op.error_num != ERR_IN_PROGRESS) + && !need_physical_connection + ) { + std::string url = "http://www.google.com"; + //msg_printf(0, MSG_ERROR, "need_phys_conn %d trying google", gstate.need_physical_connection); + gstate.lookup_website_op.do_rpc(url); + } +} + const char *BOINC_RCSID_733b4006f5 = "$Id$"; diff --git a/client/net_stats.h b/client/net_stats.h index 0c825a059b..b7006f5c74 100644 --- a/client/net_stats.h +++ b/client/net_stats.h @@ -56,4 +56,31 @@ public: int parse(MIOFILE&); }; +class NET_STATUS { +public: + bool need_physical_connection; + // client wants to do network comm and no physical connection exists. + // Initially false; set whenever a Curl operation + // returns CURLE_COULDNT_RESOLVE_HOST, + // and a subsequent request to a highly-available site + // also returns CURLE_COULDNT_RESOLVE_HOST. + // cleared whenever we transfer data, + // or an operation returns some other value + // + bool have_sporadic_connection; + // we have a network connection, but it's likely to go away soon, + // so do as much network comm as possible + // (e.g. report completed results) + // + int network_status(); + void network_available(); + void got_http_error(); + NET_STATUS() { + need_physical_connection = false; + have_sporadic_connection = false; + } +}; + +extern NET_STATUS net_status; + #endif diff --git a/client/pers_file_xfer.C b/client/pers_file_xfer.C index a919c3a7fd..fbae16bea2 100644 --- a/client/pers_file_xfer.C +++ b/client/pers_file_xfer.C @@ -366,7 +366,7 @@ void PERS_FILE_XFER::do_backoff() { // don't count it as a server failure if network is down // - if (!gstate.need_physical_connection) { + if (!net_status.need_physical_connection) { nretry++; } diff --git a/client/scheduler_op.C b/client/scheduler_op.C index d7735b0934..8508f7563a 100644 --- a/client/scheduler_op.C +++ b/client/scheduler_op.C @@ -183,7 +183,7 @@ void SCHEDULER_OP::backoff(PROJECT* p, const char *error_msg ) { // if network is down, don't count it as RPC failure // - if (!gstate.need_physical_connection) { + if (!net_status.need_physical_connection) { p->nrpc_failures++; } //msg_printf(p, MSG_INFO, "nrpc_failures %d need_conn %d", p->nrpc_failures, gstate.need_physical_connection); diff --git a/lib/app_ipc.C b/lib/app_ipc.C index 36eed0aa8b..3f4c3f97df 100755 --- a/lib/app_ipc.C +++ b/lib/app_ipc.C @@ -26,13 +26,12 @@ #include #endif -#include "app_ipc.h" #include "parse.h" #include "error_numbers.h" #include "util.h" #include "filesys.h" #include "miofile.h" - +#include "app_ipc.h" using std::string;