diff options
author | David Robillard <d@drobilla.net> | 2015-02-07 01:05:13 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-02-07 01:05:13 +0000 |
commit | 82ab6f73fab060860addb30691d0e926b4723ee2 (patch) | |
tree | d468ccbcae5479161e3f2c899d9e302848ce4e8f /src/socket | |
parent | 8dad2d6e0805d0db2cca66f5901235884aad92da (diff) | |
download | ingen-82ab6f73fab060860addb30691d0e926b4723ee2.tar.gz ingen-82ab6f73fab060860addb30691d0e926b4723ee2.tar.bz2 ingen-82ab6f73fab060860addb30691d0e926b4723ee2.zip |
Demodularize socket stuff.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5535 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/socket')
-rw-r--r-- | src/socket/SocketClient.hpp | 55 | ||||
-rw-r--r-- | src/socket/SocketReader.cpp | 190 | ||||
-rw-r--r-- | src/socket/SocketReader.hpp | 74 | ||||
-rw-r--r-- | src/socket/SocketServer.hpp | 60 | ||||
-rw-r--r-- | src/socket/SocketWriter.cpp | 99 | ||||
-rw-r--r-- | src/socket/SocketWriter.hpp | 67 | ||||
-rw-r--r-- | src/socket/ingen_socket_client.cpp | 68 | ||||
-rw-r--r-- | src/socket/ingen_socket_server.cpp | 152 | ||||
-rw-r--r-- | src/socket/wscript | 28 |
9 files changed, 0 insertions, 793 deletions
diff --git a/src/socket/SocketClient.hpp b/src/socket/SocketClient.hpp deleted file mode 100644 index ae4b47d0..00000000 --- a/src/socket/SocketClient.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of Ingen. - Copyright 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/>. -*/ - -#ifndef INGEN_SOCKET_SOCKET_CLIENT_HPP -#define INGEN_SOCKET_SOCKET_CLIENT_HPP - -#include "SocketReader.hpp" -#include "SocketWriter.hpp" - -namespace Ingen { -namespace Socket { - -/** The client side of an Ingen socket connection. */ -class SocketClient : public SocketWriter -{ -public: - SocketClient(World& world, - const Raul::URI& uri, - SPtr<Raul::Socket> sock, - SPtr<Interface> respondee) - : SocketWriter(world.uri_map(), world.uris(), uri, sock) - , _respondee(respondee) - , _reader(world, *respondee.get(), sock) - {} - - virtual SPtr<Interface> respondee() const { - return _respondee; - } - - virtual void set_respondee(SPtr<Interface> respondee) { - _respondee = respondee; - } - -private: - SPtr<Interface> _respondee; - SocketReader _reader; -}; - -} // namespace Socket -} // namespace Ingen - -#endif // INGEN_SOCKET_SOCKET_CLIENT_HPP diff --git a/src/socket/SocketReader.cpp b/src/socket/SocketReader.cpp deleted file mode 100644 index 7e1a9e91..00000000 --- a/src/socket/SocketReader.cpp +++ /dev/null @@ -1,190 +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 "ingen/AtomReader.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/World.hpp" -#include "sord/sordmm.hpp" -#include "sratom/sratom.h" - -#include "SocketReader.hpp" - -namespace Ingen { -namespace Socket { - -SocketReader::SocketReader(Ingen::World& world, - Interface& iface, - SPtr<Raul::Socket> sock) - : _world(world) - , _iface(iface) - , _inserter(NULL) - , _msg_node(NULL) - , _socket(sock) - , _exit_flag(false) - , _thread(&SocketReader::run, this) -{} - -SocketReader::~SocketReader() -{ - _exit_flag = true; - _socket->shutdown(); - _thread.join(); -} - -SerdStatus -SocketReader::set_base_uri(SocketReader* iface, - const SerdNode* uri_node) -{ - return sord_inserter_set_base_uri(iface->_inserter, uri_node); -} - -SerdStatus -SocketReader::set_prefix(SocketReader* iface, - const SerdNode* name, - const SerdNode* uri_node) -{ - return sord_inserter_set_prefix(iface->_inserter, name, uri_node); -} - -SerdStatus -SocketReader::write_statement(SocketReader* iface, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang) -{ - if (!iface->_msg_node) { - iface->_msg_node = sord_node_from_serd_node( - iface->_world.rdf_world()->c_obj(), iface->_env, subject, 0, 0); - } - - return sord_inserter_write_statement( - iface->_inserter, flags, graph, - subject, predicate, object, - object_datatype, object_lang); -} - -void -SocketReader::run() -{ - Sord::World* world = _world.rdf_world(); - LV2_URID_Map* map = &_world.uri_map().urid_map_feature()->urid_map; - - // Open socket as a FILE for reading directly with serd - FILE* f = fdopen(_socket->fd(), "r"); - if (!f) { - _world.log().error(fmt("Failed to open connection (%1%)\n") - % strerror(errno)); - // Connection gone, exit - _socket.reset(); - return; - } - - // Use <ingen:/root/> as base URI so e.g. </foo/bar> will be a path - SordNode* base_uri = sord_new_uri( - world->c_obj(), (const uint8_t*)"ingen:/root/"); - - // Set up sratom and a forge to build LV2 atoms from model - Sratom* sratom = sratom_new(map); - SerdChunk chunk = { NULL, 0 }; - LV2_Atom_Forge forge; - lv2_atom_forge_init(&forge, map); - lv2_atom_forge_set_sink( - &forge, sratom_forge_sink, sratom_forge_deref, &chunk); - - // Make a model and reader to parse the next Turtle message - _env = world->prefixes().c_obj(); - SordModel* model = sord_new(world->c_obj(), SORD_SPO, false); - - _inserter = sord_inserter_new(model, _env); - - SerdReader* reader = serd_reader_new( - SERD_TURTLE, this, NULL, - (SerdBaseSink)set_base_uri, - (SerdPrefixSink)set_prefix, - (SerdStatementSink)write_statement, - NULL); - - serd_env_set_base_uri(_env, sord_node_to_serd_node(base_uri)); - serd_reader_start_stream(reader, f, (const uint8_t*)"(socket)", false); - - // Make an AtomReader to call Ingen Interface methods based on Atom - AtomReader ar(_world.uri_map(), - _world.uris(), - _world.log(), - _world.forge(), - _iface); - - struct pollfd pfd; - pfd.fd = _socket->fd(); - pfd.events = POLLIN; - pfd.revents = 0; - - while (!_exit_flag) { - if (feof(f)) { - break; // Lost connection - } - - // Wait for input to arrive at socket - int ret = poll(&pfd, 1, -1); - if (ret == -1 || (pfd.revents & (POLLERR|POLLHUP|POLLNVAL))) { - break; // Hangup - } else if (!ret) { - continue; // No data, shouldn't happen - } - - // Read until the next '.' - SerdStatus st = serd_reader_read_chunk(reader); - if (st == SERD_FAILURE || !_msg_node) { - continue; // Read nothing, e.g. just whitespace - } else if (st) { - _world.log().error(fmt("Read error: %1%\n") - % serd_strerror(st)); - continue; - } - - // Build an LV2_Atom at chunk.buf from the message - sratom_read(sratom, &forge, world->c_obj(), model, _msg_node); - - // Call _iface methods based on atom content - ar.write((const LV2_Atom*)chunk.buf); - - // Reset everything for the next iteration - chunk.len = 0; - sord_node_free(world->c_obj(), _msg_node); - _msg_node = NULL; - } - - fclose(f); - sord_inserter_free(_inserter); - serd_reader_end_stream(reader); - sratom_free(sratom); - serd_reader_free(reader); - sord_free(model); - free((uint8_t*)chunk.buf); - _socket.reset(); -} - -} // namespace Ingen -} // namespace Socket diff --git a/src/socket/SocketReader.hpp b/src/socket/SocketReader.hpp deleted file mode 100644 index 38afedef..00000000 --- a/src/socket/SocketReader.hpp +++ /dev/null @@ -1,74 +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/>. -*/ - -#ifndef INGEN_SOCKET_SOCKET_READER_HPP -#define INGEN_SOCKET_SOCKET_READER_HPP - -#include <thread> - -#include "raul/Socket.hpp" -#include "sord/sord.h" - -namespace Ingen { - -class Interface; -class World; - -namespace Socket { - -/** Calls Interface methods based on Turtle messages received via socket. */ -class SocketReader -{ -public: - SocketReader(World& world, - Interface& iface, - SPtr<Raul::Socket> sock); - - ~SocketReader(); - -private: - void run(); - - static SerdStatus set_base_uri(SocketReader* iface, - const SerdNode* uri_node); - - static SerdStatus set_prefix(SocketReader* iface, - const SerdNode* name, - const SerdNode* uri_node); - - static SerdStatus write_statement(SocketReader* iface, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang); - - World& _world; - Interface& _iface; - SerdEnv* _env; - SordInserter* _inserter; - SordNode* _msg_node; - SPtr<Raul::Socket> _socket; - bool _exit_flag; - std::thread _thread; -}; - -} // namespace Ingen -} // namespace Socket - -#endif // INGEN_SOCKET_SOCKET_READER_HPP diff --git a/src/socket/SocketServer.hpp b/src/socket/SocketServer.hpp deleted file mode 100644 index a977bdbc..00000000 --- a/src/socket/SocketServer.hpp +++ /dev/null @@ -1,60 +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/>. -*/ - -#ifndef INGEN_SOCKET_SOCKET_SERVER_HPP -#define INGEN_SOCKET_SOCKET_SERVER_HPP - -#include "raul/Socket.hpp" - -#include "../server/EventWriter.hpp" -#include "SocketReader.hpp" -#include "SocketWriter.hpp" - -namespace Ingen { -namespace Socket { - -/** The server side of an Ingen socket connection. */ -class SocketServer : public Server::EventWriter, public SocketReader -{ -public: - SocketServer(World& world, - Server::Engine& engine, - SPtr<Raul::Socket> sock) - : Server::EventWriter(engine) - , SocketReader(world, *this, sock) - , _engine(engine) - , _writer(new SocketWriter(world.uri_map(), - world.uris(), - sock->uri(), - sock)) - { - set_respondee(_writer); - engine.register_client(_writer->uri(), _writer); - } - - ~SocketServer() { - _engine.unregister_client(_writer->uri()); - } - -private: - Server::Engine& _engine; - SPtr<SocketWriter> _writer; -}; - -} // namespace Ingen -} // namespace Socket - -#endif // INGEN_SOCKET_SOCKET_SERVER_HPP diff --git a/src/socket/SocketWriter.cpp b/src/socket/SocketWriter.cpp deleted file mode 100644 index faed014c..00000000 --- a/src/socket/SocketWriter.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - This file is part of Ingen. - Copyright 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 <sys/types.h> -#include <sys/socket.h> - -#include "ingen/URIMap.hpp" - -#include "SocketWriter.hpp" - -#ifndef MSG_NOSIGNAL -# define MSG_NOSIGNAL 0 -#endif - -namespace Ingen { -namespace Socket { - -static size_t -socket_sink(const void* buf, size_t len, void* stream) -{ - SocketWriter* writer = (SocketWriter*)stream; - ssize_t ret = send(writer->fd(), buf, len, MSG_NOSIGNAL); - if (ret < 0) { - return 0; - } - return ret; -} - -SocketWriter::SocketWriter(URIMap& map, - URIs& uris, - const Raul::URI& uri, - SPtr<Raul::Socket> sock) - : AtomWriter(map, uris, *this) - , _map(map) - , _sratom(sratom_new(&map.urid_map_feature()->urid_map)) - , _uri(uri) - , _socket(sock) -{ - // Use <ingen:/root/> as base URI so e.g. </foo/bar> will be a path - _base = serd_node_from_string(SERD_URI, (const uint8_t*)"ingen:/root/"); - - serd_uri_parse(_base.buf, &_base_uri); - - _env = serd_env_new(&_base); - _writer = serd_writer_new( - SERD_TURTLE, - (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED), - _env, - &_base_uri, - socket_sink, - this); - - sratom_set_sink(_sratom, - (const char*)_base.buf, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon, - _writer); -} - -SocketWriter::~SocketWriter() -{ - sratom_free(_sratom); -} - -bool -SocketWriter::write(const LV2_Atom* msg) -{ - sratom_write(_sratom, &_map.urid_unmap_feature()->urid_unmap, 0, - NULL, NULL, msg->type, msg->size, LV2_ATOM_BODY_CONST(msg)); - serd_writer_finish(_writer); - return true; -} - -void -SocketWriter::bundle_end() -{ - AtomWriter::bundle_end(); - - // Send a NULL byte to indicate end of bundle - const char end[] = { 0 }; - send(fd(), end, 1, MSG_NOSIGNAL); -} - -} // namespace Socket -} // namespace Ingen diff --git a/src/socket/SocketWriter.hpp b/src/socket/SocketWriter.hpp deleted file mode 100644 index 1b3523d1..00000000 --- a/src/socket/SocketWriter.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of Ingen. - Copyright 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/>. -*/ - -#ifndef INGEN_SOCKET_SOCKET_WRITER_HPP -#define INGEN_SOCKET_SOCKET_WRITER_HPP - -#include <stdint.h> - -#include "ingen/AtomSink.hpp" -#include "ingen/AtomWriter.hpp" -#include "ingen/Interface.hpp" -#include "ingen/types.hpp" -#include "ingen/types.hpp" -#include "raul/Socket.hpp" -#include "raul/URI.hpp" -#include "sratom/sratom.h" - -namespace Ingen { -namespace Socket { - -/** An Interface that writes Turtle messages to a socket. - */ -class SocketWriter : public AtomWriter, public AtomSink -{ -public: - SocketWriter(URIMap& map, - URIs& uris, - const Raul::URI& uri, - SPtr<Raul::Socket> sock); - - ~SocketWriter(); - - bool write(const LV2_Atom* msg); - - void bundle_end(); - - int fd() { return _socket->fd(); } - Raul::URI uri() const { return _uri; } - -protected: - URIMap& _map; - Sratom* _sratom; - SerdNode _base; - SerdURI _base_uri; - SerdEnv* _env; - SerdWriter* _writer; - Raul::URI _uri; - SPtr<Raul::Socket> _socket; -}; - -} // namespace Socket -} // namespace Ingen - -#endif // INGEN_SOCKET_SOCKET_WRITER_HPP diff --git a/src/socket/ingen_socket_client.cpp b/src/socket/ingen_socket_client.cpp deleted file mode 100644 index 61a175d4..00000000 --- a/src/socket/ingen_socket_client.cpp +++ /dev/null @@ -1,68 +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 "ingen/Log.hpp" -#include "ingen/Module.hpp" -#include "ingen/World.hpp" -#include "raul/Socket.hpp" - -#include "SocketClient.hpp" - -namespace Ingen { -namespace Socket { - -static Raul::Socket::Type type_from_uri(const Raul::URI uri) { - return (uri.scheme() == "unix") - ? Raul::Socket::Type::UNIX - : Raul::Socket::Type::TCP; -} - -static SPtr<Ingen::Interface> -new_socket_interface(Ingen::World* world, - const Raul::URI& uri, - SPtr<Ingen::Interface> respondee) -{ - SPtr<Raul::Socket> sock(new Raul::Socket(type_from_uri(uri))); - if (!sock->connect(uri)) { - world->log().error(fmt("Failed to connect <%1%> (%2%)\n") - % sock->uri() % strerror(errno)); - return SPtr<Interface>(); - } - SocketClient* client = new SocketClient(*world, uri, sock, respondee); - return SPtr<Interface>(client); -} - -struct SocketClientModule : public Module { - void load(World* world) { - world->add_interface_factory("unix", &new_socket_interface); - world->add_interface_factory("tcp", &new_socket_interface); - } -}; - -} // namespace Socket -} // namespace Ingen - -extern "C" { - -Ingen::Module* -ingen_module_load() -{ - return new Ingen::Socket::SocketClientModule(); -} - -} // extern "C" diff --git a/src/socket/ingen_socket_server.cpp b/src/socket/ingen_socket_server.cpp deleted file mode 100644 index 5aff7179..00000000 --- a/src/socket/ingen_socket_server.cpp +++ /dev/null @@ -1,152 +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 <thread> - -#include "ingen/Configuration.hpp" -#include "ingen/Module.hpp" -#include "ingen/World.hpp" -#include "raul/Socket.hpp" - -#include "../server/Engine.hpp" -#include "../server/EventWriter.hpp" - -#include "SocketServer.hpp" - -#define UNIX_SCHEME "unix://" - -namespace Ingen { -namespace Socket { - -static void -ingen_listen(Ingen::World* world, - Raul::Socket* unix_sock, - Raul::Socket* net_sock) -{ - const std::string unix_path(world->conf().option("socket").ptr<char>()); - - SPtr<Server::Engine> engine = dynamic_ptr_cast<Server::Engine>( - world->engine()); - - // Bind UNIX socket - const Raul::URI unix_uri(UNIX_SCHEME + unix_path); - if (!unix_sock->bind(unix_uri) || !unix_sock->listen()) { - world->log().error("Failed to create UNIX socket\n"); - unix_sock->close(); - } else { - world->log().info(fmt("Listening on socket %1%\n") % unix_uri); - } - - // Bind TCP socket - const 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(); - } else { - world->log().info(fmt("Listening on TCP port %1%\n") % port); - } - - if (unix_sock->fd() == -1 && net_sock->fd() == -1) { - return; // No sockets to listen to, exit thread - } - - 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 (ret == -1) { - world->log().error(fmt("Poll error: %1%\n") % strerror(errno)); - break; - } else if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { - break; - } else if (ret == 0) { - world->log().error("Poll returned with no data\n"); - continue; - } - - if (pfds[0].revents & POLLIN) { - SPtr<Raul::Socket> conn = unix_sock->accept(); - if (conn) { - new SocketServer(*world, *engine, conn); - } - } - - if (pfds[1].revents & POLLIN) { - SPtr<Raul::Socket> conn = net_sock->accept(); - if (conn) { - new SocketServer(*world, *engine, conn); - } - } - } -} - -struct ServerModule : public Ingen::Module -{ - ServerModule() - : unix_sock(Raul::Socket::Type::UNIX) - , net_sock(Raul::Socket::Type::TCP) - {} - - ~ServerModule() { - unix_sock.shutdown(); - net_sock.shutdown(); - thread->join(); - unlink(unix_sock.uri().substr(strlen(UNIX_SCHEME)).c_str()); - } - - void load(World* world) { - thread = std::unique_ptr<std::thread>( - new std::thread(ingen_listen, world, &unix_sock, &net_sock)); - } - - Raul::Socket unix_sock; - Raul::Socket net_sock; - std::unique_ptr<std::thread> thread; -}; - -} // namespace Socket -} // namespace Ingen - -extern "C" { - -Ingen::Module* -ingen_module_load() -{ - return new Ingen::Socket::ServerModule(); -} - -} // extern "C" diff --git a/src/socket/wscript b/src/socket/wscript deleted file mode 100644 index 1ebc9f4c..00000000 --- a/src/socket/wscript +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -from waflib.extras import autowaf as autowaf - -def build(bld): - if bld.is_defined('HAVE_SOCKET'): - obj = bld(features = 'cxx cxxshlib', - source = ['SocketReader.cpp', - 'SocketWriter.cpp', - 'ingen_socket_server.cpp'], - includes = ['.', '../..'], - name = 'libingen_socket_server', - target = 'ingen_socket_server', - install_path = '${LIBDIR}', - use = 'libingen_server', - lib = ['pthread']) - autowaf.use_lib(bld, obj, 'GLIBMM SERD SORD SRATOM RAUL LV2') - - obj = bld(features = 'cxx cxxshlib', - source = ['SocketReader.cpp', - 'SocketWriter.cpp', - 'ingen_socket_client.cpp'], - includes = ['.', '../..'], - name = 'libingen_socket_client', - target = 'ingen_socket_client', - install_path = '${LIBDIR}', - use = 'libingen_server', - lib = ['pthread']) - autowaf.use_lib(bld, obj, 'GLIBMM SERD SORD SRATOM RAUL LV2') |