From da0908002cea260dd6e7e5c2ec03b6f104c4a6f6 Mon Sep 17 00:00:00 2001 From: Abhishek Nath Date: Fri, 7 May 2010 05:56:29 +0000 Subject: [PATCH] Stop the hard crash at the python level when maximum buffer size is exceeded --- .../nativenet/buffered_datagramconnection.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/panda/src/nativenet/buffered_datagramconnection.h b/panda/src/nativenet/buffered_datagramconnection.h index c22de6050c..4dc440e364 100755 --- a/panda/src/nativenet/buffered_datagramconnection.h +++ b/panda/src/nativenet/buffered_datagramconnection.h @@ -237,10 +237,23 @@ inline bool Buffered_DatagramConnection::SendMessage(const Datagram &msg) // printf(" DO SendMessage %d\n",msg.get_length()); int val = 0; val = _Writer.AddData(msg.get_data(),msg.get_length(),*this); + if(val >= 0) + return true; + // Raise an exception to give us more information at the python level + nativenet_cat.warning() << "Buffered_DatagramConnection::SendMessage->Error On Write--Out Buffer = " << _Writer.AmountBuffered() << "\n"; + #ifdef HAVE_PYTHON + ostringstream s; + PyObject *exc_type = PyExc_StandardError; - if(val >= 0) - return true; - nativenet_cat.error() << "Buffered_DatagramConnection::SendMessage->Error On Write--Out Buffer = " << _Writer.AmountBuffered() << "\n"; + s << endl << "Error sending message: " << endl; + msg.dump_hex(s); + + s << "Message data: " << msg.get_data() << endl; + + string message = s.str(); + PyErr_SetString(exc_type, message.c_str()); + #endif + ClearAll(); } return false;