From abbbb21a8e930ecd98701abd310dedf765575eb9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 19 Nov 2009 02:37:09 +0000 Subject: [PATCH] some more explicit control over connection parameters --- direct/src/distributed/ClientRepository.py | 5 +-- .../src/distributed/ClientRepositoryBase.py | 7 ++-- .../src/distributed/ConnectionRepository.py | 9 +++-- direct/src/distributed/ServerRepository.py | 31 +++++++++++++--- .../src/distributed/cConnectionRepository.I | 11 ++++++ .../src/distributed/cConnectionRepository.cxx | 35 ++++++++++++++++--- .../src/distributed/cConnectionRepository.h | 7 +++- 7 files changed, 90 insertions(+), 15 deletions(-) diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index 9b676adf66..3b5257af69 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -24,8 +24,9 @@ class ClientRepository(ClientRepositoryBase): doNotDeallocateChannel = True - def __init__(self, dcFileNames = None, dcSuffix = ''): - ClientRepositoryBase.__init__(self, dcFileNames = dcFileNames, dcSuffix = dcSuffix) + def __init__(self, dcFileNames = None, dcSuffix = '', connectMethod = None, + threadedNet = None): + ClientRepositoryBase.__init__(self, dcFileNames = dcFileNames, dcSuffix = dcSuffix, connectMethod = connectMethod, threadedNet = threadedNet) self.setHandleDatagramsInternally(False) # The doId allocator. The CMU LAN server may choose to diff --git a/direct/src/distributed/ClientRepositoryBase.py b/direct/src/distributed/ClientRepositoryBase.py index 9a887114e2..470b8279f5 100644 --- a/direct/src/distributed/ClientRepositoryBase.py +++ b/direct/src/distributed/ClientRepositoryBase.py @@ -25,8 +25,11 @@ class ClientRepositoryBase(ConnectionRepository): """ notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepositoryBase") - def __init__(self, dcFileNames = None, dcSuffix = ''): - ConnectionRepository.__init__(self, ConnectionRepository.CM_HTTP, base.config, hasOwnerView=True) + def __init__(self, dcFileNames = None, dcSuffix = '', + connectMethod = None, threadedNet = None): + if connectMethod is None: + connectMethod = self.CM_HTTP + ConnectionRepository.__init__(self, connectMethod, base.config, hasOwnerView = True, threadedNet = threadedNet) self.dcSuffix = dcSuffix if hasattr(self, 'setVerbose'): if self.config.GetBool('verbose-clientrepository'): diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index 74dfbfa4bf..7995b1a2de 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -33,13 +33,18 @@ class ConnectionRepository( GarbageCollectTaskName = "allowGarbageCollect" GarbageThresholdTaskName = "adjustGarbageCollectThreshold" - def __init__(self, connectMethod, config, hasOwnerView=False): + def __init__(self, connectMethod, config, hasOwnerView = False, + threadedNet = None): assert self.notify.debugCall() + if threadedNet is None: + # Default value. + threadedNet = config.GetBool('threaded-net', False) + # let the C connection repository know whether we're supporting # 'owner' views of distributed objects (i.e. 'receives ownrecv', # 'I own this object and have a separate view of it regardless of # where it currently is located') - CConnectionRepository.__init__(self, hasOwnerView) + CConnectionRepository.__init__(self, hasOwnerView, threadedNet) self.setWantMessageBundling(config.GetBool('want-message-bundling', 1)) # DoInterestManager.__init__ relies on CConnectionRepository being # initialized diff --git a/direct/src/distributed/ServerRepository.py b/direct/src/distributed/ServerRepository.py index eb85256269..27e73d75f3 100644 --- a/direct/src/distributed/ServerRepository.py +++ b/direct/src/distributed/ServerRepository.py @@ -78,12 +78,20 @@ class ServerRepository: # record its current fields. That is left to the clients. - def __init__(self, tcpPort, udpPort = None, dcFileNames = None): + def __init__(self, tcpPort, udpPort = None, dcFileNames = None, + threadedNet = None): + if threadedNet is None: + # Default value. + threadedNet = config.GetBool('threaded-net', False) + # Set up networking interfaces. + numThreads = 0 + if threadedNet: + numThreads = 1 self.qcm = QueuedConnectionManager() - self.qcl = QueuedConnectionListener(self.qcm, 0) - self.qcr = QueuedConnectionReader(self.qcm, 0) - self.cw = ConnectionWriter(self.qcm, 0) + self.qcl = QueuedConnectionListener(self.qcm, numThreads) + self.qcr = QueuedConnectionReader(self.qcm, numThreads) + self.cw = ConnectionWriter(self.qcm, numThreads) self.tcpRendezvous = self.qcm.openTCPServerRendezvous(tcpPort, 10) self.qcl.addConnection(self.tcpRendezvous) taskMgr.add(self.listenerPoll, "serverListenerPollTask") @@ -137,6 +145,21 @@ class ServerRepository: return task.again + def setTcpHeaderSize(self, headerSize): + """Sets the header size of TCP packets. At the present, legal + values for this are 0, 2, or 4; this specifies the number of + bytes to use encode the datagram length at the start of each + TCP datagram. Sender and receiver must independently agree on + this.""" + self.qcr.setTcpHeaderSize(headerSize) + self.cw.setTcpHeaderSize(headerSize) + + def getTcpHeaderSize(self): + """Returns the current setting of TCP header size. See + setTcpHeaderSize(). """ + return self.qcr.getTcpHeaderSize() + + def importModule(self, dcImports, moduleName, importSymbols): """ Imports the indicated moduleName and all of its symbols into the current namespace. This more-or-less reimplements diff --git a/direct/src/distributed/cConnectionRepository.I b/direct/src/distributed/cConnectionRepository.I index 0a9aad525c..76405066b9 100644 --- a/direct/src/distributed/cConnectionRepository.I +++ b/direct/src/distributed/cConnectionRepository.I @@ -111,6 +111,17 @@ get_handle_datagrams_internally() const { return _handle_datagrams_internally; } +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::get_tcp_header_size +// Access: Public +// Description: Returns the current setting of TCP header size. +// See set_tcp_header_size(). +//////////////////////////////////////////////////////////////////// +INLINE int CConnectionRepository:: +get_tcp_header_size() const { + return _tcp_header_size; +} + #ifdef HAVE_PYTHON //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::set_python_repository diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 9b685feeeb..bbde55ed36 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -18,6 +18,7 @@ #include "dcPacker.h" #include "config_distributed.h" +#include "config_downloader.h" #include "httpChannel.h" #include "urlSpec.h" #include "datagramIterator.h" @@ -44,7 +45,7 @@ PStatCollector CConnectionRepository::_update_pcollector("App:Show code:readerPo // Description: //////////////////////////////////////////////////////////////////// CConnectionRepository:: -CConnectionRepository(bool has_owner_view) : +CConnectionRepository(bool has_owner_view, bool threaded_net) : _lock("CConnectionRepository::_lock"), #ifdef HAVE_PYTHON _python_repository(NULL), @@ -54,8 +55,8 @@ CConnectionRepository(bool has_owner_view) : _http_conn(NULL), #endif #ifdef HAVE_NET - _cw(&_qcm, 0), - _qcr(&_qcm, 0), + _cw(&_qcm, threaded_net ? 1 : 0), + _qcr(&_qcm, threaded_net ? 1 : 0), #endif #ifdef WANT_NATIVE_NET _bdc(4096000,4096000,1400), @@ -79,7 +80,7 @@ CConnectionRepository(bool has_owner_view) : _qcr.start_delay(min_lag, max_lag); } #endif - + _tcp_header_size = tcp_header_size; #ifdef HAVE_PYTHON PyObject * PyDitterator = DTool_CreatePyInstance(&_di,Dtool_DatagramIterator,false,false); @@ -99,6 +100,31 @@ CConnectionRepository:: disconnect(); } +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::set_tcp_header_size +// Access: Public +// Description: Sets the header size of TCP packets. At the present, +// legal values for this are 0, 2, or 4; this specifies +// the number of bytes to use encode the datagram length +// at the start of each TCP datagram. Sender and +// receiver must independently agree on this. +//////////////////////////////////////////////////////////////////// +void CConnectionRepository:: +set_tcp_header_size(int tcp_header_size) { + _tcp_header_size = tcp_header_size; + +#ifdef HAVE_OPENSSL + if (_http_conn != (SocketStream *)NULL) { + _http_conn->set_tcp_header_size(tcp_header_size); + } +#endif + +#ifdef HAVE_NET + _cw.set_tcp_header_size(tcp_header_size); + _qcr.set_tcp_header_size(tcp_header_size); +#endif +} + #ifdef HAVE_OPENSSL //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::set_connection_http @@ -115,6 +141,7 @@ set_connection_http(HTTPChannel *channel) { disconnect(); nassertv(channel->is_connection_ready()); _http_conn = channel->get_connection(); + _http_conn->set_tcp_header_size(_tcp_header_size); #ifdef SIMULATE_NETWORK_DELAY if (min_lag != 0.0 || max_lag != 0.0) { _http_conn->start_delay(min_lag, max_lag); diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index 37958a90fb..13bfbf853a 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -60,7 +60,8 @@ class SocketStream; //////////////////////////////////////////////////////////////////// class EXPCL_DIRECT CConnectionRepository { PUBLISHED: - CConnectionRepository(bool has_owner_view = false); + CConnectionRepository(bool has_owner_view = false, + bool threaded_net = false); ~CConnectionRepository(); INLINE DCFile &get_dc_file(); @@ -76,6 +77,9 @@ PUBLISHED: INLINE void set_handle_datagrams_internally(bool handle_datagrams_internally); INLINE bool get_handle_datagrams_internally() const; + void set_tcp_header_size(int tcp_header_size); + INLINE int get_tcp_header_size() const; + #ifdef HAVE_PYTHON INLINE void set_python_repository(PyObject *python_repository); #endif @@ -192,6 +196,7 @@ private: bool _handle_c_updates; bool _client_datagram; bool _handle_datagrams_internally; + int _tcp_header_size; bool _simulated_disconnect; bool _verbose; bool _in_quiet_zone;