summaryrefslogtreecommitdiffstats
path: root/src/socket/SocketListener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket/SocketListener.cpp')
-rw-r--r--src/socket/SocketListener.cpp128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/socket/SocketListener.cpp b/src/socket/SocketListener.cpp
deleted file mode 100644
index c2c1d0ee..00000000
--- a/src/socket/SocketListener.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- This file is part of Ingen.
- Copyright 2007-2012 David Robillard <http://drobilla.net/>
-
- Ingen is free software: you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free
- Software Foundation, either version 3 of the License, or any later version.
-
- Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for details.
-
- You should have received a copy of the GNU Affero General Public License
- along with Ingen. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <errno.h>
-#include <poll.h>
-
-#include <sstream>
-
-#include "ingen/AtomReader.hpp"
-#include "ingen/Configuration.hpp"
-#include "ingen/Interface.hpp"
-#include "ingen/Log.hpp"
-#include "ingen/World.hpp"
-#include "sord/sordmm.hpp"
-#include "sratom/sratom.h"
-
-#include "../server/Engine.hpp"
-#include "../server/EventWriter.hpp"
-#include "SocketListener.hpp"
-#include "SocketServer.hpp"
-
-namespace Ingen {
-namespace Socket {
-
-SocketListener::SocketListener(Ingen::World& world)
- : Raul::Thread()
- , _world(world)
- , _unix_sock(Socket::Type::UNIX)
- , _net_sock(Socket::Type::TCP)
-{
- // Create UNIX socket
- _unix_path = world.conf().option("socket").ptr<char>();
- const Raul::URI unix_uri("unix://" + _unix_path);
- if (!_unix_sock.bind(unix_uri) || !_unix_sock.listen()) {
- _world.log().error("Failed to create UNIX socket\n");
- _unix_sock.close();
- }
- _world.log().info(Raul::fmt("Listening on socket %1%\n") % unix_uri);
-
- // Create TCP socket
- int port = world.conf().option("engine-port").get<int32_t>();
- std::ostringstream ss;
- ss << "tcp://localhost:";
- ss << port;
- if (!_net_sock.bind(Raul::URI(ss.str())) || !_net_sock.listen()) {
- _world.log().error("Failed to create TCP socket\n");
- _net_sock.close();
- }
- _world.log().info(Raul::fmt("Listening on TCP port %1%\n") % port);
-
- start();
-}
-
-SocketListener::~SocketListener()
-{
- _exit_flag = true;
- _unix_sock.shutdown();
- _net_sock.shutdown();
- _unix_sock.close();
- _net_sock.close();
- join();
- unlink(_unix_path.c_str());
-}
-
-void
-SocketListener::_run()
-{
- Server::Engine* engine = (Server::Engine*)_world.engine().get();
-
- struct pollfd pfds[2];
- int nfds = 0;
- if (_unix_sock.fd() != -1) {
- pfds[nfds].fd = _unix_sock.fd();
- pfds[nfds].events = POLLIN;
- pfds[nfds].revents = 0;
- ++nfds;
- }
- if (_net_sock.fd() != -1) {
- pfds[nfds].fd = _net_sock.fd();
- pfds[nfds].events = POLLIN;
- pfds[nfds].revents = 0;
- ++nfds;
- }
-
- while (true) {
- // Wait for input to arrive at a socket
- const int ret = poll(pfds, nfds, -1);
- if (_exit_flag) {
- break;
- } else if (ret == -1) {
- _world.log().error(Raul::fmt("Poll error: %1%\n") % strerror(errno));
- break;
- } else if (ret == 0) {
- _world.log().error("Poll returned with no data\n");
- continue;
- }
-
- if (pfds[0].revents & POLLIN) {
- SPtr<Socket> conn = _unix_sock.accept();
- if (conn) {
- new SocketServer(_world, *engine, conn);
- }
- }
-
- if (pfds[1].revents & POLLIN) {
- SPtr<Socket> conn = _net_sock.accept();
- if (conn) {
- new SocketServer(_world, *engine, conn);
- }
- }
- }
-}
-
-} // namespace Ingen
-} // namespace Socket