X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fnanomsg.h;h=8d89d6d99fee05b641ed5213d83d9145f42d4b32;hb=0185ba27b0e9c52a173147c1380ec5f345109afc;hp=dc84a6ce739f821ed2b939e1569e42c4f378dcf2;hpb=a1f7bf2d9e5610075fbd898cdf52f4f8373741f2;p=dcpomatic.git diff --git a/src/lib/nanomsg.h b/src/lib/nanomsg.h index dc84a6ce7..8d89d6d99 100644 --- a/src/lib/nanomsg.h +++ b/src/lib/nanomsg.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,30 +18,39 @@ */ + #include #include #include -#include -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 nonblocking_get (); + boost::optional receive (int timeout); private: boost::optional get_from_pending (); - void recv_and_parse (bool blocking); + void recv_and_parse (int flags); int _socket; + int _endpoint; std::list _pending; std::string _current; };