summaryrefslogtreecommitdiff
path: root/src/lib/nanomsg.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-03-16 00:44:31 +0100
committerCarl Hetherington <cth@carlh.net>2020-04-06 15:57:14 +0200
commita1f7bf2d9e5610075fbd898cdf52f4f8373741f2 (patch)
tree5539cea37bebe3347408b9404ac3d9aa5cd5fe1b /src/lib/nanomsg.h
parentadddda49c17e87198253d9c900dcef0f5fb2e175 (diff)
Add disk writer tool.
Diffstat (limited to 'src/lib/nanomsg.h')
-rw-r--r--src/lib/nanomsg.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/nanomsg.h b/src/lib/nanomsg.h
new file mode 100644
index 000000000..dc84a6ce7
--- /dev/null
+++ b/src/lib/nanomsg.h
@@ -0,0 +1,48 @@
+/*
+ Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <string>
+#include <list>
+#include <boost/optional.hpp>
+#include <boost/noncopyable.hpp>
+
+class Nanomsg : public boost::noncopyable
+{
+public:
+ explicit Nanomsg (bool server);
+
+ void blocking_send (std::string s);
+ /** Try to send a message, returning true if successful, false
+ * if we should try again (EAGAIN) or throwing an exception on any other
+ * error.
+ */
+ bool nonblocking_send (std::string s);
+ std::string blocking_get ();
+ boost::optional<std::string> nonblocking_get ();
+
+private:
+ boost::optional<std::string> get_from_pending ();
+ void recv_and_parse (bool blocking);
+
+ int _socket;
+ std::list<std::string> _pending;
+ std::string _current;
+};
+