9#include "wvencoderstream.h"
18WvEncoderStream::~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 );
104void WvEncoderStream::pull(
size_t size)
113 cloned->read(readinbuf, size);
120 tmpbuf.
merge(readoutbuf);
148bool 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 );
233void WvEncoderStream::checkreadisok()
243void WvEncoderStream::checkwriteisok()
virtual bool isok() const =0
By default, returns true if geterr() == 0.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
void put(const T *data, size_t count)
Writes the specified number of elements from the specified storage location into the buffer at its ta...
void unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads.
void move(T *buf, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
bool continue_encode(WvBuf &inbuf, WvBuf &outbuf)
"Continues" encoding a buffer.
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.
virtual void close()
Safely shuts down the stream.
virtual bool isok() const
Defines isok() semantics for encoders.
bool flush_read()
Flushes the read chain through to the stream's input buffer.
WvEncoderChain writechain
Encoder chain through which output data is passed.
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.
bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
bool flush_write()
Flushes the write chain through to the stream's output buffer.
void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual size_t uread(void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
bool finish_write()
Calls flush() then finish() on the write chain of encoders.
WvEncoderStream(WvStream *cloned)
Creates an encoder stream.
bool finish_read()
Calls flush() then finish() on the read chain of encoders.
bool finish(WvBuf &outbuf)
Tells the encoder that NO MORE DATA will ever be encoded.
bool isok() const
Returns true if the encoder has not encountered an error.
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.
bool isfinished() const
Returns true if the encoder can no longer encode data.
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
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...
WvStreamClone simply forwards all requests to the "cloned" stream.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual void close()
Close this stream.
virtual void noread()
Shuts down the reading side of the stream.
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
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...
virtual bool isok() const
return true if the stream is actually usable right now
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
WvString is an implementation of a simple and efficient printable-string class.
the data structure used by pre_select()/post_select() and internally by select().