-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathNagleTest.c
47 lines (41 loc) · 983 Bytes
/
NagleTest.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
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "../../tool/TimeTool.h"
#include "../../tool/CommonTool.h"
#include <string.h>
#include <unistd.h>
#include <netinet/tcp.h>
int on;
int cb(int fd)
{
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) {
logx("setsockopt error!");
return -1;
}
return 0;
}
int main(int argc, char *argv[])
{
if (argc != 4) {
logx("usage : %s <ip/hostname> <service/port> <enable_nagle>", argv[0]);
exit(1);
}
on = atoi(argv[3]) == 1 ? 0 : 1;
int fd = -1;
if ((fd = tcp_connect_cb(argv[1], argv[2], NULL)) < 0) {
logx("tcp_connect error!");
exit(1);
}
char msg[128];
memset(msg, 'a', sizeof(msg));
msg[127] = 0;
for (;;) {
for (int i = 0; i < strlen(msg); i++) {
write(fd, msg + i, 1);
logx("send %c to server", msg[i]);
}
}
close(fd);
}