CR now requires a connection method,will be changed to has-a later

This commit is contained in:
Zachary Pavlov 2006-11-09 22:22:59 +00:00
parent 426dc40890
commit c0f9dce26f
6 changed files with 109 additions and 15 deletions

View File

@ -25,7 +25,7 @@ class ClientRepositoryBase(ConnectionRepository):
def __init__(self, dcFileNames = None): def __init__(self, dcFileNames = None):
self.dcSuffix="" self.dcSuffix=""
ConnectionRepository.__init__(self, base.config, hasOwnerView=True) ConnectionRepository.__init__(self, ConnectionRepository.CM_HTTP, base.config, hasOwnerView=True)
self.context=100000 self.context=100000
self.setClientDatagram(1) self.setClientDatagram(1)

View File

@ -9,7 +9,9 @@ from PyDatagramIterator import PyDatagramIterator
import types import types
import imp import imp
class ConnectionRepository(
class ConnectionRepository(
DoInterestManager, DoCollectionManager, CConnectionRepository): DoInterestManager, DoCollectionManager, CConnectionRepository):
""" """
This is a base class for things that know how to establish a This is a base class for things that know how to establish a
@ -19,7 +21,12 @@ class ConnectionRepository(
notify = DirectNotifyGlobal.directNotify.newCategory("ConnectionRepository") notify = DirectNotifyGlobal.directNotify.newCategory("ConnectionRepository")
taskPriority = -30 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() assert self.notify.debugCall()
# let the C connection repository know whether we're supporting # let the C connection repository know whether we're supporting
# 'owner' views of distributed objects (i.e. 'receives ownrecv', # '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 # 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 is in place, but the NSPR interface if we don't have a
# proxy. # proxy.
self.connectMethod = self.config.GetString('connect-method', 'default') self.connectMethod=connectMethod
self.connectHttp = None self.connectHttp = None
self.http = None self.http = None
@ -366,16 +374,11 @@ class ConnectionRepository(
else: else:
self.notify.info("Connecting to gameserver directly (no proxy).") self.notify.info("Connecting to gameserver directly (no proxy).")
if self.connectMethod == 'http': #Redefine the connection to http or nspr in the default case
self.connectHttp = 1
elif self.connectMethod == 'nspr':
self.connectHttp = 0
else:
self.connectHttp = (hasProxy or serverList[0].isSsl())
self.bootedIndex = None self.bootedIndex = None
self.bootedText = 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 # In the HTTP case, we can't just iterate through the list
# of servers, because each server attempt requires # of servers, because each server attempt requires
# spawning a request and then coming back later to check # spawning a request and then coming back later to check
@ -389,7 +392,7 @@ class ConnectionRepository(
ch, serverList, 0, ch, serverList, 0,
successCallback, successArgs, successCallback, successArgs,
failureCallback, failureArgs) failureCallback, failureArgs)
else: elif self.connectMethod == self.CM_NSPR:
# Try each of the servers in turn. # Try each of the servers in turn.
for url in serverList: for url in serverList:
self.notify.info("Connecting to %s via NSPR interface." % (url.cStr())) self.notify.info("Connecting to %s via NSPR interface." % (url.cStr()))
@ -402,7 +405,9 @@ class ConnectionRepository(
# Failed to connect. # Failed to connect.
if failureCallback: if failureCallback:
failureCallback(0, '', *failureArgs) failureCallback(0, '', *failureArgs)
elif self.connectMethod == self.CM_NATIVE:
pass
def disconnect(self): def disconnect(self):
""" """
Closes the previously-established connection. Closes the previously-established connection.

View File

@ -2,7 +2,7 @@
#begin lib_target #begin lib_target
#define BUILD_TARGET $[HAVE_PYTHON] #define BUILD_TARGET $[HAVE_PYTHON]
#define USE_PACKAGES openssl nspr #define USE_PACKAGES openssl nspr
#define TARGET distributed #define TARGET distributed
#define LOCAL_LIBS \ #define LOCAL_LIBS \
@ -12,7 +12,7 @@
interrogatedb:c dconfig:c dtoolconfig:m \ interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m \ dtoolutil:c dtoolbase:c dtool:m \
prc:c pstatclient:c pandabase:c linmath:c putil:c \ 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 \ #define SOURCES \
config_distributed.cxx config_distributed.h \ config_distributed.cxx config_distributed.h \

View File

@ -120,6 +120,20 @@ get_qcr() {
INLINE QueuedConnectionReader &get_qcr(); INLINE QueuedConnectionReader &get_qcr();
#endif // HAVE_NSPR #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 // Function: CConnectionRepository::get_datagram
// Access: Published // Access: Published

View File

@ -29,6 +29,7 @@
#include "pStatTimer.h" #include "pStatTimer.h"
const string CConnectionRepository::_overflow_event_name = "CRDatagramOverflow"; const string CConnectionRepository::_overflow_event_name = "CRDatagramOverflow";
#ifndef CPPPARSER #ifndef CPPPARSER
@ -51,6 +52,10 @@ CConnectionRepository(bool has_owner_view) :
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
_cw(&_qcm, 0), _cw(&_qcm, 0),
_qcr(&_qcm, 0), _qcr(&_qcm, 0),
#endif
#ifdef WANT_NATIVE_NET
_bdc(0,4096000,4096000,102400),
_native(false),
#endif #endif
_client_datagram(true), _client_datagram(true),
_simulated_disconnect(false), _simulated_disconnect(false),
@ -140,6 +145,24 @@ try_connect_nspr(const URLSpec &url) {
} }
#endif // HAVE_NSPR #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 #ifdef SIMULATE_NETWORK_DELAY
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: CConnectionRepository::start_delay // Function: CConnectionRepository::start_delay
@ -281,6 +304,12 @@ check_datagram() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool CConnectionRepository:: bool CConnectionRepository::
is_connected() { is_connected() {
#ifdef WANT_NATIVE_NET
if(_native)
return (_bdc.IsConnected());
#endif
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
if (_qcm.reset_connection_available()) { if (_qcm.reset_connection_available()) {
@ -335,6 +364,11 @@ send_datagram(const Datagram &dg) {
} }
#endif // NDEBUG #endif // NDEBUG
#ifdef WANT_NATIVE_NET
if(_native)
return _bdc.SendMessage(dg);
#endif
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
_cw.send(dg, _nspr_conn); _cw.send(dg, _nspr_conn);
@ -372,6 +406,12 @@ consider_flush() {
return false; return false;
} }
#ifdef WANT_NATIVE_NET
//NATIVENET HERE
if(_native)
return 1;
#endif
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
return _nspr_conn->consider_flush(); return _nspr_conn->consider_flush();
@ -399,6 +439,10 @@ flush() {
if (_simulated_disconnect) { if (_simulated_disconnect) {
return false; return false;
} }
#ifdef WANT_NATIVE_NET
if(_native)
return _bdc.Flush();
#endif
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
@ -422,6 +466,12 @@ flush() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void CConnectionRepository:: void CConnectionRepository::
disconnect() { disconnect() {
#ifdef WANT_NATIVE_NET
if(_native) {
_bdc.Reset();
_bdc.ClearAddresses();
}
#endif
#ifdef HAVE_NSPR #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
_qcm.close_connection(_nspr_conn); _qcm.close_connection(_nspr_conn);
@ -448,6 +498,15 @@ disconnect() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool CConnectionRepository:: bool CConnectionRepository::
do_check_datagram() { 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 #ifdef HAVE_NSPR
if (_nspr_conn) { if (_nspr_conn) {
_nspr_conn->consider_flush(); _nspr_conn->consider_flush();
@ -466,6 +525,7 @@ do_check_datagram() {
} }
#endif // HAVE_OPENSSL #endif // HAVE_OPENSSL
return false; return false;
} }

View File

@ -35,6 +35,11 @@
#include "connection.h" #include "connection.h"
#endif #endif
#ifdef WANT_NATIVE_NET
#include "buffered_datagramconnection.h"
#include "socket_address.h"
#endif
class URLSpec; class URLSpec;
class HTTPChannel; class HTTPChannel;
class SocketStream; class SocketStream;
@ -82,6 +87,11 @@ PUBLISHED:
INLINE QueuedConnectionReader &get_qcr(); INLINE QueuedConnectionReader &get_qcr();
#endif #endif
#ifdef WANT_NATIVE_NET
bool connect_native(const URLSpec &url);
INLINE Buffered_DatagramConnection &get_bdc();
#endif
#ifdef SIMULATE_NETWORK_DELAY #ifdef SIMULATE_NETWORK_DELAY
void start_delay(double min_delay, double max_delay); void start_delay(double min_delay, double max_delay);
void stop_delay(); void stop_delay();
@ -141,6 +151,11 @@ private:
PT(Connection) _nspr_conn; PT(Connection) _nspr_conn;
#endif #endif
#ifdef WANT_NATIVE_NET
Buffered_DatagramConnection _bdc;
bool _native;
#endif
DCFile _dc_file; DCFile _dc_file;
bool _has_owner_view; bool _has_owner_view;
bool _client_datagram; bool _client_datagram;