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()
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
bool flush_write()
Flushes the write chain through to the stream's output buffer.
WvEncoderChain writechain
Encoder chain through which output data is passed.
WvEncoderStream(WvStream *cloned)
Creates an encoder stream.
bool isfinished() const
Returns true if the encoder can no longer encode data.
void unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads.
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 void close()
Close this stream.
virtual bool isok() const
Defines isok() semantics for encoders.
bool finish_read()
Calls flush() then finish() on the read chain of encoders.
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
virtual size_t uread(void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
virtual void noread()
Shuts down the reading side of the stream.
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.
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.
size_t min_readsize
Controls the minimum number of unencoded bytes the encoder should try to read at once from the underl...
the data structure used by pre_select()/post_select() and internally by select().
bool continue_encode(WvBuf &inbuf, WvBuf &outbuf)
"Continues" encoding a buffer.
WvStreamClone simply forwards all requests to the "cloned" stream.
WvString geterror() const
Returns an error message if any is available.
virtual bool isok() const =0
By default, returns true if geterr() == 0.
virtual bool isok() const
return true if the stream is actually usable right now
bool isok() const
Returns true if the encoder has not encountered an error.
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
bool finish(WvBuf &outbuf)
Tells the encoder that NO MORE DATA will ever be encoded.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
bool flush_read()
Flushes the read chain through to the stream's input buffer.
virtual void close()
Safely shuts down the stream.
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
bool finish_write()
Calls flush() then finish() on the write chain of encoders.
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
WvEncoderChain readchain
Encoder chain through which input data is passed.
void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
virtual bool flush_internal(time_t msec_timeout)
WvStream overrides.