-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cpp
86 lines (72 loc) · 1.49 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <thread>
#include <nng/nng.h>
#include <nng/protocol/reqrep0/req.h>
#include <nng/supplemental/util/platform.h>
void
fatal(const char* func, int rv)
{
fprintf(stderr, "%s: %s\n", func, nng_strerror(rv));
exit(1);
}
/* The client runs just once, and then returns. */
int
client(const char* url, const char* msecstr)
{
nng_socket sock;
int rv;
nng_msg* msg;
nng_time start;
nng_time end;
unsigned msec;
msec = atoi(msecstr);
if ((rv = nng_req0_open(&sock)) != 0) {
fatal("nng_req0_open", rv);
}
if ((rv = nng_dial(sock, url, NULL, 0)) != 0) {
fatal("nng_dial", rv);
}
for (;;)
{
start = nng_clock();
if ((rv = nng_msg_alloc(&msg, 0)) != 0) {
fatal("nng_msg_alloc", rv);
}
if ((rv = nng_msg_append_u32(msg, msec)) != 0) {
fatal("nng_msg_append_u32", rv);
}
if ((rv = nng_sendmsg(sock, msg, 0)) != 0) {
fatal("nng_send", rv);
}
if ((rv = nng_recvmsg(sock, &msg, 0)) != 0) {
fatal("nng_recvmsg", rv);
}
end = nng_clock();
nng_msg_free(msg);
}
nng_close(sock);
printf("Request took %u milliseconds.\n", (uint32_t)(end - start));
return (0);
}
#include <iostream>
using namespace std;
int
main(int argc, char** argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: %s <url> <secs>\n", argv[0]);
exit(EXIT_FAILURE);
}
int i = 0;
for (i = 0; i < 8*20; ++i)
{
thread th(&client, argv[1], argv[2]);
th.detach();
}
int ix = 0;
cin >> ix;
return 0;
}