- GUI RPC client lib: change setsockopt() for receive timeout

to work on Windows.  From Fred.


svn path=/trunk/boinc/; revision=24648
This commit is contained in:
David Anderson 2011-11-24 21:16:32 +00:00
parent 28c52cfd9d
commit 9279ef467e
4 changed files with 46 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -19,6 +19,16 @@ struct SIMULATOR {
events.push_back(e);
push_heap(events.begin(), events.end(), compare);
}
void remove(EVENT* e) {
vector<EVENT*>::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();

View File

@ -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<hosts.size(); i++) {
CHUNK_ON_HOST* c = hosts[i];
set<CHUNK_ON_HOST*>::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; i<children.size(); i++) {
children[i]->cleanup();
}
}
// 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);