From 4b0a024743186ec855dde1c3795df6d90b58b62f Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Wed, 5 Dec 2007 03:17:41 +0000 Subject: [PATCH] added support for nested message bundles --- .../src/distributed/cConnectionRepository.I | 11 ++++ .../src/distributed/cConnectionRepository.cxx | 65 +++++++++++-------- .../src/distributed/cConnectionRepository.h | 4 +- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/direct/src/distributed/cConnectionRepository.I b/direct/src/distributed/cConnectionRepository.I index 754c44b1cb..79db81aa06 100644 --- a/direct/src/distributed/cConnectionRepository.I +++ b/direct/src/distributed/cConnectionRepository.I @@ -247,6 +247,17 @@ get_overflow_event_name() { return _overflow_event_name; } +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::is_bundling_messages +// Access: Published +// Description: Returns true if repository is queueing outgoing messages +// into a message bundle +//////////////////////////////////////////////////////////////////// +INLINE bool CConnectionRepository:: +is_bundling_messages() const { + return _bundling_msgs > 0; +} + //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::set_simulated_disconnect // Access: Published diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 9c619b247e..e791157680 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -72,7 +72,7 @@ CConnectionRepository(bool has_owner_view) : _msg_type(0), _has_owner_view(has_owner_view), _handle_c_updates(true), - _bundling_msgs(false) + _bundling_msgs(0) { #if defined(HAVE_NET) && defined(SIMULATE_NETWORK_DELAY) if (min_lag != 0.0 || max_lag != 0.0) { @@ -392,7 +392,7 @@ send_datagram(const Datagram &dg) { describe_message(nout, "SEND", dg); } - if (_bundling_msgs) { + if (is_bundling_messages()) { bundle_msg(dg); return false; } @@ -441,14 +441,13 @@ start_message_bundle() { // all updates in between must be sent from the same doId (updates // must all affect the same DistributedObject) // it is an error to call this again before calling sendMessageBundle - // NOTE: this is currently only implemented for setLocation and sendUpdate - // msgs - nassertv(!_bundling_msgs); - _bundling_msgs = true; - _bundle_msgs.clear(); if (get_verbose()) { - nout << "CR::SEND:BUNDLE_START" << endl; + nout << "CR::SEND:BUNDLE_START(" << _bundling_msgs << ")" << endl; } + if (_bundling_msgs == 0) { + _bundle_msgs.clear(); + } + ++_bundling_msgs; } //////////////////////////////////////////////////////////////////// @@ -460,27 +459,41 @@ void CConnectionRepository:: send_message_bundle(unsigned int channel, unsigned int sender_channel) { nassertv(_bundling_msgs); - Datagram dg; - // add server header (see PyDatagram.addServerHeader) - dg.add_int8(1); - dg.add_uint64(channel); - dg.add_uint64(sender_channel); - dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); - // add each bundled message - BundledMsgVector::const_iterator bmi; - for (bmi = _bundle_msgs.begin(); bmi != _bundle_msgs.end(); bmi++) { - dg.add_string(*bmi); - } - - _bundling_msgs = false; - _bundle_msgs.clear(); + --_bundling_msgs; if (get_verbose()) { - nout << "CR::SEND:BUNDLE_FINISH" << endl; + nout << "CR::SEND:BUNDLE_FINISH(" << _bundling_msgs << ")" << endl; } - // once _bundling_msgs flag is set to false, we can send the datagram - send_datagram(dg); + // if _bundling_msgs ref count is zero, send the bundle out + if (_bundling_msgs == 0) { + Datagram dg; + // add server header (see PyDatagram.addServerHeader) + dg.add_int8(1); + dg.add_uint64(channel); + dg.add_uint64(sender_channel); + dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); + // add each bundled message + BundledMsgVector::const_iterator bmi; + for (bmi = _bundle_msgs.begin(); bmi != _bundle_msgs.end(); bmi++) { + dg.add_string(*bmi); + } + + send_datagram(dg); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::abandon_message_bundles +// Access: Published +// Description: throw out any msgs that have been queued up for +// message bundles +//////////////////////////////////////////////////////////////////// +void CConnectionRepository:: +abandon_message_bundles() { + nassertv(is_bundling_messages()); + _bundling_msgs = 0; + _bundle_msgs.clear(); } //////////////////////////////////////////////////////////////////// @@ -490,7 +503,7 @@ send_message_bundle(unsigned int channel, unsigned int sender_channel) { //////////////////////////////////////////////////////////////////// void CConnectionRepository:: bundle_msg(const Datagram &dg) { - nassertv(_bundling_msgs); + nassertv(is_bundling_messages()); _bundle_msgs.push_back(dg.get_message()); } diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index 686c828a1f..be6dd83dc1 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -124,7 +124,9 @@ PUBLISHED: bool send_datagram(const Datagram &dg); void start_message_bundle(); + INLINE bool is_bundling_messages() const; void send_message_bundle(unsigned int channel, unsigned int sender_channel); + void abandon_message_bundles(); void bundle_msg(const Datagram &dg); bool consider_flush(); @@ -191,7 +193,7 @@ private: static const string _overflow_event_name; - bool _bundling_msgs; + unsigned int _bundling_msgs; typedef std::vector< const string > BundledMsgVector; BundledMsgVector _bundle_msgs;