commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 32/50: controlport: moving the generation o


From: git
Subject: [Commit-gnuradio] [gnuradio] 32/50: controlport: moving the generation of the Thrift endpoint string to the application_started() function.
Date: Wed, 15 Apr 2015 21:07:55 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit de96353ab2b27f251909ec9a69f336f133899011
Author: Nate Goergen <address@hidden>
Date:   Wed Mar 4 17:38:53 2015 -0600

    controlport: moving the generation of the Thrift endpoint string to the 
application_started() function.
    
    Includes moving the call that logs the generated endpoint.
    
    This allows the application_base::kickoff() function to wait until the
    Thrift runtime publishes the port selected by bind(), when a
    pseudorandom / unused port number is configured (i.e. port=0, the
    default setting). Once bind()'s final port number is available, the
    endpoint string may be generated and the ControlPort Thrift interface
    may be started.
---
 .../include/gnuradio/thrift_application_base.h     | 29 +++++++++++-------
 .../include/gnuradio/thrift_server_template.h      | 19 ------------
 .../controlport/thrift/rpcserver_booter_thrift.cc  | 34 +++++++++++++++++++++-
 3 files changed, 51 insertions(+), 31 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/thrift_application_base.h 
b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
index 4dc56a1..b957c5e 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_application_base.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
@@ -106,10 +106,7 @@ thrift_application_base<TserverBase, 
TserverClass>::thrift_application_base(Tser
   GR_LOG_DEBUG(d_debug_logger, "thrift_application_base: ctor");
 
   //std::cerr << "thrift_application_base: ctor" << std::endl;
-  d_is_running = false;
   d_this = _this;
-
-  //d_application->d_thriftserver = d_this->d_thriftserver;
 }
 
 template<typename TserverBase, typename TserverClass>
@@ -123,10 +120,26 @@ void thrift_application_base<TserverBase, 
TserverClass>::kickoff()
     thrift_application_common::d_thread = boost::shared_ptr<gr::thread::thread>
       (new 
gr::thread::thread(boost::bind(&thrift_application_base::start_thrift, 
d_this)));
 
+    ::timespec timer_ts, rem_ts;
+    timer_ts.tv_sec = 0; timer_ts.tv_nsec = 
THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS*1000;
+
+    int iter = 0;
+    while(!d_this->application_started()) {
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+      ::Sleep(timer_ts.tv_nsec / 1000000);
+#else
+      ::nanosleep(&timer_ts, &rem_ts);
+#endif
+      if(!d_this->application_started())
+        std::cout << "@";
+      if(iter++ > 100) {
+        std::cout << "thrift_application_base::kickoff(), timeout waiting to 
port number might have failed?!" << std::endl;;
+        break;
+      }
+    }
+
     run_once = true;
   }
-
-  return;
 }
 
 
@@ -154,10 +167,4 @@ TserverBase* thrift_application_base<TserverBase, 
TserverClass>::i()
   return d_this->i_impl();
 }
 
-template<typename TserverBase, typename TImplClass>
-bool thrift_application_base<TserverBase, TImplClass>::application_started()
-{
-  return d_is_running;
-}
-
 #endif
diff --git a/gnuradio-runtime/include/gnuradio/thrift_server_template.h 
b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
index 0bf4ac2..1635642 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_server_template.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
@@ -37,9 +37,6 @@
 #include <thrift/transport/TBufferTransports.h>
 #include "thrift/ControlPort.h"
 
-//#include <netdb.h>
-#include <boost/asio/ip/host_name.hpp>
-
 using namespace apache;
 
 namespace {
@@ -171,22 +168,6 @@ TserverBase* thrift_server_template<TserverBase, 
TserverClass, TImplClass, TThri
 {
   //std::cerr << "thrift_server_template: i_impl" << std::endl;
 
-  // Determine the hostname of this host
-  const std::string boost_hostname(boost::asio::ip::host_name());
-
-  // Define the endpoint
-  thrift::transport::TServerTransport *thetransport =
-    thrift_application_base<TserverBase, 
TImplClass>::d_thriftserver->getServerTransport().get();
-
-  // Determine the specified endpoint port number, or the port number selected 
by bind() if
-  // ControlPort is configured to listen on port 0 (the default)
-  int used_port = ((thrift::transport::TServerSocket*)thetransport)->getPort();
-  std::string endpoint = boost::str(boost::format("-h %1% -p %2%") % 
boost_hostname % used_port);
-  //std::cout << "Thrift endpoint: " << endpoint << " boost hostname: " << 
boost_hostname << std::endl;
-  thrift_application_base<TserverBase, 
TImplClass>::d_this->set_endpoint(endpoint);
-
-  GR_LOG_INFO(logger, "Apache Thrift: " + endpoint);
-
   return d_server;
 }
 
diff --git a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc 
b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
index b76ce77..095db2e 100644
--- a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
@@ -23,6 +23,8 @@
 #include <gnuradio/rpcserver_thrift.h>
 #include <gnuradio/rpcserver_booter_thrift.h>
 
+#include <boost/asio/ip/host_name.hpp>
+
 namespace {
   static const char* const CONTROL_PORT_CLASS("thrift");
   static const char* const CONTROL_PORT_NAME("ControlPort");
@@ -96,7 +98,37 @@ void thrift_application_base<TserverBase, 
TserverClass>::start_thrift()
 
   //std::cerr << "thrift_application_base: start_thrift" << std::endl;
   GR_LOG_DEBUG(d_debug_logger, "thrift_application_base: start server");
-  d_is_running = true;
   d_thriftserver->serve();
   GR_LOG_DEBUG(d_debug_logger, "thrift_application_base: server started");
 }
+
+
+template<typename TserverBase, typename TserverClass>
+bool thrift_application_base<TserverBase, TserverClass>::application_started()
+{
+  if (d_is_running) return true;
+
+  bool result(false);
+  // Define the endpoint
+  apache::thrift::transport::TServerTransport *thetransport =
+    d_thriftserver->getServerTransport().get();
+
+  // Determine the specified endpoint port number, or the port number selected 
by bind() if
+  // ControlPort is configured to listen on port 0 (the default)
+  int used_port = 
((apache::thrift::transport::TServerSocket*)thetransport)->getPort();
+
+  if (used_port > 0) {
+    // Determine the hostname of this host
+    const std::string boost_hostname(boost::asio::ip::host_name());
+
+    std::string endpoint = boost::str(boost::format("-h %1% -p %2%") % 
boost_hostname % used_port);
+    //std::cout << "Thrift endpoint: " << endpoint << " boost hostname: " << 
boost_hostname << std::endl;
+    set_endpoint(endpoint);
+
+    GR_LOG_INFO(logger, "Apache Thrift: " + endpoint);
+    d_is_running = true;
+    result = true;
+  }
+
+  return result;
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]