diff options
author | David Robillard <d@drobilla.net> | 2021-01-02 14:46:29 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-01-02 14:46:29 +0100 |
commit | bd0214b1da66225f410641692e89e492f668472a (patch) | |
tree | 80956f373070734dc14a7f103e5fa21a5baa0b6e /test/socket_test.cpp | |
parent | 5c263125aeae87dcd4694a4d3a4781bda7247a00 (diff) | |
download | raul-bd0214b1da66225f410641692e89e492f668472a.tar.gz raul-bd0214b1da66225f410641692e89e492f668472a.tar.bz2 raul-bd0214b1da66225f410641692e89e492f668472a.zip |
Format all code with clang-format
Diffstat (limited to 'test/socket_test.cpp')
-rw-r--r-- | test/socket_test.cpp | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/test/socket_test.cpp b/test/socket_test.cpp index f2f04fc..e1638d6 100644 --- a/test/socket_test.cpp +++ b/test/socket_test.cpp @@ -29,70 +29,70 @@ int main() { - using Socket = Raul::Socket; - - std::string unix_uri("unix:///tmp/raul_test_sock"); - std::string tcp_uri("tcp://127.0.0.1:12345"); - - Socket unix_server_sock(Socket::Type::UNIX); - Socket tcp_server_sock(Socket::Type::TCP); - assert(unix_server_sock.bind(unix_uri)); - assert(unix_server_sock.listen()); - assert(tcp_server_sock.bind(tcp_uri)); - assert(tcp_server_sock.listen()); - - const pid_t child_pid = fork(); - if (child_pid) { - // This is the parent (server) process - int status = 0; - waitpid(child_pid, &status, 0); - - struct pollfd pfds[2]; - pfds[0].fd = unix_server_sock.fd(); - pfds[0].events = POLLIN; - pfds[0].revents = 0; - pfds[1].fd = tcp_server_sock.fd(); - pfds[1].events = POLLIN; - pfds[1].revents = 0; - - unsigned n_received = 0; - while (n_received < 2) { - const int ret = poll(pfds, 2, -1); - assert(ret != -1); - - if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { - break; - } - - if (ret == 0) { - fprintf(stderr, "poll returned with no data\n"); - continue; - } - - if (pfds[0].revents & POLLIN) { - std::shared_ptr<Socket> conn = unix_server_sock.accept(); - ++n_received; - } - - if (pfds[1].revents & POLLIN) { - std::shared_ptr<Socket> conn = tcp_server_sock.accept(); - ++n_received; - } - } - - unix_server_sock.shutdown(); - tcp_server_sock.shutdown(); - unlink("/tmp/raul_test_sock"); - fprintf(stderr, "n received: %u\n", n_received); - return n_received != 2; - } - - // This is the child (client) process - Raul::Socket unix_sock(Socket::Type::UNIX); - Raul::Socket tcp_sock(Socket::Type::TCP); - - assert(unix_sock.connect(unix_uri)); - assert(tcp_sock.connect(tcp_uri)); - - return 0; + using Socket = Raul::Socket; + + std::string unix_uri("unix:///tmp/raul_test_sock"); + std::string tcp_uri("tcp://127.0.0.1:12345"); + + Socket unix_server_sock(Socket::Type::UNIX); + Socket tcp_server_sock(Socket::Type::TCP); + assert(unix_server_sock.bind(unix_uri)); + assert(unix_server_sock.listen()); + assert(tcp_server_sock.bind(tcp_uri)); + assert(tcp_server_sock.listen()); + + const pid_t child_pid = fork(); + if (child_pid) { + // This is the parent (server) process + int status = 0; + waitpid(child_pid, &status, 0); + + struct pollfd pfds[2]; + pfds[0].fd = unix_server_sock.fd(); + pfds[0].events = POLLIN; + pfds[0].revents = 0; + pfds[1].fd = tcp_server_sock.fd(); + pfds[1].events = POLLIN; + pfds[1].revents = 0; + + unsigned n_received = 0; + while (n_received < 2) { + const int ret = poll(pfds, 2, -1); + assert(ret != -1); + + if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { + break; + } + + if (ret == 0) { + fprintf(stderr, "poll returned with no data\n"); + continue; + } + + if (pfds[0].revents & POLLIN) { + std::shared_ptr<Socket> conn = unix_server_sock.accept(); + ++n_received; + } + + if (pfds[1].revents & POLLIN) { + std::shared_ptr<Socket> conn = tcp_server_sock.accept(); + ++n_received; + } + } + + unix_server_sock.shutdown(); + tcp_server_sock.shutdown(); + unlink("/tmp/raul_test_sock"); + fprintf(stderr, "n received: %u\n", n_received); + return n_received != 2; + } + + // This is the child (client) process + Raul::Socket unix_sock(Socket::Type::UNIX); + Raul::Socket tcp_sock(Socket::Type::TCP); + + assert(unix_sock.connect(unix_uri)); + assert(tcp_sock.connect(tcp_uri)); + + return 0; } |