9#include "wvencoderstream.h"
18WvEncoderStream::~WvEncoderStream()
32 if (is_closing)
return;
56 if (!cloned || cloned->geterr() != 0)
72 bool success =
readchain.flush(readinbuf, readoutbuf);
74 inbuf.merge(readoutbuf);
81 bool success = push(
true ,
false );
88 bool success =
readchain.flush(readinbuf, readoutbuf);
92 inbuf.merge(readoutbuf);
100 return push(
true ,
true );
104void WvEncoderStream::pull(
size_t size)
113 cloned->read(readinbuf, size);
120 tmpbuf.
merge(readoutbuf);
121 readchain.continue_encode(tmpbuf, readoutbuf);
127 readchain.encode(readinbuf, readoutbuf,
true);
137 else if (!readoutbuf.used() && !inbuf.used() &&
readchain.isfinished())
148bool WvEncoderStream::push(
bool flush,
bool finish)
150 WvDynBuf writeoutbuf;
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 flush(time_t msec_timeout)=0
flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a ti...
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 unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
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 isok() const
Returns true if the encoder has not encountered an error.
WvString geterror() const
Returns an error message if any is available.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual void close()
Close this stream.
WvStreamClone(IWvStream *_cloned=NULL)
Constructs the stream, then calls setclone(_cloned).
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().
virtual bool isok() const
return true if the stream is actually usable right now
WvStream()
Basic constructor for just a do-nothing WvStream.
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().