Commit 5c083e12 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

Revert "zdtm: clean up socket_listen"

This reverts commit 46dc368f.

There will be another one. Instead of hard rebase I decide to
do a revert instead.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 46dc368f
#include "zdtmtst.h"
const char *test_doc = "Check TCP listen sockets\n";
const char *test_author = "Andrew Vagin <avagin@parallels.com>";
const char *test_doc = "static test for AIO\n";
const char *test_author = "Andrew Vagin <avagin@sw.ru>";
/* Description:
* Create two tcp socket, server send asynchronous request on
......@@ -56,39 +56,81 @@ int main(int argc, char **argv)
if (pid == 0) {
/*
* Client of TCP connection
* Chiled is client of TCP connection
*/
close(fd_s);
fd = init_client("127.0.0.1", PORT);
if (fd < 0)
return 1;
memset(&aiocb, 0, sizeof(struct aiocb));
aiocb.aio_fildes = fd;
aiocb.aio_buf = buf;
aiocb.aio_nbytes = BUF_SIZE;
ret = aio_read(&aiocb);
if (ret < 0) {
err("aio_read failed %m");
return 1;
}
/* Wait for request completion */
aioary[0] = &aiocb;
ret = aio_error(&aiocb);
#ifdef DEBUG
test_msg(".");
#endif
res = 0;
again:
if (aio_suspend(aioary, 1, NULL) < 0 && errno != EINTR) {
err("aio_suspend failed %m");
res = 1;
}
ret = aio_error(&aiocb);
if (!res && ret == EINPROGRESS) {
#ifdef DEBUG
test_msg("restart aio_suspend\n");
#endif
goto again;
}
if (ret != 0) {
err("Error at aio_error() %s", strerror(ret));
res = 1;
}
if (aio_return(&aiocb) != BUF_SIZE) {
err("Error at aio_return() %m");
res = 1;
}
close(fd);
return 0;
return res;
}
/*
* Server of TCP connection
* parent is server of TCP connection
*/
fd = accept_server(fd_s);
close(fd_s);
if (fd < 0) {
fail("can't accept client connection");
err("can't accept client connection %m");
goto error;
}
close(fd_s);
if (write(fd, buf, BUF_SIZE) < BUF_SIZE) {
err("can't write");
goto error;
}
close(fd);
if (wait(&status) < 0) {
err("wait failed %m");
goto error;
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
err("The child failed. Return %d", WEXITSTATUS(status));
return 1;
} else if (WIFSIGNALED(status)) {
err("The child was killed by %d", WTERMSIG(status));
err("chiled failed. Return %d", WEXITSTATUS(status));
return 1;
}
......@@ -97,7 +139,7 @@ int main(int argc, char **argv)
error:
kill(pid, SIGKILL);
wait(&status);
return 1;
return -1;
}
int init_server(int port)
......@@ -108,7 +150,7 @@ int init_server(int port)
memset(&addr,0,sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("0.0.0.0");
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(port);
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment