Move ports around to allow master/server to coexist (#962).
authorCarl Hetherington <cth@carlh.net>
Thu, 27 Apr 2017 14:07:21 +0000 (15:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 27 Apr 2017 14:07:21 +0000 (15:07 +0100)
ChangeLog
src/lib/dcp_video.cc
src/lib/encode_server.cc
src/lib/encode_server_finder.cc
src/lib/types.h
src/tools/dcpomatic.cc
src/tools/dcpomatic_batch.cc

index b1ffde1..b1fcbb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-27  Carl Hetherington  <cth@carlh.net>
+
+       * Stop master and server instances fighting over ports, allowing them to coexist (#962).
+
 2017-04-26  Carl Hetherington  <cth@carlh.net>
 
        * Make a copy of the configuration, if it fails to load, before making new defaults.
index ba8057b..916563b 100644 (file)
@@ -156,7 +156,7 @@ DCPVideo::encode_remotely (EncodeServerDescription serv, int timeout)
 {
        boost::asio::io_service io_service;
        boost::asio::ip::tcp::resolver resolver (io_service);
-       boost::asio::ip::tcp::resolver::query query (serv.host_name(), raw_convert<string> (Config::instance()->server_port_base ()));
+       boost::asio::ip::tcp::resolver::query query (serv.host_name(), raw_convert<string> (ENCODE_FRAME_PORT));
        boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query);
 
        shared_ptr<Socket> socket (new Socket (timeout));
index 442ce3d..4f27ee4 100644 (file)
@@ -67,7 +67,7 @@ using dcp::Data;
 using dcp::raw_convert;
 
 EncodeServer::EncodeServer (shared_ptr<Log> log, bool verbose, int num_threads)
-       : Server (Config::instance()->server_port_base())
+       : Server (ENCODE_FRAME_PORT)
        , _log (log)
        , _verbose (verbose)
        , _num_threads (num_threads)
@@ -237,7 +237,7 @@ EncodeServer::broadcast_thread ()
 try
 {
        boost::asio::ip::address address = boost::asio::ip::address_v4::any ();
-       boost::asio::ip::udp::endpoint listen_endpoint (address, Config::instance()->server_port_base() + 1);
+       boost::asio::ip::udp::endpoint listen_endpoint (address, HELLO_PORT);
 
        _broadcast.socket = new boost::asio::ip::udp::socket (_broadcast.io_service);
        _broadcast.socket->open (listen_endpoint.protocol ());
@@ -274,7 +274,7 @@ EncodeServer::broadcast_received ()
                }
                shared_ptr<Socket> socket (new Socket);
                try {
-                       socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), Config::instance()->server_port_base() + 1));
+                       socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), SERVER_PRESENCE_PORT));
                        socket->write (xml.length() + 1);
                        socket->write ((uint8_t *) xml.c_str(), xml.length() + 1);
                } catch (...) {
index e964bb8..2796df8 100644 (file)
@@ -118,7 +118,7 @@ try
                if (Config::instance()->use_any_servers ()) {
                        /* Broadcast to look for servers */
                        try {
-                               boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port_base() + 1);
+                               boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), HELLO_PORT);
                                socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
                        } catch (...) {
 
@@ -134,7 +134,7 @@ try
                        }
                        try {
                                boost::asio::ip::udp::resolver resolver (io_service);
-                               boost::asio::ip::udp::resolver::query query (*i, raw_convert<string> (Config::instance()->server_port_base() + 1));
+                               boost::asio::ip::udp::resolver::query query (*i, raw_convert<string> (HELLO_PORT));
                                boost::asio::ip::udp::endpoint end_point (*resolver.resolve (query));
                                socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
                        } catch (...) {
@@ -157,7 +157,7 @@ try {
        using namespace boost::asio::ip;
 
        try {
-               _listen_acceptor.reset (new tcp::acceptor (_listen_io_service, tcp::endpoint (tcp::v4(), Config::instance()->server_port_base() + 1)));
+               _listen_acceptor.reset (new tcp::acceptor (_listen_io_service, tcp::endpoint (tcp::v4(), SERVER_PRESENCE_PORT)));
        } catch (...) {
                boost::throw_exception (NetworkError (_("Could not listen for remote encode servers.  Perhaps another instance of DCP-o-matic is running.")));
        }
index 041db17..0702c87 100644 (file)
@@ -70,6 +70,15 @@ namespace xmlpp {
 */
 #define VIDEO_FRAME_RATE_EPSILON (1e-4)
 
+/** Port on which EncodeServer listens for frame encoding requests */
+#define ENCODE_FRAME_PORT (Config::instance()->server_port_base())
+/** Port on which EncodeServer listens for DCPOMATIC_HELLO from masters */
+#define HELLO_PORT (Config::instance()->server_port_base()+1)
+/** Port on which EncodeServerFinder listens for replies to DCPOMATIC_HELLO from servers */
+#define SERVER_PRESENCE_PORT (Config::instance()->server_port_base()+2)
+/** Port on which batch converter listens for job requests */
+#define BATCH_JOB_PORT (Config::instance()->server_port_base()+3)
+
 typedef std::vector<boost::shared_ptr<Content> > ContentList;
 typedef std::vector<boost::shared_ptr<FFmpegContent> > FFmpegContentList;
 
index f94c2ac..e9a1f65 100644 (file)
@@ -559,7 +559,7 @@ private:
                        try {
                                boost::asio::io_service io_service;
                                boost::asio::ip::tcp::resolver resolver (io_service);
-                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (Config::instance()->server_port_base() + 2));
+                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (BATCH_JOB_PORT));
                                boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query);
                                Socket socket (5);
                                socket.connect (*endpoint_iterator);
index 3088743..9b6fdfd 100644 (file)
@@ -252,7 +252,7 @@ class JobServer : public Server
 {
 public:
        JobServer (DOMFrame* frame)
-               : Server (Config::instance()->server_port_base() + 2)
+               : Server (BATCH_JOB_PORT)
                , _frame (frame)
        {}