Typos corrected, impl-details added.

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1057 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
adrian
2012-04-12 09:50:43 +00:00
parent 223f466f9e
commit ec9a1c33d1
3 changed files with 13 additions and 5 deletions

View File

@ -12,7 +12,7 @@ JobClient::JobClient(std::string server, int port)
perror("[Client@gethostbyname()]");
exit(1);
}
srand(time(NULL));
srand(time(NULL)); // needed for random backoff (see connectToServer)
}
bool JobClient::connectToServer()
@ -34,22 +34,25 @@ bool JobClient::connectToServer()
memcpy(&serv_addr.sin_addr.s_addr, m_server_ent->h_addr, m_server_ent->h_length);
serv_addr.sin_port = htons(m_server_port);
int retries = 3;
int retries = RETRY_COUNT;
while(true) {
if(connect(m_sockfd, (sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("[Client@connect()]");
if(retries > 0) {
int delay = rand() % 5 + 3;
// Wait RAND_BACKOFF_TSTART to RAND_BACKOFF_TEND seconds:
int delay = rand() % (RAND_BACKOFF_TEND-RAND_BACKOFF_TSTART) + RAND_BACKOFF_TSTART;
cout << "[Client] Retrying to connect to server in " << delay << "s..." << endl;
sleep(delay);
--retries;
continue;
}
cout << "|Client] Unable to reconnect (tried " << RETRY_COUNT << " times); "
<< "I'll give it up!" << endl;
return false; // finally: unable to connect, give it up :-(
}
break; // connected! :-)
}
cout << "[Client] Connected established!" << endl;
cout << "[Client] Connection established!" << endl;
return true;
}

View File

@ -17,6 +17,11 @@
#include "controller/ExperimentData.hpp"
#include "jobserver/messagedefs/FailControlMessage.pb.h"
// FIXME This should be part of a "client config" (?).
#define RAND_BACKOFF_TSTART 3
#define RAND_BACKOFF_TEND 8
#define RETRY_COUNT 3
namespace fi {
/**

View File

@ -32,7 +32,7 @@ public:
/**
* Receive Protobuf-generated message
* @param sockfd open socket descriptor to write to
* @param sockfd open socket descriptor to read from
* @param Msg Reference to Protobuf generated message type
* \return false if message reception failed
*/