diff options
Diffstat (limited to 'src/SocketWriter.cpp')
-rw-r--r-- | src/SocketWriter.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/SocketWriter.cpp b/src/SocketWriter.cpp new file mode 100644 index 00000000..83895701 --- /dev/null +++ b/src/SocketWriter.cpp @@ -0,0 +1,63 @@ +/* + This file is part of Ingen. + Copyright 2012-2016 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 "ingen/SocketWriter.hpp" + +#include "ingen/URI.hpp" +#include "raul/Socket.hpp" + +#include <boost/variant/get.hpp> + +#include <sys/types.h> +#include <sys/socket.h> +#include <utility> + +#ifndef MSG_NOSIGNAL +# define MSG_NOSIGNAL 0 +#endif + +namespace ingen { + +SocketWriter::SocketWriter(URIMap& map, + URIs& uris, + const URI& uri, + SPtr<Raul::Socket> sock) + : TurtleWriter(map, uris, uri) + , _socket(std::move(sock)) +{} + +void +SocketWriter::message(const Message& message) +{ + TurtleWriter::message(message); + if (boost::get<BundleEnd>(&message)) { + // Send a null byte to indicate end of bundle + const char end[] = { 0 }; + send(_socket->fd(), end, 1, MSG_NOSIGNAL); + } +} + +size_t +SocketWriter::text_sink(const void* buf, size_t len) +{ + ssize_t ret = send(_socket->fd(), buf, len, MSG_NOSIGNAL); + if (ret < 0) { + return 0; + } + return ret; +} + +} // namespace ingen |