-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_splice.cpp
More file actions
40 lines (29 loc) · 831 Bytes
/
Copy pathtest_splice.cpp
File metadata and controls
40 lines (29 loc) · 831 Bytes
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
//
// Created by s on 19-5-3.
//
/*
* 测试splice函数
* 零拷贝,在两个文件描述符之间传递数据
*/
#include "myutili.h"
int main (int argc, char *argv[])
{
if (argc <= 2)
{
printf ("usage: %s ip_address port_number\n", basename (argv[0]));
exit (EXIT_FAILURE);
}
const char *ip = argv[1];
int port = atoi (argv[2]);
int listenfd = Start_TCPserver_up (ip, port);
struct sockaddr_in cli_addr;
socklen_t cli_addr_length = sizeof (cli_addr);
int connfd = Accept (listenfd, (struct sockaddr *) &cli_addr, &cli_addr_length);
int pipefd[2];
Pipe (pipefd);
Splice (connfd, NULL, pipefd[1], NULL, 32768, SPLICE_F_MORE | SPLICE_F_MOVE);
Splice (pipefd[0], NULL, connfd, NULL, 32768, SPLICE_F_MORE | SPLICE_F_MOVE);
close (connfd);
close (listenfd);
return 0;
}