From c0f9dce26f15ee6d247e6cc9a9e327795b695abd Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Thu, 9 Nov 2006 22:22:59 +0000 Subject: [PATCH] CR now requires a connection method,will be changed to has-a later --- .../src/distributed/ClientRepositoryBase.py | 2 +- .../src/distributed/ConnectionRepository.py | 29 +++++---- direct/src/distributed/Sources.pp | 4 +- .../src/distributed/cConnectionRepository.I | 14 +++++ .../src/distributed/cConnectionRepository.cxx | 60 +++++++++++++++++++ .../src/distributed/cConnectionRepository.h | 15 +++++ 6 files changed, 109 insertions(+), 15 deletions(-) diff --git a/direct/src/distributed/ClientRepositoryBase.py b/direct/src/distributed/ClientRepositoryBase.py index b0a1a74fa6..3b16c2e682 100644 --- a/direct/src/distributed/ClientRepositoryBase.py +++ b/direct/src/distributed/ClientRepositoryBase.py @@ -25,7 +25,7 @@ class ClientRepositoryBase(ConnectionRepository): def __init__(self, dcFileNames = None): self.dcSuffix="" - ConnectionRepository.__init__(self, base.config, hasOwnerView=True) + ConnectionRepository.__init__(self, ConnectionRepository.CM_HTTP, base.config, hasOwnerView=True) self.context=100000 self.setClientDatagram(1) diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index b3454db70e..e1950f35bd 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -9,7 +9,9 @@ from PyDatagramIterator import PyDatagramIterator import types import imp -class ConnectionRepository( + + +class ConnectionRepository( DoInterestManager, DoCollectionManager, CConnectionRepository): """ This is a base class for things that know how to establish a @@ -19,7 +21,12 @@ class ConnectionRepository( notify = DirectNotifyGlobal.directNotify.newCategory("ConnectionRepository") taskPriority = -30 - def __init__(self, config, hasOwnerView=False): + CM_HTTP=0 + CM_NSPR=1 + CM_NATIVE=2 + + + def __init__(self, connectMethod, config, hasOwnerView=False): assert self.notify.debugCall() # let the C connection repository know whether we're supporting # 'owner' views of distributed objects (i.e. 'receives ownrecv', @@ -54,7 +61,8 @@ class ConnectionRepository( # 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 = self.config.GetString('connect-method', 'default') + self.connectMethod=connectMethod + self.connectHttp = None self.http = None @@ -366,16 +374,11 @@ class ConnectionRepository( else: self.notify.info("Connecting to gameserver directly (no proxy).") - if self.connectMethod == 'http': - self.connectHttp = 1 - elif self.connectMethod == 'nspr': - self.connectHttp = 0 - else: - self.connectHttp = (hasProxy or serverList[0].isSsl()) + #Redefine the connection to http or nspr in the default case self.bootedIndex = None self.bootedText = None - if self.connectHttp: + if self.connectMethod == self.CM_HTTP: # In the HTTP case, we can't just iterate through the list # of servers, because each server attempt requires # spawning a request and then coming back later to check @@ -389,7 +392,7 @@ class ConnectionRepository( ch, serverList, 0, successCallback, successArgs, failureCallback, failureArgs) - else: + elif self.connectMethod == self.CM_NSPR: # Try each of the servers in turn. for url in serverList: self.notify.info("Connecting to %s via NSPR interface." % (url.cStr())) @@ -402,7 +405,9 @@ class ConnectionRepository( # Failed to connect. if failureCallback: failureCallback(0, '', *failureArgs) - + elif self.connectMethod == self.CM_NATIVE: + pass + def disconnect(self): """ Closes the previously-established connection. diff --git a/direct/src/distributed/Sources.pp b/direct/src/distributed/Sources.pp index d6a35f927b..a4f1056e5b 100644 --- a/direct/src/distributed/Sources.pp +++ b/direct/src/distributed/Sources.pp @@ -2,7 +2,7 @@ #begin lib_target #define BUILD_TARGET $[HAVE_PYTHON] - #define USE_PACKAGES openssl nspr + #define USE_PACKAGES openssl nspr #define TARGET distributed #define LOCAL_LIBS \ @@ -12,7 +12,7 @@ interrogatedb:c dconfig:c dtoolconfig:m \ dtoolutil:c dtoolbase:c dtool:m \ prc:c pstatclient:c pandabase:c linmath:c putil:c \ - pipeline:c $[if $[HAVE_NET],net:c] + pipeline:c $[if $[HAVE_NET],net:c] $[if $[WANT_NATIVE_NET],nativenet:c] #define SOURCES \ config_distributed.cxx config_distributed.h \ diff --git a/direct/src/distributed/cConnectionRepository.I b/direct/src/distributed/cConnectionRepository.I index b58fcbc8f0..12c10446dc 100644 --- a/direct/src/distributed/cConnectionRepository.I +++ b/direct/src/distributed/cConnectionRepository.I @@ -120,6 +120,20 @@ get_qcr() { INLINE QueuedConnectionReader &get_qcr(); #endif // HAVE_NSPR +#ifdef WANT_NATIVE_NET +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::get_bcd +// Access: Published +// Description: Returns the Buffered_DatagramConnection object associated +// with the repository. +//////////////////////////////////////////////////////////////////// +INLINE Buffered_DatagramConnection &CConnectionRepository:: +get_bdc() { + return _bdc; +} + INLINE Buffered_DatagramConnection &get_bdc(); +#endif + //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::get_datagram // Access: Published diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 22c60d83a4..b1a4cd4fcd 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -29,6 +29,7 @@ #include "pStatTimer.h" + const string CConnectionRepository::_overflow_event_name = "CRDatagramOverflow"; #ifndef CPPPARSER @@ -51,6 +52,10 @@ CConnectionRepository(bool has_owner_view) : #ifdef HAVE_NSPR _cw(&_qcm, 0), _qcr(&_qcm, 0), +#endif +#ifdef WANT_NATIVE_NET + _bdc(0,4096000,4096000,102400), + _native(false), #endif _client_datagram(true), _simulated_disconnect(false), @@ -140,6 +145,24 @@ try_connect_nspr(const URLSpec &url) { } #endif // HAVE_NSPR +#ifdef WANT_NATIVE_NET +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::connect_native +// Access: Published +// Description: Connects to the server using a native system roger +// put together +//////////////////////////////////////////////////////////////////// +bool CConnectionRepository:: +connect_native(const URLSpec &url) { + _native=true; + Socket_Address addr; + addr.set_host(url.get_server(),url.get_port()); + _bdc.AddAddress(addr); + return _bdc.IsConnected(); +} + +#endif //WANT NATIVE NET + #ifdef SIMULATE_NETWORK_DELAY //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::start_delay @@ -281,6 +304,12 @@ check_datagram() { //////////////////////////////////////////////////////////////////// bool CConnectionRepository:: is_connected() { + +#ifdef WANT_NATIVE_NET + if(_native) + return (_bdc.IsConnected()); +#endif + #ifdef HAVE_NSPR if (_nspr_conn) { if (_qcm.reset_connection_available()) { @@ -335,6 +364,11 @@ send_datagram(const Datagram &dg) { } #endif // NDEBUG +#ifdef WANT_NATIVE_NET + if(_native) + return _bdc.SendMessage(dg); +#endif + #ifdef HAVE_NSPR if (_nspr_conn) { _cw.send(dg, _nspr_conn); @@ -372,6 +406,12 @@ consider_flush() { return false; } +#ifdef WANT_NATIVE_NET + //NATIVENET HERE + if(_native) + return 1; +#endif + #ifdef HAVE_NSPR if (_nspr_conn) { return _nspr_conn->consider_flush(); @@ -399,6 +439,10 @@ flush() { if (_simulated_disconnect) { return false; } + #ifdef WANT_NATIVE_NET + if(_native) + return _bdc.Flush(); + #endif #ifdef HAVE_NSPR if (_nspr_conn) { @@ -422,6 +466,12 @@ flush() { //////////////////////////////////////////////////////////////////// void CConnectionRepository:: disconnect() { + #ifdef WANT_NATIVE_NET + if(_native) { + _bdc.Reset(); + _bdc.ClearAddresses(); + } + #endif #ifdef HAVE_NSPR if (_nspr_conn) { _qcm.close_connection(_nspr_conn); @@ -448,6 +498,15 @@ disconnect() { //////////////////////////////////////////////////////////////////// bool CConnectionRepository:: do_check_datagram() { + #ifdef WANT_NATIVE_NET + if(_native) { + Datagram * dgi; + bool ret= _bdc.GetMessageInternal(&dgi); + if(ret) + _dg=*dgi; + return ret; + } + #endif #ifdef HAVE_NSPR if (_nspr_conn) { _nspr_conn->consider_flush(); @@ -466,6 +525,7 @@ do_check_datagram() { } #endif // HAVE_OPENSSL + return false; } diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index 377a20001d..1b6d780f2c 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -35,6 +35,11 @@ #include "connection.h" #endif +#ifdef WANT_NATIVE_NET +#include "buffered_datagramconnection.h" +#include "socket_address.h" +#endif + class URLSpec; class HTTPChannel; class SocketStream; @@ -82,6 +87,11 @@ PUBLISHED: INLINE QueuedConnectionReader &get_qcr(); #endif +#ifdef WANT_NATIVE_NET + bool connect_native(const URLSpec &url); + INLINE Buffered_DatagramConnection &get_bdc(); +#endif + #ifdef SIMULATE_NETWORK_DELAY void start_delay(double min_delay, double max_delay); void stop_delay(); @@ -141,6 +151,11 @@ private: PT(Connection) _nspr_conn; #endif +#ifdef WANT_NATIVE_NET + Buffered_DatagramConnection _bdc; + bool _native; +#endif + DCFile _dc_file; bool _has_owner_view; bool _client_datagram;