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/encoder.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/encoder.hpp') diff --git a/src/encoder.hpp b/src/encoder.hpp index 93efbb8..d5ea467 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -63,7 +63,11 @@ namespace xs // If offset is not NULL, it is filled by offset of the first message // in the batch.If there's no beginning of a message in the batch, // offset is set to -1. - inline void get_data (unsigned char **data_, size_t *size_, + // If data is returned and return value is false, there are no more + // data available to get from the encoder the next time. Therefore, + // an optimisation can be made and the engine can stop polling for + // POLLOUT immediately. + inline bool get_data (unsigned char **data_, size_t *size_, int *offset_ = NULL) { unsigned char *buffer = !*data_ ? buf : *data_; @@ -82,7 +86,7 @@ namespace xs if (!(static_cast (this)->*next) ()) { *data_ = buffer; *size_ = pos; - return; + return false; } // If beginning of the message was processed, adjust the @@ -109,7 +113,7 @@ namespace xs *size_ = to_write; write_pos = NULL; to_write = 0; - return; + return true; } // Copy data to the buffer. If the buffer is full, return. @@ -121,7 +125,7 @@ namespace xs if (pos == buffersize) { *data_ = buffer; *size_ = pos; - return; + return true; } } } -- cgit v1.2.3