Emit no audio from DCPs if none is mapped
[dcpomatic.git] / src / lib / nanomsg.cc
index b66d966afb7cc4bd02ed5b42142b6f7cc736f9fe..8061e2f8462c2b101f01e9ea71e48ca5724c71a1 100644 (file)
 */
 
 
-#include "nanomsg.h"
 #include "dcpomatic_log.h"
 #include "exceptions.h"
+#include "nanomsg.h"
 #include <nanomsg/nn.h>
 #include <nanomsg/pair.h>
-#include <stdexcept>
 #include <cerrno>
+#include <stdexcept>
 
 
-using std::string;
 using std::runtime_error;
+using std::string;
 using boost::optional;
 
 
@@ -43,17 +43,24 @@ Nanomsg::Nanomsg (bool server)
                throw runtime_error("Could not set up nanomsg socket");
        }
        if (server) {
-               if (nn_bind(_socket, NANOMSG_URL) < 0) {
+               if ((_endpoint = nn_bind(_socket, NANOMSG_URL)) < 0) {
                        throw runtime_error(String::compose("Could not bind nanomsg socket (%1)", errno));
                }
        } else {
-               if (nn_connect(_socket, NANOMSG_URL) < 0) {
+               if ((_endpoint = nn_connect(_socket, NANOMSG_URL)) < 0) {
                        throw runtime_error(String::compose("Could not connect nanomsg socket (%1)", errno));
                }
        }
 }
 
 
+Nanomsg::~Nanomsg ()
+{
+       nn_shutdown (_socket, _endpoint);
+       nn_close (_socket);
+}
+
+
 bool
 Nanomsg::send (string s, int timeout)
 {
@@ -99,6 +106,7 @@ Nanomsg::recv_and_parse (int flags)
                        return;
                }
 
+               LOG_DISK_NC("nn_recv failed");
                throw CommunicationFailedError ();
        }