From 54c1538aee9691b7e106b04664156c3d7573eba1 Mon Sep 17 00:00:00 2001 From: Reinhard Pfau Date: Mon, 1 Sep 2008 07:35:53 +0000 Subject: [PATCH] libsimpleio: (reinhard) modified server connection to allow fill_buffer without a backend cycle. --- glue_t2n/simpleio_t2n.cpp | 46 ++++++++++++++++++++++++++++++++++++-------- glue_t2n/simpleio_t2n.hpp | 3 ++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/glue_t2n/simpleio_t2n.cpp b/glue_t2n/simpleio_t2n.cpp index 6dfeacb..a2f55d6 100644 --- a/glue_t2n/simpleio_t2n.cpp +++ b/glue_t2n/simpleio_t2n.cpp @@ -621,11 +621,13 @@ void T2NServerConnection::real_write(const std::string& data) * Since this class uses the asnychronous SimpleIo framework, new data may already be read when * this method is called. * + * @param wait determines if we need to wait; if @a false it is just checked if new data + * was received, but no backend cycle is executed. * @param usec_timeout * @param usec_timeout_remaining * @return @a true if new data is available. */ -bool T2NServerConnection::fill_buffer(long long usec_timeout,long long* usec_timeout_remaining) +bool T2NServerConnection::low_fill_buffer(bool wait, long long usec_timeout, long long* usec_timeout_remaining) { SCOPETRACKER(); if (is_closed()) @@ -633,10 +635,10 @@ bool T2NServerConnection::fill_buffer(long long usec_timeout,long long* usec_tim module_logger().debug(HERE) << "fill_buffer() called on closed connection"; return false; } - SimpleIo::MilliTime t0,t1; - SimpleIo::get_current_monotonic_time(t0); - if (!m_got_new_data) + if (not m_got_new_data and wait) { + SimpleIo::MilliTime t0,t1; + SimpleIo::get_current_monotonic_time(t0); IOExportWrapperBasePtr ptr = boost::dynamic_pointer_cast< IOExportWrapperBase >(m_real_connection); if (!ptr) { @@ -665,12 +667,19 @@ bool T2NServerConnection::fill_buffer(long long usec_timeout,long long* usec_tim } } Backend::getBackend()->doOneStep( timeout ); + SimpleIo::get_current_monotonic_time(t1); + if (usec_timeout_remaining) + { + long long delta= ((long long)(t1 - t0).get_milliseconds())* 1000L; + *usec_timeout_remaining= (usec_timeout > delta ) ? (usec_timeout - delta) : 0L; + } } - SimpleIo::get_current_monotonic_time(t1); - if (usec_timeout_remaining) + else { - long long delta= ((long long)(t1 - t0).get_milliseconds())* 1000L; - *usec_timeout_remaining= (usec_timeout > delta ) ? (usec_timeout - delta) : 0L; + if (usec_timeout_remaining) + { + *usec_timeout_remaining= usec_timeout; + } } if (m_got_new_data) { @@ -678,6 +687,22 @@ bool T2NServerConnection::fill_buffer(long long usec_timeout,long long* usec_tim return true; } return false; +} // eo T2NServerConnection::low_fill_buffer(bool,long long,long long*) + + +/** + * @brief called to fill the connection buffer. + * + * Since this class uses the asnychronous SimpleIo framework, new data may already be read when + * this method is called. + * + * @param usec_timeout + * @param usec_timeout_remaining + * @return @a true if new data is available. + */ +bool T2NServerConnection::fill_buffer(long long usec_timeout,long long* usec_timeout_remaining) +{ + return low_fill_buffer(true, usec_timeout, usec_timeout_remaining); } // eo T2NServerConnection::fill_buffer(long long,long long*) @@ -806,7 +831,10 @@ bool T2NServerBase::fill_connection_buffers() } continue; } - result= result or conn->fill_buffer(0); + if ( conn->low_fill_buffer(false, 0) ) + { + result= true; + } } return result; } // eo T2NServerBase::fill_connection_buffers() diff --git a/glue_t2n/simpleio_t2n.hpp b/glue_t2n/simpleio_t2n.hpp index 24b3594..c57fb8a 100644 --- a/glue_t2n/simpleio_t2n.hpp +++ b/glue_t2n/simpleio_t2n.hpp @@ -121,6 +121,8 @@ class T2NServerConnection void eofSlot(); + bool low_fill_buffer(bool wait, long long usec_timeout=-1, long long* usec_timeout_remaining=NULL); + /* ** overloaded methods from t2n classes: */ @@ -129,6 +131,7 @@ class T2NServerConnection virtual bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL); + protected: SimpleIo::IOImplementationPtr m_real_connection; -- 1.7.1