mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
CR now requires a connection method,will be changed to has-a later
This commit is contained in:
parent
426dc40890
commit
c0f9dce26f
@ -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)
|
||||
|
@ -9,6 +9,8 @@ from PyDatagramIterator import PyDatagramIterator
|
||||
import types
|
||||
import imp
|
||||
|
||||
|
||||
|
||||
class ConnectionRepository(
|
||||
DoInterestManager, DoCollectionManager, CConnectionRepository):
|
||||
"""
|
||||
@ -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,6 +405,8 @@ class ConnectionRepository(
|
||||
# Failed to connect.
|
||||
if failureCallback:
|
||||
failureCallback(0, '', *failureArgs)
|
||||
elif self.connectMethod == self.CM_NATIVE:
|
||||
pass
|
||||
|
||||
def disconnect(self):
|
||||
"""
|
||||
|
@ -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 \
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user