From 13391938bb2ffed25226e4e6bb2f9d3a69953888 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Tue, 29 Jun 2004 02:24:06 +0000 Subject: [PATCH] detect incoming-datagram buffer overflow --- direct/src/distributed/ConnectionRepository.py | 8 ++++++++ direct/src/distributed/cConnectionRepository.I | 11 +++++++++++ direct/src/distributed/cConnectionRepository.cxx | 7 +++++++ direct/src/distributed/cConnectionRepository.h | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index 1603ceb5d9..07d738d48a 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -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. diff --git a/direct/src/distributed/cConnectionRepository.I b/direct/src/distributed/cConnectionRepository.I index abdcb4b4e0..89d22bd31a 100644 --- a/direct/src/distributed/cConnectionRepository.I +++ b/direct/src/distributed/cConnectionRepository.I @@ -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 diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 950469c880..60920d4fc3 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -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 diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index ddf44c7f90..f9268e9be3 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -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"