Add some asserts to check for negative trims.
[dcpomatic.git] / src / lib / nanomsg.cc
index b66d966afb7cc4bd02ed5b42142b6f7cc736f9fe..61e6c08ce9e66fa738300b9a417267356f71a8b6 100644 (file)
@@ -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 ();
        }