From: Geliang Tang <tanggeliang@kylinos.cn>
Replaces pipe-based synchronization with Unix domain socket pairs
(SOCK_DGRAM) for better bidirectional communication reliability
between server and client processes.
These codes are from mptcp_inq.c.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../selftests/net/mptcp/mptcp_sockopt.c | 36 +++++++++----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index 366e4aa4df0b..add29bdda9e5 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -593,7 +593,7 @@ static void do_getsockopts(struct so_state *s, int fd, size_t r, size_t w)
do_getsockopt_mptcp_full_info(s, fd);
}
-static void connect_one_server(int fd, int pipefd)
+static void connect_one_server(int fd, int unixfd)
{
char buf[4096], buf2[4096];
size_t len, i, total;
@@ -618,9 +618,9 @@ static void connect_one_server(int fd, int pipefd)
do_getsockopts(&s, fd, 0, 0);
/* un-block server */
- ret = read(pipefd, buf2, 4);
+ ret = read(unixfd, buf2, 4);
assert(ret == 4);
- close(pipefd);
+ close(unixfd);
assert(strncmp(buf2, "xmit", 4) == 0);
@@ -662,7 +662,7 @@ static void connect_one_server(int fd, int pipefd)
close(fd);
}
-static void process_one_client(int fd, int pipefd)
+static void process_one_client(int fd, int unixfd)
{
ssize_t ret, ret2, ret3;
struct so_state s;
@@ -671,7 +671,7 @@ static void process_one_client(int fd, int pipefd)
memset(&s, 0, sizeof(s));
do_getsockopts(&s, fd, 0, 0);
- ret = write(pipefd, "xmit", 4);
+ ret = write(unixfd, "xmit", 4);
assert(ret == 4);
ret = read(fd, buf, sizeof(buf));
@@ -736,7 +736,7 @@ static int xaccept(int s)
return fd;
}
-static int server(int pipefd)
+static int server(int unixfd)
{
int fd = -1, r;
@@ -752,13 +752,13 @@ static int server(int pipefd)
break;
}
- r = write(pipefd, "conn", 4);
+ r = write(unixfd, "conn", 4);
assert(r == 4);
alarm(15);
r = xaccept(fd);
- process_one_client(r, pipefd);
+ process_one_client(r, unixfd);
return 0;
}
@@ -801,7 +801,7 @@ static void test_ip_tos_sockopt(int fd)
xerror("expect socklen_t == -1");
}
-static int client(int pipefd)
+static int client(int unixfd)
{
int fd = -1;
@@ -820,7 +820,7 @@ static int client(int pipefd)
test_ip_tos_sockopt(fd);
- connect_one_server(fd, pipefd);
+ connect_one_server(fd, unixfd);
return 0;
}
@@ -867,31 +867,31 @@ int main(int argc, char *argv[])
{
int e1, e2, wstatus;
pid_t s, c, ret;
- int pipefds[2];
+ int unixfds[2];
parse_opts(argc, argv);
init_rng();
- e1 = pipe(pipefds);
+ e1 = socketpair(AF_UNIX, SOCK_DGRAM, 0, unixfds);
if (e1 < 0)
- die_perror("pipe");
+ die_perror("socketpair");
s = xfork();
if (s == 0)
- return server(pipefds[1]);
+ return server(unixfds[1]);
- close(pipefds[1]);
+ close(unixfds[1]);
/* wait until server bound a socket */
- e1 = read(pipefds[0], &e1, 4);
+ e1 = read(unixfds[0], &e1, 4);
assert(e1 == 4);
c = xfork();
if (c == 0)
- return client(pipefds[0]);
+ return client(unixfds[0]);
- close(pipefds[0]);
+ close(unixfds[0]);
ret = waitpid(s, &wstatus, 0);
if (ret == -1)
--
2.48.1