/*
- Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
+
#include <string>
#include <list>
#include <boost/optional.hpp>
-#include <boost/noncopyable.hpp>
-class Nanomsg : public boost::noncopyable
+
+class Nanomsg
{
public:
explicit Nanomsg (bool server);
+ ~Nanomsg ();
+
+ Nanomsg (Nanomsg const&) = delete;
+ Nanomsg& operator= (Nanomsg const&) = delete;
+
+ /** Try to send a message, waiting for some timeout before giving up.
+ * @param timeout Timeout in milliseconds, or -1 for infinite timeout.
+ * @return true if the send happened, false if there was a timeout.
+ */
+ bool send (std::string s, int timeout);
- 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.
+ /** Try to receive a message, waiting for some timeout before giving up.
+ * @param timeout Timeout in milliseconds, or -1 for infinite timeout.
+ * @return Empty if the timeout was reached, otherwise the received string.
*/
- bool nonblocking_send (std::string s);
- std::string blocking_get ();
- boost::optional<std::string> nonblocking_get ();
+ boost::optional<std::string> receive (int timeout);
private:
boost::optional<std::string> get_from_pending ();
- void recv_and_parse (bool blocking);
+ void recv_and_parse (int flags);
int _socket;
+ int _endpoint;
std::list<std::string> _pending;
std::string _current;
};