Fix some typos in comments.
[dcpomatic.git] / src / lib / encode_server_finder.cc
index 200286fd94426e945c32cff7c37b8dc0867a47bd..3f5cb74f01bddbe659dc2360446d454bdbe06725 100644 (file)
 */
 
 
-#include "encode_server_finder.h"
-#include "exceptions.h"
-#include "util.h"
 #include "config.h"
+#include "constants.h"
 #include "cross.h"
-#include "encode_server_description.h"
 #include "dcpomatic_socket.h"
+#include "encode_server_description.h"
+#include "encode_server_finder.h"
+#include "exceptions.h"
 #include <dcp/raw_convert.h>
 #include <libcxml/cxml.h>
 #include <boost/bind/placeholders.hpp>
@@ -220,16 +220,24 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec)
                return;
        }
 
-       uint32_t length;
-       _accept_socket->read (reinterpret_cast<uint8_t*>(&length), sizeof(uint32_t));
-       length = ntohl (length);
+       string server_available;
 
-       scoped_array<char> buffer(new char[length]);
-       _accept_socket->read (reinterpret_cast<uint8_t*>(buffer.get()), length);
+       try {
+               uint32_t length;
+               _accept_socket->read (reinterpret_cast<uint8_t*>(&length), sizeof(uint32_t));
+               length = ntohl (length);
+
+               scoped_array<char> buffer(new char[length]);
+               _accept_socket->read (reinterpret_cast<uint8_t*>(buffer.get()), length);
+               server_available = buffer.get();
+       } catch (NetworkError&) {
+               /* Maybe the server went away; let's just try again */
+               start_accept();
+               return;
+       }
 
-       string s (buffer.get());
        auto xml = make_shared<cxml::Document>("ServerAvailable");
-       xml->read_string (s);
+       xml->read_string(server_available);
 
        auto const ip = _accept_socket->socket().remote_endpoint().address().to_string();
        bool changed = false;