-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkInterface.cpp
50 lines (46 loc) · 1.52 KB
/
NetworkInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*************************************************************************
> File Name: NetworkInterface.cpp
> Author: Weidong, ZHANG
> Mail: [email protected]
> Created Time: Thu 01 Jan 2015 06:50:05 AM PST
************************************************************************/
#include "NetworkInterface.h"
namespace pdfs {
NetworkInterface::NetworkInterface()
{
_workerPool = nullptr;
}
NetworkInterface::NetworkInterface(Cluster &cluster){
_cluster = cluster;
}
ssize_t NetworkInterface::connect()
{
struct timeval start, end;
long seconds, useconds, elapse;
gettimeofday(&start, NULL);
/////////////////////////////////
std::clog << "Connecting...\n";
_workerPool = new ThreadPool(3);
_workerPool->initializeThreads();
_workerPool->assignWork(new ClusterHandler(1, 0));
size_t cluster_size = std::numeric_limits<int>::max();
// Wait until two Cluster's size equal
while (true)
{
size_t newClusterSize = _cluster.getClusterSize();
//std::clog << cluster_size << ":" << newClusterSize << std::endl;
if (cluster_size == newClusterSize)
{
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
elapse = seconds * 1000 * 1000 + useconds;
//cout << "Recv time Consumption:" << elapse << "(us)" << endl;
return 1;
}
cluster_size = newClusterSize;
usleep(600001);
}
return -1;
}
} // end of namespace pdfs