Browse Source

filter out overlarge frames

David Rose 18 years ago
parent
commit
8d8a4cf620

+ 7 - 2
panda/src/pstatclient/pStatClientImpl.cxx

@@ -247,10 +247,15 @@ transmit_frame_data(int thread_index) {
 
       datagram.add_uint16(thread_index);
       datagram.add_uint32(thread->_frame_number);
-      thread->_frame_data.write_datagram(datagram);
 
       bool sent;
-      if (_writer.is_valid_for_udp(datagram)) {
+
+      if (!thread->_frame_data.write_datagram(datagram, _client)) {
+        // Too many events to fit in a single datagram.  Maybe it was
+        // a long frame load or something.  Just drop the datagram.
+        sent = false;
+
+      } else if (_writer.is_valid_for_udp(datagram)) {
         if (_udp_count * _udp_count_factor < _tcp_count * _tcp_count_factor) {
           // Send this one as a UDP packet.
           nassertv(_got_udp_port);

+ 14 - 3
panda/src/pstatclient/pStatFrameData.cxx

@@ -18,6 +18,7 @@
 
 #include "pStatFrameData.h"
 #include "pStatClientVersion.h"
+#include "config_pstats.h"
 
 #include "datagram.h"
 #include "datagramIterator.h"
@@ -39,11 +40,19 @@ sort_time() {
 //     Function: PStatFrameData::write_datagram
 //       Access: Public
 //  Description: Writes the definition of the FrameData to the
-//               datagram.
+//               datagram.  Returns true on success, false on failure.
 ////////////////////////////////////////////////////////////////////
-void PStatFrameData::
-write_datagram(Datagram &destination) const {
+bool PStatFrameData::
+write_datagram(Datagram &destination, PStatClient *client) const {
   Data::const_iterator di;
+  if (_time_data.size() >= 65536 || _level_data.size() >= 65536) {
+    pstats_cat.info()
+      << "Dropping frame with " << _time_data.size()
+      << " time measurements and " << _level_data.size()
+      << " level measurements.\n";
+    return false;
+  }
+
   destination.add_uint16(_time_data.size());
   for (di = _time_data.begin(); di != _time_data.end(); ++di) {
     destination.add_uint16((*di)._index);
@@ -54,6 +63,8 @@ write_datagram(Datagram &destination) const {
     destination.add_uint16((*di)._index);
     destination.add_float32((*di)._value);
   }
+  
+  return true;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 2 - 1
panda/src/pstatclient/pStatFrameData.h

@@ -28,6 +28,7 @@
 class Datagram;
 class DatagramIterator;
 class PStatClientVersion;
+class PStatClient;
 
 ////////////////////////////////////////////////////////////////////
 //       Class : PStatFrameData
@@ -62,7 +63,7 @@ public:
   INLINE int get_level_collector(int n) const;
   INLINE float get_level(int n) const;
 
-  void write_datagram(Datagram &destination) const;
+  bool write_datagram(Datagram &destination, PStatClient *client) const;
   void read_datagram(DatagramIterator &source, PStatClientVersion *version);
 
 private: