mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
detect incoming-datagram buffer overflow
This commit is contained in:
parent
03951a3b1f
commit
13391938bb
@ -310,11 +310,14 @@ class ConnectionRepository(DirectObject.DirectObject, CConnectionRepository):
|
||||
def startReaderPollTask(self):
|
||||
# Stop any tasks we are running now
|
||||
self.stopReaderPollTask()
|
||||
self.accept(CConnectionRepository.getOverflowEventName(),
|
||||
self.handleReaderOverflow)
|
||||
taskMgr.add(self.readerPollUntilEmpty, "readerPollTask",
|
||||
priority = self.taskPriority)
|
||||
|
||||
def stopReaderPollTask(self):
|
||||
taskMgr.remove("readerPollTask")
|
||||
self.ignore(CConnectionRepository.getOverflowEventName())
|
||||
|
||||
def readerPollUntilEmpty(self, task):
|
||||
while self.readerPollOnce():
|
||||
@ -333,6 +336,11 @@ class ConnectionRepository(DirectObject.DirectObject, CConnectionRepository):
|
||||
self.lostConnection()
|
||||
return 0
|
||||
|
||||
def handleReaderOverflow(self):
|
||||
# this is called if the incoming-datagram queue overflowed and
|
||||
# we lost some data. Override and handle if desired.
|
||||
pass
|
||||
|
||||
def lostConnection(self):
|
||||
# This should be overrided by a derived class to handle an
|
||||
# unexpectedly lost connection to the gameserver.
|
||||
|
@ -182,6 +182,17 @@ get_msg_type() const {
|
||||
return _msg_type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CConnectionRepository::get_overflow_event_name
|
||||
// Access: Published
|
||||
// Description: Returns event string that will be thrown if the
|
||||
// datagram reader queue overflows.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const string &CConnectionRepository::
|
||||
get_overflow_event_name() {
|
||||
return _overflow_event_name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CConnectionRepository::set_simulated_disconnect
|
||||
// Access: Published
|
||||
|
@ -24,6 +24,9 @@
|
||||
#include "httpChannel.h"
|
||||
#include "urlSpec.h"
|
||||
#include "datagramIterator.h"
|
||||
#include "throw_event.h"
|
||||
|
||||
const string CConnectionRepository::_overflow_event_name = "CRDatagramOverflow";
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CConnectionRepository::Constructor
|
||||
@ -345,6 +348,10 @@ do_check_datagram() {
|
||||
#ifdef HAVE_NSPR
|
||||
if (_nspr_conn) {
|
||||
_nspr_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
|
||||
|
@ -83,6 +83,8 @@ PUBLISHED:
|
||||
INLINE unsigned char get_sec_code() const;
|
||||
INLINE unsigned int get_msg_type() const;
|
||||
|
||||
INLINE static const string &get_overflow_event_name();
|
||||
|
||||
bool is_connected();
|
||||
|
||||
bool send_datagram(const Datagram &dg);
|
||||
@ -124,6 +126,8 @@ private:
|
||||
unsigned int _msg_sender;
|
||||
unsigned char _sec_code;
|
||||
unsigned int _msg_type;
|
||||
|
||||
static const string _overflow_event_name;
|
||||
};
|
||||
|
||||
#include "cConnectionRepository.I"
|
||||
|
Loading…
x
Reference in New Issue
Block a user