-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.cpp
36 lines (32 loc) · 1.15 KB
/
client.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
#include "RDMAClientSocket.h"
#include <iostream>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
uint64_t getnsecs(const struct timespec& in)
{
return in.tv_sec * 1000000000LL + in.tv_nsec;
}
int main(int argc, char* argv[])
{
try {
rdma::ClientSocket clientSocket(argv[1], argv[2], atoi(argv[3]), atoi(argv[4]));
struct timespec nbegin;
struct timespec nend;
const int count = atoi(argv[5]);
clock_gettime(CLOCK_REALTIME, &nbegin);
for(int i = 0; i < count; ++i) {
rdma::Buffer sendPacket = clientSocket.getWriteBuffer();
memset(sendPacket.get(), 'b', sendPacket.size);
clientSocket.write(sendPacket);
rdma::Buffer readPacket = clientSocket.read();
clientSocket.returnReadBuffer(readPacket);
}
clock_gettime(CLOCK_REALTIME, &nend);
const uint64_t nsecs = getnsecs(nend) - getnsecs(nbegin);
std::cout << "wrote " << count << " packets of size " << argv[3] << " in " << nsecs << " nsecs" << std::endl;
} catch(std::exception& e) {
std::cerr << "exception: " << e.what() << std::endl;
}
return 0;
}