Browse Source

allow connect-method config var

David Rose 18 years ago
parent
commit
81d1f43ad0

+ 36 - 18
direct/src/distributed/ConnectionRepository.py

@@ -22,7 +22,7 @@ class ConnectionRepository(
     taskPriority = -30
 
     CM_HTTP=0
-    CM_NSPR=1
+    CM_NET=1
     CM_NATIVE=2
 
 
@@ -41,28 +41,46 @@ class ConnectionRepository(
         
         self.config = config
 
-        if hasattr(self, 'setVerbose'):
-            if self.config.GetBool('verbose-repository'):
-                self.setVerbose(1)
+        if self.config.GetBool('verbose-repository'):
+            self.setVerbose(1)
 
         # Set this to 'http' to establish a connection to the server
         # using the HTTPClient interface, which ultimately uses the
         # OpenSSL socket library (even though SSL is not involved).
-        # This is not as robust a socket library as NSPR's, but the
+        # This is not as robust a socket library as NET's, but the
         # HTTPClient interface does a good job of negotiating the
         # connection over an HTTP proxy if one is in use.
         #
-        # Set it to 'nspr' to use Panda's net interface
+        # Set it to 'net' to use Panda's net interface
         # (e.g. QueuedConnectionManager, etc.) to establish the
-        # connection, which ultimately uses the NSPR socket library.
-        # This is a much better socket library, but it may be more
-        # than you need for most applications; and there is no support
-        # for proxies.
+        # connection.  This is a higher-level layer build on top of
+        # the low-level "native net" library.  There is no support for
+        # proxies.  This is a good, general choice.
         #
-        # Set it to 'default' to use the HTTPClient interface if a
-        # proxy is in place, but the NSPR interface if we don't have a
-        # proxy.
-        self.connectMethod=connectMethod
+        # Set it to 'native' to use Panda's low-level native net
+        # interface directly.  This is much faster than either http or
+        # net for high-bandwidth (e.g. server) applications, but it
+        # doesn't support the simulated delay via the start_delay()
+        # call.
+        #
+        # Set it to 'default' to use an appropriate interface
+        # according to the type of ConnectionRepository we are
+        # creating.
+        userConnectMethod = self.config.GetString('connect-method', 'default')
+        if userConnectMethod == 'http':
+            connectMethod = self.CM_HTTP
+        elif userConnectMethod == 'net':
+            connectMethod = self.CM_NET
+        elif userConnectMethod == 'native':
+            connectMethod = self.CM_NATIVE
+
+        self.connectMethod = connectMethod
+        if self.connectMethod == self.CM_HTTP:
+            self.notify.info("Using connect method 'http'")
+        elif self.connectMethod == self.CM_NET:
+            self.notify.info("Using connect method 'net'")
+        elif self.connectMethod == self.CM_NATIVE:
+            self.notify.info("Using connect method 'native'")
         
         self.connectHttp = None
         self.http = None
@@ -375,7 +393,7 @@ class ConnectionRepository(
         else:
             self.notify.info("Connecting to gameserver directly (no proxy).")
 
-        #Redefine the connection to http or nspr in the default case
+        #Redefine the connection to http or net in the default case
 
         self.bootedIndex = None
         self.bootedText = None
@@ -393,11 +411,11 @@ class ConnectionRepository(
                     ch, serverList, 0,
                     successCallback, successArgs,
                     failureCallback, failureArgs)
-        elif self.connectMethod == self.CM_NSPR or (not hasattr(self,"connectNative")):
+        elif self.connectMethod == self.CM_NET or (not hasattr(self,"connectNative")):
             # Try each of the servers in turn.
             for url in serverList:
-                self.notify.info("Connecting to %s via NSPR interface." % (url.cStr()))
-                if self.tryConnectNspr(url):
+                self.notify.info("Connecting to %s via NET interface." % (url.cStr()))
+                if self.tryConnectNet(url):
                     self.startReaderPollTask()
                     if successCallback:
                         successCallback(*successArgs)

+ 1 - 1
direct/src/distributed/Sources.pp

@@ -2,7 +2,7 @@
 
 #begin lib_target
   #define BUILD_TARGET $[HAVE_PYTHON]
-  #define USE_PACKAGES openssl nspr native_net
+  #define USE_PACKAGES openssl native_net net
 
   #define TARGET distributed
   #define LOCAL_LIBS \

+ 6 - 6
direct/src/distributed/cConnectionRepository.I

@@ -79,7 +79,7 @@ set_python_repository(PyObject *python_repository) {
 }
 #endif  // HAVE_PYTHON
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
 ////////////////////////////////////////////////////////////////////
 //     Function: CConnectionRepository::get_qcm
 //       Access: Published
@@ -90,9 +90,9 @@ INLINE QueuedConnectionManager &CConnectionRepository::
 get_qcm() {
   return _qcm;
 }
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
 ////////////////////////////////////////////////////////////////////
 //     Function: CConnectionRepository::get_cw
 //       Access: Published
@@ -104,9 +104,9 @@ get_cw() {
   return _cw;
 }
   INLINE ConnectionWriter &get_cw();
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
 ////////////////////////////////////////////////////////////////////
 //     Function: CConnectionRepository::get_qcr
 //       Access: Published
@@ -118,7 +118,7 @@ get_qcr() {
   return _qcr;
 }
   INLINE QueuedConnectionReader &get_qcr();
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
 #ifdef WANT_NATIVE_NET
 ////////////////////////////////////////////////////////////////////

+ 48 - 45
direct/src/distributed/cConnectionRepository.cxx

@@ -49,7 +49,7 @@ CConnectionRepository(bool has_owner_view) :
 #ifdef HAVE_OPENSSL
   _http_conn(NULL),
 #endif
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
   _cw(&_qcm, 0),
   _qcr(&_qcm, 0),
 #endif
@@ -65,7 +65,7 @@ CConnectionRepository(bool has_owner_view) :
   _msg_type(0),
   _has_owner_view(has_owner_view)
 {
-#if defined(HAVE_NSPR) && defined(SIMULATE_NETWORK_DELAY)
+#if defined(HAVE_NET) && defined(SIMULATE_NETWORK_DELAY)
   if (min_lag != 0.0 || max_lag != 0.0) {
     _qcr.start_delay(min_lag, max_lag);
   }
@@ -119,38 +119,38 @@ get_stream() {
 #endif  // HAVE_OPENSSL
 
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
 ////////////////////////////////////////////////////////////////////
-//     Function: CConnectionRepository::try_connect_nspr
+//     Function: CConnectionRepository::try_connect_net
 //       Access: Published
-//  Description: Uses NSPR to try to connect to the server and port
-//               named in the indicated URL.  Returns true if
-//               successful, false otherwise.
+//  Description: Uses Panda's "net" library to try to connect to the
+//               server and port named in the indicated URL.  Returns
+//               true if successful, false otherwise.
 ////////////////////////////////////////////////////////////////////
 bool CConnectionRepository::
-try_connect_nspr(const URLSpec &url) {
+try_connect_net(const URLSpec &url) {
   disconnect();
 
-  _nspr_conn = 
+  _net_conn = 
     _qcm.open_TCP_client_connection(url.get_server(), url.get_port(),
                                     game_server_timeout_ms);
 
-  if (_nspr_conn != (Connection *)NULL) {
-    _nspr_conn->set_no_delay(true);
-    _qcr.add_connection(_nspr_conn);
+  if (_net_conn != (Connection *)NULL) {
+    _net_conn->set_no_delay(true);
+    _qcr.add_connection(_net_conn);
     return true;
   }
 
   return false;
 }
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
 #ifdef WANT_NATIVE_NET
 ////////////////////////////////////////////////////////////////////
 //     Function: CConnectionRepository::connect_native
 //       Access: Published
-//  Description: Connects to the server using a native system roger 
-//               put together
+//  Description: Connects to the server using Panda's low-level and
+//               fast "native net" library.
 ////////////////////////////////////////////////////////////////////
 bool CConnectionRepository::
 connect_native(const URLSpec &url) {
@@ -178,13 +178,16 @@ connect_native(const URLSpec &url) {
 //               is non-blocking.  If you call this on a blocking
 //               socket, it will force all datagrams to be held up
 //               until the socket closes.
+//
+//               This has no effect if the connection method is via
+//               the "native net" library.
 ////////////////////////////////////////////////////////////////////
 void CConnectionRepository::
 start_delay(double min_delay, double max_delay) {
   if (min_delay != 0.0 || max_delay != 0.0) {
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
     _qcr.start_delay(min_delay, max_delay);
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 #ifdef HAVE_OPENSSL
     if (_http_conn != (SocketStream *)NULL) {
       _http_conn->start_delay(min_delay, max_delay);
@@ -206,9 +209,9 @@ start_delay(double min_delay, double max_delay) {
 ////////////////////////////////////////////////////////////////////
 void CConnectionRepository::
 stop_delay() {
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
   _qcr.stop_delay();
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 #ifdef HAVE_OPENSSL
   if (_http_conn != (SocketStream *)NULL) {
     _http_conn->stop_delay();
@@ -312,22 +315,22 @@ is_connected() {
     return (_bdc.IsConnected());
 #endif
 
-#ifdef HAVE_NSPR
-  if (_nspr_conn) {
+#ifdef HAVE_NET
+  if (_net_conn) {
     if (_qcm.reset_connection_available()) {
       PT(Connection) reset_connection;
       if (_qcm.get_reset_connection(reset_connection)) {
         _qcm.close_connection(reset_connection);
-        if (reset_connection == _nspr_conn) {
+        if (reset_connection == _net_conn) {
           // Whoops, lost our connection.
-          _nspr_conn = NULL;
+          _net_conn = NULL;
           return false;
         }
       }
     }
     return true;
   }
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
 #ifdef HAVE_OPENSSL
   if (_http_conn) {
@@ -369,12 +372,12 @@ send_datagram(const Datagram &dg) {
     return _bdc.SendMessage(dg);
 #endif
 
-#ifdef HAVE_NSPR
-  if (_nspr_conn) {
-    _cw.send(dg, _nspr_conn);
+#ifdef HAVE_NET
+  if (_net_conn) {
+    _cw.send(dg, _net_conn);
     return true;
   }
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
 #ifdef HAVE_OPENSSL
   if (_http_conn) {
@@ -411,11 +414,11 @@ consider_flush() {
     return true;  //Maybe we should just flush here for now?
 #endif
 
-#ifdef HAVE_NSPR
-  if (_nspr_conn) {
-    return _nspr_conn->consider_flush();
+#ifdef HAVE_NET
+  if (_net_conn) {
+    return _net_conn->consider_flush();
   }
-#endif  // HAVE_NSPR
+#endif  // HAVE_NET
 
 #ifdef HAVE_OPENSSL
   if (_http_conn) {
@@ -443,11 +446,11 @@ flush() {
     return _bdc.Flush();
   #endif
 
-  #ifdef HAVE_NSPR
-  if (_nspr_conn) {
-    return _nspr_conn->flush();
+  #ifdef HAVE_NET
+  if (_net_conn) {
+    return _net_conn->flush();
   }
-  #endif  // HAVE_NSPR
+  #endif  // HAVE_NET
 
   #ifdef HAVE_OPENSSL
   if (_http_conn) {
@@ -471,12 +474,12 @@ disconnect() {
     _bdc.ClearAddresses();
   }
   #endif
-  #ifdef HAVE_NSPR
-  if (_nspr_conn) {
-    _qcm.close_connection(_nspr_conn);
-    _nspr_conn = NULL;
+  #ifdef HAVE_NET
+  if (_net_conn) {
+    _qcm.close_connection(_net_conn);
+    _net_conn = NULL;
   }
-  #endif  // HAVE_NSPR
+  #endif  // HAVE_NET
 
   #ifdef HAVE_OPENSSL
   if (_http_conn) {
@@ -502,16 +505,16 @@ do_check_datagram() {
     return _bdc.GetMessage(_dg);
   }
   #endif
-  #ifdef HAVE_NSPR
-  if (_nspr_conn) {
-    _nspr_conn->consider_flush();
+  #ifdef HAVE_NET
+  if (_net_conn) {
+    _net_conn->consider_flush();
     if (_qcr.get_overflow_flag()) {
       throw_event(get_overflow_event_name());
       _qcr.reset_overflow_flag();
     }
     return (_qcr.data_available() && _qcr.get_data(_dg));
   }
-  #endif  // HAVE_NSPR
+  #endif  // HAVE_NET
 
   #ifdef HAVE_OPENSSL
   if (_http_conn) {

+ 5 - 5
direct/src/distributed/cConnectionRepository.h

@@ -28,7 +28,7 @@
 #include "pStatCollector.h"
 #include "datagramIterator.h"
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
 #include "queuedConnectionManager.h"
 #include "connectionWriter.h"
 #include "queuedConnectionReader.h"
@@ -79,8 +79,8 @@ PUBLISHED:
   void set_connection_http(HTTPChannel *channel);
   SocketStream *get_stream();
 #endif
-#ifdef HAVE_NSPR
-  bool try_connect_nspr(const URLSpec &url);
+#ifdef HAVE_NET
+  bool try_connect_net(const URLSpec &url);
 
   INLINE QueuedConnectionManager &get_qcm();
   INLINE ConnectionWriter &get_cw();
@@ -140,11 +140,11 @@ private:
   SocketStream *_http_conn;
 #endif
 
-#ifdef HAVE_NSPR
+#ifdef HAVE_NET
   QueuedConnectionManager _qcm;
   ConnectionWriter _cw;
   QueuedConnectionReader _qcr;
-  PT(Connection) _nspr_conn;
+  PT(Connection) _net_conn;
 #endif
 
 #ifdef WANT_NATIVE_NET