diff options
Diffstat (limited to 'src/server/SocketListener.cpp')
-rw-r--r-- | src/server/SocketListener.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/server/SocketListener.cpp b/src/server/SocketListener.cpp index b4b50a14..fb961ee2 100644 --- a/src/server/SocketListener.cpp +++ b/src/server/SocketListener.cpp @@ -19,13 +19,16 @@ #include "Engine.hpp" #include "SocketServer.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/World.hpp" -#include "raul/Socket.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/URI.hpp> +#include <ingen/World.hpp> +#include <raul/Socket.hpp> #include <poll.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> #include <cerrno> @@ -33,12 +36,12 @@ #include <cstdint> #include <cstdlib> #include <cstring> +#include <memory> #include <sstream> #include <string> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { static constexpr const char* const unix_scheme = "unix://"; @@ -48,29 +51,29 @@ get_link_target(const char* link_path) // Stat the link to get the required size for the target path struct stat link_stat{}; if (lstat(link_path, &link_stat)) { - return std::string(); + return {}; } // Allocate buffer and read link target - char* target = (char*)calloc(1, link_stat.st_size + 1); + char* target = static_cast<char*>(calloc(1, link_stat.st_size + 1)); if (readlink(link_path, target, link_stat.st_size) != -1) { - const std::string result(target); + std::string result(target); free(target); return result; } free(target); - return std::string(); + return {}; } static void ingen_listen(Engine* engine, - Raul::Socket* unix_sock, - Raul::Socket* net_sock); + raul::Socket* unix_sock, + raul::Socket* net_sock); SocketListener::SocketListener(Engine& engine) - : unix_sock(Raul::Socket::Type::UNIX) - , net_sock(Raul::Socket::Type::TCP) + : unix_sock(raul::Socket::Type::UNIX) + , net_sock(raul::Socket::Type::TCP) , thread(new std::thread(ingen_listen, &engine, &unix_sock, &net_sock)) {} @@ -82,7 +85,7 @@ SocketListener::~SocketListener() { } static void -ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) +ingen_listen(Engine* engine, raul::Socket* unix_sock, raul::Socket* net_sock) { ingen::World& world = engine->world(); @@ -138,7 +141,7 @@ ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) } if (unix_sock->fd() == -1 && net_sock->fd() == -1) { - return; // No sockets to listen to, exit thread + return; // No sockets to listen to, exit thread } struct pollfd pfds[2]; @@ -162,22 +165,26 @@ ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) if (ret == -1) { world.log().error("Poll error: %1%\n", strerror(errno)); break; - } else if (ret == 0) { + } + + if (ret == 0) { world.log().warn("Poll returned with no data\n"); continue; - } else if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { + } + + if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { break; } if (pfds[0].revents & POLLIN) { - SPtr<Raul::Socket> conn = unix_sock->accept(); + auto conn = unix_sock->accept(); if (conn) { new SocketServer(world, *engine, conn); } } if (pfds[1].revents & POLLIN) { - SPtr<Raul::Socket> conn = net_sock->accept(); + auto conn = net_sock->accept(); if (conn) { new SocketServer(world, *engine, conn); } @@ -189,5 +196,4 @@ ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) } } -} // namespace server -} // namespace ingen +} // namespace ingen::server |