From 9279ef467e3cd01e7f07dc8ea28256cb01e2958e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 24 Nov 2011 21:16:32 +0000 Subject: [PATCH] - GUI RPC client lib: change setsockopt() for receive timeout to work on Windows. From Fred. svn path=/trunk/boinc/; revision=24648 --- checkin_notes | 10 ++++++++++ lib/gui_rpc_client.cpp | 7 +++++++ ssim/des.h | 10 ++++++++++ ssim/ssim.cpp | 23 +++++++++++++++++++---- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/checkin_notes b/checkin_notes index 77e0c4fabc..232e08bb07 100644 --- a/checkin_notes +++ b/checkin_notes @@ -8660,3 +8660,13 @@ Charlie 23 Nov 2011 MacBitmapComboBox.cpp sg_ProjectPanel.cpp sg_TaskPanel.cpp + +David 24 Nov 2011 + - GUI RPC client lib: change setsockopt() for receive timeout + to work on Windows. From Fred. + + lib/ + gui_rpc_client.cpp + ssim/ + ssim.cpp + des.h diff --git a/lib/gui_rpc_client.cpp b/lib/gui_rpc_client.cpp index 0b14cee550..407995b581 100644 --- a/lib/gui_rpc_client.cpp +++ b/lib/gui_rpc_client.cpp @@ -127,12 +127,19 @@ int RPC_CLIENT::init(const char* host, int port) { // set up receive timeout; avoid hang if client doesn't respond // +#ifdef _WIN32 + DWORD dwTime = 30000; + if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&dwTime, sizeof dwTime)) { + // not fatal + } +#else struct timeval tv; tv.tv_sec = 30; tv.tv_usec = 0; if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv)) { // not fatal } +#endif retval = connect(sock, (const sockaddr*)(&addr), addr_len(addr)); if (retval) { #ifdef _WIN32 diff --git a/ssim/des.h b/ssim/des.h index 1ce14ed9d3..8fd1863a58 100644 --- a/ssim/des.h +++ b/ssim/des.h @@ -19,6 +19,16 @@ struct SIMULATOR { events.push_back(e); push_heap(events.begin(), events.end(), compare); } + void remove(EVENT* e) { + vector::iterator i; + for (i=events.begin(); i!=events.end(); i++) { + if (*i == e) { + events.erase(i); + make_heap(events.begin(), events.end(), compare); + break; + } + } + } void simulate(double dur) { while (events.size()) { EVENT* e = events.front(); diff --git a/ssim/ssim.cpp b/ssim/ssim.cpp index 64d175264a..4e98eb0d5e 100644 --- a/ssim/ssim.cpp +++ b/ssim/ssim.cpp @@ -189,7 +189,7 @@ struct CHUNK : DATA_UNIT { // CHUNK_ON_HOST *c = *(hosts.begin()); c->transfer_in_progress = true; - c->t = sim.now + size/UPLOAD_BYTES_SEC; + c->t = sim.now + (drand()+.5)*size/UPLOAD_BYTES_SEC; printf("%.0f: starting upload of %s\n", sim.now, c->name); sim.insert(c); } @@ -197,8 +197,9 @@ struct CHUNK : DATA_UNIT { // see if we can remove chunk from server // int n=0; - for (unsigned int i=0; i::iterator i; + for (i=hosts.begin(); i!=hosts.end(); i++) { + CHUNK_ON_HOST* c = *i; if (c->present_on_host) { n++; } @@ -256,6 +257,12 @@ struct META_CHUNK : DATA_UNIT { } } + virtual void cleanup() { + for (unsigned int i=0; icleanup(); + } + } + // this is called only if we're uploading // void child_upload_complete() { @@ -272,6 +279,11 @@ struct META_CHUNK : DATA_UNIT { assign(); if (parent && parent->uploading) { parent->child_upload_complete(); + } else { + // if we're not reconstructing parent, + // delete any chunks not being downloaded + // + cleanup(); } } }; @@ -328,6 +340,9 @@ void HOST::handle() { for (p = chunks.begin(); p != chunks.end(); p++) { CHUNK_ON_HOST* c = *p; c->chunk->host_failed(c); + if (c->transfer_in_progress) { + sim.remove(c); + } delete c; } } @@ -375,7 +390,7 @@ void CHUNK::assign() { printf("%.0f: assigning chunk %s to host %d\n", sim.now, name, h->id); c->host = h; c->chunk = this; - c->t = sim.now + size/DOWNLOAD_BYTES_SEC; + c->t = sim.now + (drand()+.5)*size/DOWNLOAD_BYTES_SEC; hosts.insert(c); h->chunks.insert(c); sim.insert(c);