summaryrefslogtreecommitdiffstats
path: root/src/SocketWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SocketWriter.cpp')
-rw-r--r--src/SocketWriter.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/SocketWriter.cpp b/src/SocketWriter.cpp
new file mode 100644
index 00000000..dcba5799
--- /dev/null
+++ b/src/SocketWriter.cpp
@@ -0,0 +1,58 @@
+/*
+ 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 <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include "ingen/SocketWriter.hpp"
+#include "raul/Socket.hpp"
+
+#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))
+{}
+
+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;
+}
+
+void
+SocketWriter::bundle_end()
+{
+ TurtleWriter::bundle_end();
+
+ // Send a null byte to indicate end of bundle
+ const char end[] = { 0 };
+ send(_socket->fd(), end, 1, MSG_NOSIGNAL);
+}
+
+} // namespace ingen