9 #include "wvencoderstream.h" 18 WvEncoderStream::~WvEncoderStream()
32 if (is_closing)
return;
56 if (!cloned || cloned->
geterr() != 0)
74 inbuf.
merge(readoutbuf);
81 bool success = push(
true ,
false );
92 inbuf.
merge(readoutbuf);
100 return push(
true ,
true );
104 void WvEncoderStream::pull(
size_t size)
113 cloned->read(readinbuf, size);
120 tmpbuf.
merge(readoutbuf);
148 bool WvEncoderStream::push(
bool flush,
bool finish)
154 writeinbuf.
merge(outbuf);
163 size_t size = writeoutbuf.
used();
166 const unsigned char *writeout = writeoutbuf.
get(size);
168 writeoutbuf.
unget(size - len);
172 cloned->write(writeoutbuf, writeoutbuf.
used());
181 if (size && readoutbuf.
used() == 0)
183 size_t avail = readoutbuf.
used();
186 readoutbuf.move(buf, size);
193 writeinbuf.put(buf, size);
194 push(
false ,
false );
203 if (si.wants.readable && readoutbuf.
used() != 0)
215 if (si.wants.readable && readoutbuf.
used() != 0)
218 if (readoutbuf.
used() != 0)
224 push(
false ,
false );
233 void WvEncoderStream::checkreadisok()
243 void WvEncoderStream::checkwriteisok()
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
WvString geterror() const
Returns an error message if any is available.
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
bool isfinished() const
Returns true if the encoder can no longer encode data.
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
bool isok() const
Returns true if the encoder has not encountered an error.
virtual size_t uread(void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
virtual bool flush(time_t msec_timeout)
flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a ti...
WvEncoderStream(WvStream *cloned)
Creates an encoder stream.
size_t min_readsize
Controls the minimum number of unencoded bytes the encoder should try to read at once from the underl...
WvEncoderChain readchain
Encoder chain through which input data is passed.
virtual bool isok() const
Defines isok() semantics for encoders.
WvEncoderChain writechain
Encoder chain through which output data is passed.
virtual void noread()
Shuts down the reading side of the stream.
bool continue_encode(WvBuf &inbuf, WvBuf &outbuf)
"Continues" encoding a buffer.
bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
bool finish(WvBuf &outbuf)
Tells the encoder that NO MORE DATA will ever be encoded.
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
the data structure used by pre_select()/post_select() and internally by select(). ...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
bool flush_write()
Flushes the write chain through to the stream's output buffer.
virtual bool isok() const
return true if the stream is actually usable right now
virtual void close()
Close this stream.
virtual void close()
Safely shuts down the stream.
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
virtual bool isok() const =0
By default, returns true if geterr() == 0.
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
bool flush_read()
Flushes the read chain through to the stream's input buffer.
bool finish_read()
Calls flush() then finish() on the read chain of encoders.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
bool encode(WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false)
Reads data from the input buffer, encodes it, and writes the result to the output buffer...
WvString is an implementation of a simple and efficient printable-string class.
bool finish_write()
Calls flush() then finish() on the write chain of encoders.
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.
WvStreamClone simply forwards all requests to the "cloned" stream.
void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
void unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads...