mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -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):
|
def startReaderPollTask(self):
|
||||||
# Stop any tasks we are running now
|
# Stop any tasks we are running now
|
||||||
self.stopReaderPollTask()
|
self.stopReaderPollTask()
|
||||||
|
self.accept(CConnectionRepository.getOverflowEventName(),
|
||||||
|
self.handleReaderOverflow)
|
||||||
taskMgr.add(self.readerPollUntilEmpty, "readerPollTask",
|
taskMgr.add(self.readerPollUntilEmpty, "readerPollTask",
|
||||||
priority = self.taskPriority)
|
priority = self.taskPriority)
|
||||||
|
|
||||||
def stopReaderPollTask(self):
|
def stopReaderPollTask(self):
|
||||||
taskMgr.remove("readerPollTask")
|
taskMgr.remove("readerPollTask")
|
||||||
|
self.ignore(CConnectionRepository.getOverflowEventName())
|
||||||
|
|
||||||
def readerPollUntilEmpty(self, task):
|
def readerPollUntilEmpty(self, task):
|
||||||
while self.readerPollOnce():
|
while self.readerPollOnce():
|
||||||
@ -333,6 +336,11 @@ class ConnectionRepository(DirectObject.DirectObject, CConnectionRepository):
|
|||||||
self.lostConnection()
|
self.lostConnection()
|
||||||
return 0
|
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):
|
def lostConnection(self):
|
||||||
# This should be overrided by a derived class to handle an
|
# This should be overrided by a derived class to handle an
|
||||||
# unexpectedly lost connection to the gameserver.
|
# unexpectedly lost connection to the gameserver.
|
||||||
|
@ -182,6 +182,17 @@ get_msg_type() const {
|
|||||||
return _msg_type;
|
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
|
// Function: CConnectionRepository::set_simulated_disconnect
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
#include "httpChannel.h"
|
#include "httpChannel.h"
|
||||||
#include "urlSpec.h"
|
#include "urlSpec.h"
|
||||||
#include "datagramIterator.h"
|
#include "datagramIterator.h"
|
||||||
|
#include "throw_event.h"
|
||||||
|
|
||||||
|
const string CConnectionRepository::_overflow_event_name = "CRDatagramOverflow";
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::Constructor
|
// Function: CConnectionRepository::Constructor
|
||||||
@ -345,6 +348,10 @@ do_check_datagram() {
|
|||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NSPR
|
||||||
if (_nspr_conn) {
|
if (_nspr_conn) {
|
||||||
_nspr_conn->consider_flush();
|
_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));
|
return (_qcr.data_available() && _qcr.get_data(_dg));
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NSPR
|
||||||
|
@ -83,6 +83,8 @@ PUBLISHED:
|
|||||||
INLINE unsigned char get_sec_code() const;
|
INLINE unsigned char get_sec_code() const;
|
||||||
INLINE unsigned int get_msg_type() const;
|
INLINE unsigned int get_msg_type() const;
|
||||||
|
|
||||||
|
INLINE static const string &get_overflow_event_name();
|
||||||
|
|
||||||
bool is_connected();
|
bool is_connected();
|
||||||
|
|
||||||
bool send_datagram(const Datagram &dg);
|
bool send_datagram(const Datagram &dg);
|
||||||
@ -124,6 +126,8 @@ private:
|
|||||||
unsigned int _msg_sender;
|
unsigned int _msg_sender;
|
||||||
unsigned char _sec_code;
|
unsigned char _sec_code;
|
||||||
unsigned int _msg_type;
|
unsigned int _msg_type;
|
||||||
|
|
||||||
|
static const string _overflow_event_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "cConnectionRepository.I"
|
#include "cConnectionRepository.I"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user