-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl.c
48 lines (35 loc) · 827 Bytes
/
cl.c
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
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "math.h"
#include "net.h"
#include "cl.h"
int32_t
main(int32_t argc, char * const *argv)
{
int32_t i, sfd;
struct Msg msg;
if (argc != ARGS_LEN)
usage(USAGE_STR);
/* when tloc is NULL, time() can't fail */
srand(time(NULL));
if ((sfd = createSocket(argv[DESTINATION], argv[PORT], 0)) < 0)
err(1, "createSocket");
for (i = 0; i < MIN_REQS + rand(); ++i) {
usleep(rand() % MAX_SLEEP);
msg.op = rand() % NUM_OPS;
msg.arg1 = rand() % (2 << CHAR_BIT);
msg.arg2 = rand() % (2 << CHAR_BIT);
printMsg("request:", msg, 0);
if (writeMsg(sfd, msg))
err(1, "writeMsg");
if (readMsg(sfd, &msg))
err(1, "readMsg");
printMsg("reply:", msg, 1);
}
close(sfd);
return 0;
}