diff options
Diffstat (limited to 'src/socket')
-rw-r--r-- | src/socket/SocketClient.hpp | 8 | ||||
-rw-r--r-- | src/socket/SocketServer.hpp | 20 | ||||
-rw-r--r-- | src/socket/SocketWriter.cpp | 10 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/socket/SocketClient.hpp b/src/socket/SocketClient.hpp index 22e6eeb4..d75288e0 100644 --- a/src/socket/SocketClient.hpp +++ b/src/socket/SocketClient.hpp @@ -41,6 +41,14 @@ public: _reader.start(); } + virtual SharedPtr<Interface> respondee() const { + return _respondee; + } + + virtual void set_respondee(SharedPtr<Interface> respondee) { + _respondee = respondee; + } + private: SharedPtr<Interface> _respondee; SocketReader _reader; diff --git a/src/socket/SocketServer.hpp b/src/socket/SocketServer.hpp index 8ea0f445..55434030 100644 --- a/src/socket/SocketServer.hpp +++ b/src/socket/SocketServer.hpp @@ -34,17 +34,23 @@ public: SharedPtr<Socket> sock) : Server::EventWriter(engine) , SocketReader(world, *this, sock) - , _writer(*world.lv2_uri_map().get(), - *world.uris().get(), - sock->uri(), - sock) + , _engine(engine) + , _writer(new SocketWriter(*world.lv2_uri_map().get(), + *world.uris().get(), + sock->uri(), + sock)) { - set_respondee(&_writer); - engine.register_client(sock->uri(), &_writer); + set_respondee(_writer); + engine.register_client(_writer->uri(), _writer); + } + + ~SocketServer() { + _engine.unregister_client(_writer->uri()); } private: - SocketWriter _writer; + Server::Engine& _engine; + SharedPtr<SocketWriter> _writer; }; } // namespace Ingen diff --git a/src/socket/SocketWriter.cpp b/src/socket/SocketWriter.cpp index 29bc018b..808d62cf 100644 --- a/src/socket/SocketWriter.cpp +++ b/src/socket/SocketWriter.cpp @@ -14,6 +14,10 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> + #include "SocketWriter.hpp" namespace Ingen { @@ -23,7 +27,11 @@ static size_t socket_sink(const void* buf, size_t len, void* stream) { SocketWriter* writer = (SocketWriter*)stream; - return write(writer->fd(), buf, len); + ssize_t ret = send(writer->fd(), buf, len, MSG_NOSIGNAL); + if (ret < 0) { + return 0; + } + return ret; } SocketWriter::SocketWriter(Shared::LV2URIMap& map, |