From 1c763b5eeabe0ac3a4464fcf04c1be24df30876c Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:02:09 +0900 Subject: Stop polling for OUT immediately when no data in pipe This patch is an optimisation. So far, when there were no data in the pipe, it was only next out_event that stopped the polling for POLLOUT. Now, the polling is canceled immediately. Signed-off-by: Martin Sustrik --- src/stream_engine.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/stream_engine.cpp') diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 0034737..0ae96d2 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -208,11 +208,13 @@ void xs::stream_engine_t::in_event () void xs::stream_engine_t::out_event () { + bool more_data = true; + // If write buffer is empty, try to read new data from the encoder. if (!outsize) { outpos = NULL; - encoder.get_data (&outpos, &outsize); + more_data = encoder.get_data (&outpos, &outsize); // If IO handler has unplugged engine, flush transient IO handler. if (unlikely (!plugged)) { @@ -243,6 +245,11 @@ void xs::stream_engine_t::out_event () outpos += nbytes; outsize -= nbytes; + + // If the encoder reports that there are no more data to get from it + // we can stop polling for POLLOUT immediately. + if (!more_data) + reset_pollout (handle); } void xs::stream_engine_t::activate_out () -- cgit v1.2.3