Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

WvStream Class Reference

#include <wvstream.h>

Inheritance diagram for WvStream:

WvDailyEvent WvDailyEvent WvFile WvFile WvLog WvLog WvLogConsole WvLogConsole WvPipe WvPipe WvSplitStream WvSplitStream WvStreamClone WvStreamClone WvStreamList WvStreamList WvTCPConn WvTCPConn WvTCPListener WvTCPListener WvTimeStream WvTimeStream WvUDPStream WvUDPStream WvUnixConn WvUnixConn WvUnixListener WvUnixListener List of all members.

Public Methods

 WvStream (int _fd)
virtual ~WvStream ()
 WvStream (const WvStream &s)
WvStream & operator= (const WvStream &s)
virtual void close ()
virtual int getrfd () const
virtual int getwfd () const
int getfd () const
virtual bool isok () const
virtual int geterr () const
virtual const char * errstr () const
size_t read (void *buf, size_t count)
size_t write (const void *buf, size_t count)
void outbuf_limit (size_t size)
virtual size_t uread (void *buf, size_t count)
virtual size_t uwrite (const void *buf, size_t count)
char * getline (time_t wait_msec, char separator='\n')
void queuemin (size_t count)
void drain ()
void delay_output (bool is_delayed)
void flush (time_t msec_timeout)
void flush_then_close (int msec_timeout)
virtual bool pre_select (SelectInfo &si)
bool pre_select (SelectInfo &si, const SelectRequest &r)
virtual bool post_select (SelectInfo &si)
bool post_select (SelectInfo &si, const SelectRequest &r)
bool select (time_t msec_timeout)
bool select (time_t msec_timeout, bool readable, bool writable, bool isex=false)
void force_select (bool readable, bool writable, bool isexception=false)
void undo_force_select (bool readable, bool writable, bool isexception=false)
bool continue_select (time_t msec_timeout)
void terminate_continue_select ()
virtual const WvAddrsrc () const
void setcallback (WvStreamCallback _callfunc, void *_userdata)
void autoforward (WvStream &s)
void callback ()
void alarm (time_t msec_timeout)
time_t alarm_remaining ()
size_t write (const WvString &s)
size_t print (const WvString &s)
size_t print (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
size_t operator() (const WvString &s)
size_t operator() (const WvString &__wvs_format, const WvString &__wvs_a0, const WvString &__wvs_a1=__wvs_n, const WvString &__wvs_a2=__wvs_n, const WvString &__wvs_a3=__wvs_n, const WvString &__wvs_a4=__wvs_n, const WvString &__wvs_a5=__wvs_n, const WvString &__wvs_a6=__wvs_n, const WvString &__wvs_a7=__wvs_n, const WvString &__wvs_a8=__wvs_n, const WvString &__wvs_a9=__wvs_n, const WvString &__wvs_a10=__wvs_n, const WvString &__wvs_a11=__wvs_n, const WvString &__wvs_a12=__wvs_n, const WvString &__wvs_a13=__wvs_n, const WvString &__wvs_a14=__wvs_n, const WvString &__wvs_a15=__wvs_n, const WvString &__wvs_a16=__wvs_n, const WvString &__wvs_a17=__wvs_n, const WvString &__wvs_a18=__wvs_n, const WvString &__wvs_a19=__wvs_n)
 WvStream (int _fd)
virtual ~WvStream ()
 WvStream (const WvStream &s)
WvStream & operator= (const WvStream &s)
virtual void close ()
virtual int getrfd () const
virtual int getwfd () const
int getfd () const
virtual bool isok () const
virtual int geterr () const
virtual const char * errstr () const
size_t read (void *buf, size_t count)
size_t write (const void *buf, size_t count)
void outbuf_limit (size_t size)
virtual size_t uread (void *buf, size_t count)
virtual size_t uwrite (const void *buf, size_t count)
char * getline (time_t wait_msec, char separator='\n')
void queuemin (size_t count)
void drain ()
void delay_output (bool is_delayed)
void flush (time_t msec_timeout)
void flush_then_close (int msec_timeout)
virtual bool pre_select (SelectInfo &si)
bool pre_select (SelectInfo &si, const SelectRequest &r)
virtual bool post_select (SelectInfo &si)
bool post_select (SelectInfo &si, const SelectRequest &r)
bool select (time_t msec_timeout)
bool select (time_t msec_timeout, bool readable, bool writable, bool isex=false)
void force_select (bool readable, bool writable, bool isexception=false)
void undo_force_select (bool readable, bool writable, bool isexception=false)
bool continue_select (time_t msec_timeout)
void terminate_continue_select ()
virtual const WvAddrsrc () const
void setcallback (WvStreamCallback _callfunc, void *_userdata)
void autoforward (WvStream &s)
void callback ()
void alarm (time_t msec_timeout)
time_t alarm_remaining ()
size_t write (const WvString &s)
size_t print (const WvString &s)
size_t print (WVSTRING_FORMAT_DECL)
size_t operator() (const WvString &s)
size_t operator() (WVSTRING_FORMAT_DECL)

Static Public Methods

void autoforward_callback (WvStream &s, void *userdata)
void autoforward_callback (WvStream &s, void *userdata)

Public Attributes

SelectRequest force
WvStream * read_requires_writable
WvStream * write_requires_readable
bool uses_continue_select
size_t personal_stack_size
WvStream * read_requires_writable
WvStream * write_requires_readable

Protected Methods

 WvStream ()
void seterr (int _errnum)
void seterr (const WvString &specialerr)
virtual void execute ()
 WvStream ()
void seterr (int _errnum)
void seterr (const WvString &specialerr)
virtual void execute ()

Static Protected Methods

void _callback (void *stream)
void _callback (void *stream)

Protected Attributes

WvStreamCallback callfunc
void * userdata
int rwfd
int errnum
WvString errstring
WvBuffer inbuf
WvBuffer outbuf
size_t max_outbuf_size
bool outbuf_delayed_flush
bool alarm_was_ticking
size_t queue_min
time_t autoclose_time
timeval alarm_time
bool running_callback
WvTasktask
void * userdata
timeval alarm_time
WvTasktask

Static Protected Attributes

WvTaskMantaskman
WvTaskMantaskman

Private Methods

void init ()
bool _select (time_t msec_timeout, bool readable, bool writable, bool isexcept, bool forceable)
void init ()
bool _select (time_t msec_timeout, bool readable, bool writable, bool isexcept, bool forceable)

Private Attributes

bool wvstream_execute_called

Detailed Description

Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write at any given time.

We provide typical read and write routines, as well as a select() function for each stream.

Definition at line 30 of file include/wvstream.h.


Constructor & Destructor Documentation

WvStream::WvStream int    _fd
 

constructor to create a WvStream from an existing file descriptor. The file descriptor is closed automatically by the destructor. If this is undesirable, duplicate it first using dup().

Definition at line 35 of file wvstream.cc.

References init, and rwfd.

WvStream::~WvStream   [virtual]
 

Definition at line 64 of file wvstream.cc.

References close, WvTask::isrunning, WvTask::recycle, WvTaskMan::run, running_callback, task, taskman, and TRACE.

WvStream::WvStream const WvStream &    s
 

copy constructor - not actually defined anywhere. This prevents people from accidentally trying to copy a WvStream without defining one.

WvStream::WvStream   [inline, protected]
 

plain internal constructor to just set up internal variables.

Definition at line 463 of file include/wvstream.h.

References init, and rwfd.

WvStream::WvStream int    _fd
 

constructor to create a WvStream from an existing file descriptor. The file descriptor is closed automatically by the destructor. If this is undesirable, duplicate it first using dup().

virtual WvStream::~WvStream   [virtual]
 

WvStream::WvStream const WvStream &    s
 

copy constructor - not actually defined anywhere. This prevents people from accidentally trying to copy a WvStream without defining one.

WvStream::WvStream   [inline, protected]
 

plain internal constructor to just set up internal variables.

Definition at line 463 of file streams/wvstream.h.

References init, and rwfd.


Member Function Documentation

void WvStream::_callback void *    stream [static, protected]
 

actually do the callback for an arbitrary stream. This is a static function so we can pass it as a function pointer to WvTask functions.

void WvStream::_callback void *    stream [static, protected]
 

actually do the callback for an arbitrary stream. This is a static function so we can pass it as a function pointer to WvTask functions.

Definition at line 113 of file wvstream.cc.

References callfunc, execute, running_callback, userdata, and wvstream_execute_called.

Referenced by callback.

bool WvStream::_select time_t    msec_timeout,
bool    readable,
bool    writable,
bool    isexcept,
bool    forceable
[private]
 

The function that does the actual work of select().

bool WvStream::_select time_t    msec_timeout,
bool    readable,
bool    writable,
bool    isexcept,
bool    forceable
[private]
 

The function that does the actual work of select().

Definition at line 586 of file wvstream.cc.

References force, isok, post_select, pre_select, WvStream::SelectRequest::readable, and seterr.

Referenced by select.

void WvStream::alarm time_t    msec_timeout
 

set an alarm, ie. select() will return true after this many ms. The alarm is cleared when callback() is called.

void WvStream::alarm time_t    msec_timeout
 

set an alarm, ie. select() will return true after this many ms. The alarm is cleared when callback() is called.

Definition at line 660 of file wvstream.cc.

References alarm_time, and normalize.

Referenced by continue_select.

time_t WvStream::alarm_remaining  
 

return the number of milliseconds remaining before the alarm will go off; -1 means no alarm is set (infinity), 0 means the alarm has been hit and will be cleared by the next callback().

time_t WvStream::alarm_remaining  
 

return the number of milliseconds remaining before the alarm will go off; -1 means no alarm is set (infinity), 0 means the alarm has been hit and will be cleared by the next callback().

Definition at line 679 of file wvstream.cc.

References alarm_time, and normalize.

Referenced by callback, WvStreamList::pre_select, WvStreamClone::pre_select, and pre_select.

void WvStream::autoforward WvStream &    s [inline]
 

set the callback function for this stream to an internal routine that auto-forwards all incoming stream data to the given output stream.

Definition at line 391 of file streams/wvstream.h.

References autoforward_callback, and setcallback.

void WvStream::autoforward WvStream &    s [inline]
 

set the callback function for this stream to an internal routine that auto-forwards all incoming stream data to the given output stream.

Definition at line 391 of file include/wvstream.h.

References autoforward_callback, and setcallback.

Referenced by main.

void WvStream::autoforward_callback WvStream &    s,
void *    userdata
[static]
 

void WvStream::autoforward_callback WvStream &    s,
void *    userdata
[static]
 

Definition at line 99 of file wvstream.cc.

References read, userdata, and write.

Referenced by autoforward.

void WvStream::callback  
 

if the stream has a callback function defined, call it now. otherwise call execute().

void WvStream::callback  
 

if the stream has a callback function defined, call it now. otherwise call execute().

Definition at line 135 of file wvstream.cc.

References _callback, alarm_remaining, alarm_time, alarm_was_ticking, WvTask::isrunning, personal_stack_size, WvTaskMan::run, running_callback, WvTask::start, WvTaskMan::start, task, taskman, TRACE, and uses_continue_select.

Referenced by WvStreamList::execute, WvStreamClone::execute, and main.

virtual void WvStream::close   [virtual]
 

Close the stream if it is open; isok() becomes false from now on. Note!! If you override this function in a derived class, you must call it yourself from your destructor. WvStream::~WvStream() can only call WvStream::close() because of the way virtual functions work in C++.

Reimplemented in WvSSLStream.

void WvStream::close   [virtual]
 

Close the stream if it is open; isok() becomes false from now on. Note!! If you override this function in a derived class, you must call it yourself from your destructor. WvStream::~WvStream() can only call WvStream::close() because of the way virtual functions work in C++.

Reimplemented in WvSSLStream.

Definition at line 86 of file wvstream.cc.

References flush, getrfd, getwfd, and rwfd.

Referenced by WvUnixListener::close, WvTCPListener::close, WvStreamClone::close, WvSplitStream::close, WvModem::close, flush, WvLockFile::lock, WvFileWatcher::make_ok, WvFile::open, seterr, terminate_continue_select, WvFileWatcher::WvFileWatcher, WvPipe::~WvPipe, ~WvStream, and WvUnixConn::~WvUnixConn.

bool WvStream::continue_select time_t    msec_timeout
 

bool WvStream::continue_select time_t    msec_timeout
 

Definition at line 712 of file wvstream.cc.

References alarm, alarm_was_ticking, running_callback, select, task, taskman, uses_continue_select, WvTaskMan::whoami, and WvTaskMan::yield.

Referenced by getline.

void WvStream::delay_output bool    is_delayed [inline]
 

force write() to always buffer output. This can be more efficient if you write a lot of small segments and want to "coagulate" them automatically. To flush the output buffer, use flush() or select().

Definition at line 161 of file streams/wvstream.h.

References outbuf_delayed_flush.

void WvStream::delay_output bool    is_delayed [inline]
 

force write() to always buffer output. This can be more efficient if you write a lot of small segments and want to "coagulate" them automatically. To flush the output buffer, use flush() or select().

Definition at line 161 of file include/wvstream.h.

References outbuf_delayed_flush.

Referenced by bouncer.

void WvStream::drain  
 

drain the input buffer (read and discard data until select(0) returns false)

void WvStream::drain  
 

drain the input buffer (read and discard data until select(0) returns false)

Definition at line 449 of file wvstream.cc.

References read, and select.

Referenced by WvModemBase::hangup, and WvModem::setup_modem.

virtual const char* WvStream::errstr   const [virtual]
 

Reimplemented in WvHTTPStream.

const char * WvStream::errstr   const [virtual]
 

Reimplemented in WvHTTPStream.

Definition at line 277 of file wvstream.cc.

References errnum, and errstring.

Referenced by WvStreamClone::errstr, WvConf::load_file, and main.

virtual void WvStream::execute   [protected, virtual]
 

The callback() function calls execute(), and then calls the user- specified callback if one is defined. Do not call execute() directly; call callback() instead.

The default execute() function does nothing.

Note: If you override this function in a derived class, you must call the parent execute() yourself from the derived class.

Reimplemented in WvDailyEvent.

void WvStream::execute   [protected, virtual]
 

The callback() function calls execute(), and then calls the user- specified callback if one is defined. Do not call execute() directly; call callback() instead.

The default execute() function does nothing.

Note: If you override this function in a derived class, you must call the parent execute() yourself from the derived class.

Reimplemented in WvDailyEvent.

Definition at line 217 of file wvstream.cc.

References wvstream_execute_called.

Referenced by _callback, WvTimeStream::execute, WvStreamList::execute, WvStreamClone::execute, and WvDailyEvent::execute.

void WvStream::flush time_t    msec_timeout
 

flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a time. (-1 means wait forever)

void WvStream::flush time_t    msec_timeout
 

flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a time. (-1 means wait forever)

Definition at line 457 of file wvstream.cc.

References autoclose_time, close, WvBuffer::get, isok, outbuf, select, TRACE, WvBuffer::unget, WvBuffer::used, and uwrite.

Referenced by close, flush_then_close, WvStreamClone::post_select, post_select, and write.

void WvStream::flush_then_close int    msec_timeout
 

flush the output buffer automatically as select() is called. If the buffer empties, close the stream. If msec_timeout seconds pass, close the stream. After the stream closes, it will become !isok() (and a WvStreamList can delete it automatically)

void WvStream::flush_then_close int    msec_timeout
 

flush the output buffer automatically as select() is called. If the buffer empties, close the stream. If msec_timeout seconds pass, close the stream. After the stream closes, it will become !isok() (and a WvStreamList can delete it automatically)

Definition at line 497 of file wvstream.cc.

References autoclose_time, flush, outbuf, TRACE, and WvBuffer::used.

void WvStream::force_select bool    readable,
bool    writable,
bool    isexception = false
 

Use force_select() to force one or more particular modes (readable, writable, or isexception) to true when selecting on this stream.

If an option is set 'true', we will select on that option when someone does a select(). If it's set 'false', we don't change its force status. (To de-force something, use undo_force_select().)

void WvStream::force_select bool    readable,
bool    writable,
bool    isexception = false
 

Use force_select() to force one or more particular modes (readable, writable, or isexception) to true when selecting on this stream.

If an option is set 'true', we will select on that option when someone does a select(). If it's set 'false', we don't change its force status. (To de-force something, use undo_force_select().)

Definition at line 644 of file wvstream.cc.

References force, WvStream::SelectRequest::isexception, WvStream::SelectRequest::readable, and WvStream::SelectRequest::writable.

Referenced by WvSSLStream::WvSSLStream, and WvStreamClone::WvStreamClone.

virtual int WvStream::geterr   const [virtual]
 

if isok() is false, return the system error number corresponding to the error, -1 for a special error string (which you can obtain with errstr()) or 0 on end of file. If isok() is true, returns an undefined number.

Reimplemented in WvHTTPStream.

int WvStream::geterr   const [virtual]
 

if isok() is false, return the system error number corresponding to the error, -1 for a special error string (which you can obtain with errstr()) or 0 on end of file. If isok() is true, returns an undefined number.

Reimplemented in WvHTTPStream.

Definition at line 271 of file wvstream.cc.

References errnum.

Referenced by WvStreamClone::geterr, WvConf::load_file, and WvHTTPStream::pre_select.

int WvStream::getfd   const
 

return the rfd _and_ the wfd... if they're the same.

int WvStream::getfd   const
 

return the rfd _and_ the wfd... if they're the same.

Definition at line 238 of file wvstream.cc.

References getrfd, and getwfd.

Referenced by WvUnixListener::accept, WvTCPListener::accept, WvTCPConn::do_connect, WvUDPStream::enable_broadcasts, WvTCPConn::localaddr, WvTCPConn::low_delay, WvTCPConn::nice_tcpopts, WvTCPConn::post_select, WvUDPStream::uread, WvUDPStream::uwrite, WvTCPConn::WvTCPConn, WvTCPListener::WvTCPListener, WvUDPStream::WvUDPStream, WvUnixConn::WvUnixConn, and WvUnixListener::WvUnixListener.

char* WvStream::getline time_t    wait_msec,
char    separator = '\n'
 

read up to one line of data from the stream and return a pointer to the internal buffer containing this line. If the end-of-line
is encountered, it is removed from the string. If wait_msec times out before the end of line is found, returns NULL and the line may be returned later.

If wait_msec < 0, waits forever for a newline (bad idea!) If wait_msec=0, never waits. Otherwise, waits up to wait_msec milliseconds until a newline appears.

This now uses the dynamic-sized WvBuffer. It is expected that there will be no NULL characters on the line.

char * WvStream::getline time_t    wait_msec,
char    separator = '\n'
 

read up to one line of data from the stream and return a pointer to the internal buffer containing this line. If the end-of-line
is encountered, it is removed from the string. If wait_msec times out before the end of line is found, returns NULL and the line may be returned later.

If wait_msec < 0, waits forever for a newline (bad idea!) If wait_msec=0, never waits. Otherwise, waits up to wait_msec milliseconds until a newline appears.

This now uses the dynamic-sized WvBuffer. It is expected that there will be no NULL characters on the line.

Definition at line 388 of file wvstream.cc.

References WvBuffer::alloc, continue_select, WvBuffer::get, inbuf, isok, queuemin, select, WvBuffer::strchr, WvBuffer::unalloc, uread, and WvBuffer::used.

Referenced by concallback, WvProtoStream::execute, WvResolver::findaddr, WvIPRouteList::get_kernel, WvConf::load_file, WvLockFile::lock, main, mycallback, WvInterfaceDict::update, and WvHTTPStream::uread.

virtual int WvStream::getrfd   const [virtual]
 

return the Unix file descriptor for reading from this stream

Reimplemented in WvSplitStream.

int WvStream::getrfd   const [virtual]
 

return the Unix file descriptor for reading from this stream

Reimplemented in WvSplitStream.

Definition at line 225 of file wvstream.cc.

References rwfd.

Referenced by close, WvModem::close, WvModemBase::get_real_speed, getfd, WvStreamClone::getrfd, WvModem::getstatus, WvModemBase::hangup, isok, WvFileWatcher::make_ok, post_select, WvFileWatcher::pre_select, pre_select, WvModem::setup_modem, WvModem::speed, uread, and WvPipe::WvPipe.

virtual int WvStream::getwfd   const [virtual]
 

return the Unix file descriptor for writing to this stream

Reimplemented in WvSplitStream.

int WvStream::getwfd   const [virtual]
 

return the Unix file descriptor for writing to this stream

Reimplemented in WvSplitStream.

Definition at line 232 of file wvstream.cc.

References rwfd.

Referenced by close, getfd, WvStreamClone::getwfd, isok, post_select, pre_select, uwrite, and WvPipe::WvPipe.

void WvStream::init   [private]
 

void WvStream::init   [private]
 

Definition at line 42 of file wvstream.cc.

References alarm_time, alarm_was_ticking, autoclose_time, errnum, force, WvStream::SelectRequest::isexception, max_outbuf_size, outbuf_delayed_flush, personal_stack_size, queue_min, read_requires_writable, WvStream::SelectRequest::readable, running_callback, task, userdata, uses_continue_select, WvStream::SelectRequest::writable, write_requires_readable, and wvstream_execute_called.

Referenced by WvStream.

virtual bool WvStream::isok   const [virtual]
 

return true if the stream is actually usable right now

Reimplemented in WvDailyEvent.

bool WvStream::isok   const [virtual]
 

return true if the stream is actually usable right now

Reimplemented in WvDailyEvent.

Definition at line 246 of file wvstream.cc.

References getrfd, and getwfd.

Referenced by _select, bouncer, WvModem::close, WvUDPStream::enable_broadcasts, WvResolver::findaddr, flush, WvIPRouteList::get_kernel, WvModemBase::get_real_speed, getline, WvModem::getstatus, WvModemBase::hangup, WvTCPConn::isok, WvStreamClone::isok, WvConf::load_file, WvLockFile::lock, main, WvFileWatcher::make_ok, WvStreamList::post_select, WvStreamClone::post_select, post_select, WvSSLStream::post_select, WvStreamList::pre_select, WvStreamClone::pre_select, WvConf::save, WvModem::setup_modem, WvUDPStream::uread, uread, WvUDPStream::uwrite, uwrite, write, WvFileWatcher::WvFileWatcher, and WvModem::WvModem.

size_t WvStream::operator() WVSTRING_FORMAT_DECL    [inline]
 

Reimplemented in WvLog.

Definition at line 430 of file streams/wvstream.h.

References write.

size_t WvStream::operator() const WvString   s [inline]
 

Reimplemented in WvLog.

Definition at line 428 of file streams/wvstream.h.

References write.

size_t WvStream::operator() const WvString   __wvs_format,
const WvString   __wvs_a0,
const WvString   __wvs_a1 = __wvs_n,
const WvString   __wvs_a2 = __wvs_n,
const WvString   __wvs_a3 = __wvs_n,
const WvString   __wvs_a4 = __wvs_n,
const WvString   __wvs_a5 = __wvs_n,
const WvString   __wvs_a6 = __wvs_n,
const WvString   __wvs_a7 = __wvs_n,
const WvString   __wvs_a8 = __wvs_n,
const WvString   __wvs_a9 = __wvs_n,
const WvString   __wvs_a10 = __wvs_n,
const WvString   __wvs_a11 = __wvs_n,
const WvString   __wvs_a12 = __wvs_n,
const WvString   __wvs_a13 = __wvs_n,
const WvString   __wvs_a14 = __wvs_n,
const WvString   __wvs_a15 = __wvs_n,
const WvString   __wvs_a16 = __wvs_n,
const WvString   __wvs_a17 = __wvs_n,
const WvString   __wvs_a18 = __wvs_n,
const WvString   __wvs_a19 = __wvs_n
[inline]
 

Reimplemented in WvLog.

Definition at line 430 of file include/wvstream.h.

References write.

size_t WvStream::operator() const WvString   s [inline]
 

Reimplemented in WvLog.

Definition at line 428 of file include/wvstream.h.

References write.

Referenced by WvLog::operator().

WvStream& WvStream::operator= const WvStream &    s
 

WvStream& WvStream::operator= const WvStream &    s
 

void WvStream::outbuf_limit size_t    size [inline]
 

set the maximum size of outbuf, beyond which a call to write() will return 0. I need to do this for tape backups, since all I can do is write to the loopback as fast as I can, which causes us to run out of memory and get SIGABRT'd. (DLC: 12/15/2000)

Definition at line 102 of file streams/wvstream.h.

References max_outbuf_size, and size.

void WvStream::outbuf_limit size_t    size [inline]
 

set the maximum size of outbuf, beyond which a call to write() will return 0. I need to do this for tape backups, since all I can do is write to the loopback as fast as I can, which causes us to run out of memory and get SIGABRT'd. (DLC: 12/15/2000)

Definition at line 102 of file include/wvstream.h.

References max_outbuf_size, and size.

bool WvStream::post_select SelectInfo   si,
const SelectRequest   r
[inline]
 

A more convenient version of post_select() usable for overriding the 'want' value temporarily.

Definition at line 280 of file streams/wvstream.h.

References post_select.

virtual bool WvStream::post_select SelectInfo   si [virtual]
 

post_select() is called after select(), and returns true if this object is now ready. Usually this is done by checking for this object in the read, write, and except lists in the SelectInfo structure. If you want to do it in some other way, you should usually do it in pre_select() instead. (post_select() _only_ gets called if select() returned true for _some_ stream or another.)

You may also want to do extra maintenance functions here; for example, the standard WvStream::post_select tries to flush outbuf if it's nonempty. WvTCPConn might retry connect() if it's waiting for a connection to be established.

Reimplemented in WvSSLStream.

bool WvStream::post_select SelectInfo   si,
const SelectRequest   r
[inline]
 

A more convenient version of post_select() usable for overriding the 'want' value temporarily.

Definition at line 280 of file include/wvstream.h.

References post_select.

bool WvStream::post_select SelectInfo   si [virtual]
 

post_select() is called after select(), and returns true if this object is now ready. Usually this is done by checking for this object in the read, write, and except lists in the SelectInfo structure. If you want to do it in some other way, you should usually do it in pre_select() instead. (post_select() _only_ gets called if select() returned true for _some_ stream or another.)

You may also want to do extra maintenance functions here; for example, the standard WvStream::post_select tries to flush outbuf if it's nonempty. WvTCPConn might retry connect() if it's waiting for a connection to be established.

Reimplemented in WvSSLStream.

Definition at line 553 of file wvstream.cc.

References autoclose_time, flush, getrfd, getwfd, isok, outbuf, read_requires_writable, select, WvBuffer::used, and write_requires_readable.

Referenced by _select, WvTCPConn::post_select, WvStreamList::post_select, WvStreamClone::post_select, and post_select.

bool WvStream::pre_select SelectInfo   si,
const SelectRequest   r
[inline]
 

A more convenient version of pre_select() usable for overriding the 'want' value temporarily.

Definition at line 252 of file streams/wvstream.h.

References pre_select.

virtual bool WvStream::pre_select SelectInfo   si [virtual]
 

pre_select() sets up for eventually calling select(). It adds the right fds to the read, write, and except lists in the SelectInfo struct.

Returns true if we already know this stream is ready, and there's no need to actually do a real select(). Some streams, such as timers, can be implemented by _only_ either returning true or false here after doing a calculation, and never actually adding anything to the SelectInfo.

You can add your stream to any of the lists even if readable, writable, or isexception isn't set. This is what force_select() does. You can also choose not to add yourself to the list if you know it would be useless right now.

pre_select() is only called if isok() is true.

pre_select() is allowed to reduce msec_timeout (or change it if it's -1). However, it's not allowed to _increase_ msec_timeout.

Reimplemented in WvSSLStream.

bool WvStream::pre_select SelectInfo   si,
const SelectRequest   r
[inline]
 

A more convenient version of pre_select() usable for overriding the 'want' value temporarily.

Definition at line 252 of file include/wvstream.h.

References pre_select.

bool WvStream::pre_select SelectInfo   si [virtual]
 

pre_select() sets up for eventually calling select(). It adds the right fds to the read, write, and except lists in the SelectInfo struct.

Returns true if we already know this stream is ready, and there's no need to actually do a real select(). Some streams, such as timers, can be implemented by _only_ either returning true or false here after doing a calculation, and never actually adding anything to the SelectInfo.

You can add your stream to any of the lists even if readable, writable, or isexception isn't set. This is what force_select() does. You can also choose not to add yourself to the list if you know it would be useless right now.

pre_select() is only called if isok() is true.

pre_select() is allowed to reduce msec_timeout (or change it if it's -1). However, it's not allowed to _increase_ msec_timeout.

Reimplemented in WvSSLStream.

Definition at line 514 of file wvstream.cc.

References alarm_remaining, autoclose_time, getrfd, getwfd, inbuf, outbuf, queue_min, and WvBuffer::used.

Referenced by _select, WvTCPConn::pre_select, WvStreamList::pre_select, WvStreamClone::pre_select, pre_select, and WvResolver::pre_select.

size_t WvStream::print WVSTRING_FORMAT_DECL    [inline]
 

preformat and print a string.

Definition at line 426 of file streams/wvstream.h.

References write.

size_t WvStream::print const WvString   s [inline]
 

Definition at line 420 of file streams/wvstream.h.

References write.

size_t WvStream::print const WvString   __wvs_format,
const WvString   __wvs_a0,
const WvString   __wvs_a1 = __wvs_n,
const WvString   __wvs_a2 = __wvs_n,
const WvString   __wvs_a3 = __wvs_n,
const WvString   __wvs_a4 = __wvs_n,
const WvString   __wvs_a5 = __wvs_n,
const WvString   __wvs_a6 = __wvs_n,
const WvString   __wvs_a7 = __wvs_n,
const WvString   __wvs_a8 = __wvs_n,
const WvString   __wvs_a9 = __wvs_n,
const WvString   __wvs_a10 = __wvs_n,
const WvString   __wvs_a11 = __wvs_n,
const WvString   __wvs_a12 = __wvs_n,
const WvString   __wvs_a13 = __wvs_n,
const WvString   __wvs_a14 = __wvs_n,
const WvString   __wvs_a15 = __wvs_n,
const WvString   __wvs_a16 = __wvs_n,
const WvString   __wvs_a17 = __wvs_n,
const WvString   __wvs_a18 = __wvs_n,
const WvString   __wvs_a19 = __wvs_n
[inline]
 

preformat and print a string.

Definition at line 426 of file include/wvstream.h.

References write.

size_t WvStream::print const WvString   s [inline]
 

Definition at line 420 of file include/wvstream.h.

References write.

Referenced by concallback, WvLogBuffer::dump, WvHConf::dump, WvConfigSection::dump, WvLockFile::lock, main, mycallback, namelookup, WvLog::operator(), WvLog::perror, WvHTTPStream::pre_select, and WvConf::save.

void WvStream::queuemin size_t    count [inline]
 

force read() to not return any bytes unless 'count' bytes can be read at once. (Useful for processing Content-Length headers, etc.) Use count==0 to disable this feature.

queuemin() mainly affects what happens when you do a read(), not so much what happens when you do a select(). If you set queuemin != 0, you might still select true for read, but read() might return 0 bytes since it's holding back data until enough bytes are ready in inbuf.

WARNING: getline() sets queuemin to 0 automatically!

Definition at line 147 of file streams/wvstream.h.

References queue_min.

void WvStream::queuemin size_t    count [inline]
 

force read() to not return any bytes unless 'count' bytes can be read at once. (Useful for processing Content-Length headers, etc.) Use count==0 to disable this feature.

queuemin() mainly affects what happens when you do a read(), not so much what happens when you do a select(). If you set queuemin != 0, you might still select true for read, but read() might return 0 bytes since it's holding back data until enough bytes are ready in inbuf.

WARNING: getline() sets queuemin to 0 automatically!

Definition at line 147 of file include/wvstream.h.

References queue_min.

Referenced by getline, WvRSAStream::WvRSAStream, and WvRSAStream::~WvRSAStream.

size_t WvStream::read void *    buf,
size_t    count
 

read a data block on the stream. Returns the actual amount read.

size_t WvStream::read void *    buf,
size_t    count
 

read a data block on the stream. Returns the actual amount read.

Definition at line 289 of file wvstream.cc.

References WvBuffer::alloc, WvBuffer::get, inbuf, queue_min, TRACE, WvBuffer::unalloc, uread, and WvBuffer::used.

Referenced by autoforward_callback, bouncer, drain, WvStreamClone::uread, and WvHTTPStream::uread.

bool WvStream::select time_t    msec_timeout,
bool    readable,
bool    writable,
bool    isex = false
[inline]
 

This version of select() sets forceable==false, so we use the exact readable/writable/isexception options provided.

You normally use this variant of select() when deciding whether you should read/write a particular stream. For example:

if (stream.select(1000, true, false)) len = stream.read(buf, sizeof(buf));

This variant of select() is probably not what you want with most WvStreamLists, unless you know exactly what you're doing.

Definition at line 324 of file streams/wvstream.h.

References _select.

bool WvStream::select time_t    msec_timeout [inline]
 

Return true if any of the requested features are true on the stream. If msec_timeout < 0, waits forever (bad idea!). ==0, does not wait. Otherwise, waits for up to msec_timeout milliseconds.

**NOTE** select() is _not_ virtual! To change the select() behaviour of a stream, override the pre_select() and/or post_select() functions.

This version of select() sets forceable==true, so force_select options are taken into account.

You almost always use this version of select() with callbacks, like this: if (stream.select(1000)) stream.callback();

If you want to read/write the stream in question, try using the other variant of select().

Definition at line 308 of file streams/wvstream.h.

References _select.

bool WvStream::select time_t    msec_timeout,
bool    readable,
bool    writable,
bool    isex = false
[inline]
 

This version of select() sets forceable==false, so we use the exact readable/writable/isexception options provided.

You normally use this variant of select() when deciding whether you should read/write a particular stream. For example:

if (stream.select(1000, true, false)) len = stream.read(buf, sizeof(buf));

This variant of select() is probably not what you want with most WvStreamLists, unless you know exactly what you're doing.

Definition at line 324 of file include/wvstream.h.

References _select.

bool WvStream::select time_t    msec_timeout [inline]
 

Return true if any of the requested features are true on the stream. If msec_timeout < 0, waits forever (bad idea!). ==0, does not wait. Otherwise, waits for up to msec_timeout milliseconds.

**NOTE** select() is _not_ virtual! To change the select() behaviour of a stream, override the pre_select() and/or post_select() functions.

This version of select() sets forceable==true, so force_select options are taken into account.

You almost always use this version of select() with callbacks, like this: if (stream.select(1000)) stream.callback();

If you want to read/write the stream in question, try using the other variant of select().

Definition at line 308 of file include/wvstream.h.

References _select.

Referenced by continue_select, drain, WvResolver::findaddr, flush, getline, WvModemBase::hangup, main, WvStreamClone::post_select, post_select, WvHTTPStream::pre_select, and WvFileWatcher::uread.

void WvStream::setcallback WvStreamCallback    _callfunc,
void *    _userdata
[inline]
 

define the callback function for this stream, called whenever the callback() member is run, and passed the 'userdata' pointer.

Definition at line 383 of file streams/wvstream.h.

References callfunc, and userdata.

void WvStream::setcallback WvStreamCallback    _callfunc,
void *    _userdata
[inline]
 

define the callback function for this stream, called whenever the callback() member is run, and passed the 'userdata' pointer.

Definition at line 383 of file include/wvstream.h.

References callfunc, and userdata.

Referenced by WvUnixListener::accept_callback, WvTCPListener::accept_callback, WvUnixListener::auto_accept, WvTCPListener::auto_accept, autoforward, and main.

void WvStream::seterr const WvString   specialerr [protected]
 

void WvStream::seterr int    _errnum [protected]
 

set the errnum variable and close the stream -- we have an error.

void WvStream::seterr const WvString   specialerr [protected]
 

Definition at line 260 of file wvstream.cc.

References close, errnum, and errstring.

void WvStream::seterr int    _errnum [protected]
 

set the errnum variable and close the stream -- we have an error.

Definition at line 252 of file wvstream.cc.

References close, and errnum.

Referenced by _select, WvTCPConn::check_resolver, WvTCPConn::do_connect, WvFile::open, WvTCPConn::post_select, WvSSLStream::post_select, WvHTTPStream::pre_select, WvModem::setup_modem, uread, WvSSLStream::uread, WvHTTPStream::uread, WvUDPStream::uwrite, uwrite, WvSSLStream::uwrite, WvSSLStream::WvSSLStream, WvTCPConn::WvTCPConn, WvTCPListener::WvTCPListener, WvUDPStream::WvUDPStream, WvUnixConn::WvUnixConn, and WvUnixListener::WvUnixListener.

virtual const WvAddr* WvStream::src   const [virtual]
 

get the remote address from which the last data block was received. May be NULL. The pointer becomes invalid upon the next call to read().

Reimplemented in WvStreamClone.

const WvAddr * WvStream::src   const [virtual]
 

get the remote address from which the last data block was received. May be NULL. The pointer becomes invalid upon the next call to read().

Reimplemented in WvStreamClone.

Definition at line 749 of file wvstream.cc.

Referenced by WvStreamClone::src.

void WvStream::terminate_continue_select  
 

you MUST run this from your destructor if you use continue_select(), or very weird things will happen if someone deletes your object while in continue_select().

void WvStream::terminate_continue_select  
 

you MUST run this from your destructor if you use continue_select(), or very weird things will happen if someone deletes your object while in continue_select().

Definition at line 736 of file wvstream.cc.

References close, WvTask::isrunning, WvTask::recycle, WvTaskMan::run, task, and taskman.

void WvStream::undo_force_select bool    readable,
bool    writable,
bool    isexception = false
 

Undo a previous force_select() - ie. un-forces the options which are 'true', and leaves the false ones alone.

void WvStream::undo_force_select bool    readable,
bool    writable,
bool    isexception = false
 

Undo a previous force_select() - ie. un-forces the options which are 'true', and leaves the false ones alone.

Definition at line 652 of file wvstream.cc.

References force, WvStream::SelectRequest::isexception, WvStream::SelectRequest::readable, and WvStream::SelectRequest::writable.

Referenced by WvSSLStream::post_select.

virtual size_t WvStream::uread void *    buf,
size_t    count
[virtual]
 

unbuffered I/O functions; these ignore the buffer, which is handled by read(). Don't call these functions unless you have a _really_ good reason.

Reimplemented in WvXORStream.

size_t WvStream::uread void *    buf,
size_t    count
[virtual]
 

unbuffered I/O functions; these ignore the buffer, which is handled by read(). Don't call these functions unless you have a _really_ good reason.

Reimplemented in WvXORStream.

Definition at line 324 of file wvstream.cc.

References getrfd, isok, and seterr.

Referenced by getline, read, and WvFileWatcher::uread.

virtual size_t WvStream::uwrite const void *    buf,
size_t    count
[virtual]
 

unbuffered I/O functions; these ignore the buffer, which is handled by write(). Don't call these functions unless you have a _really_ good reason.

Reimplemented in WvXORStream.

size_t WvStream::uwrite const void *    buf,
size_t    count
[virtual]
 

unbuffered I/O functions; these ignore the buffer, which is handled by write(). Don't call these functions unless you have a _really_ good reason.

Reimplemented in WvXORStream.

Definition at line 366 of file wvstream.cc.

References getwfd, isok, and seterr.

Referenced by WvLogConsole::_mid_line, flush, WvFileWatcher::uwrite, WvStreamClone::uwrite, and write.

size_t WvStream::write const WvString   s [inline]
 

print a preformatted WvString to the stream. see the simple version of write() way up above.

Definition at line 418 of file streams/wvstream.h.

References write.

size_t WvStream::write const void *    buf,
size_t    count
 

write a data block on the stream. Returns the actual amount written.

size_t WvStream::write const WvString   s [inline]
 

print a preformatted WvString to the stream. see the simple version of write() way up above.

Definition at line 418 of file include/wvstream.h.

References write.

size_t WvStream::write const void *    buf,
size_t    count
 

write a data block on the stream. Returns the actual amount written.

Definition at line 343 of file wvstream.cc.

References flush, isok, max_outbuf_size, outbuf, outbuf_delayed_flush, WvBuffer::put, WvBuffer::used, and uwrite.

Referenced by autoforward_callback, bouncer, WvModemBase::hangup, operator(), WvLog::operator(), print, WvModem::setup_modem, WvProtoStream::uwrite, and write.


Member Data Documentation

struct timeval WvStream::alarm_time [protected]
 

Definition at line 454 of file streams/wvstream.h.

struct timeval WvStream::alarm_time [protected]
 

Definition at line 454 of file include/wvstream.h.

Referenced by alarm, alarm_remaining, callback, and init.

bool WvStream::alarm_was_ticking [protected]
 

Definition at line 451 of file streams/wvstream.h.

Referenced by callback, continue_select, and init.

time_t WvStream::autoclose_time [protected]
 

Definition at line 453 of file streams/wvstream.h.

Referenced by flush, flush_then_close, init, WvStreamClone::post_select, post_select, WvStreamClone::pre_select, and pre_select.

WvStreamCallback WvStream::callfunc [protected]
 

Definition at line 445 of file streams/wvstream.h.

Referenced by _callback, and setcallback.

int WvStream::errnum [protected]
 

Definition at line 447 of file streams/wvstream.h.

Referenced by errstr, WvStreamClone::geterr, geterr, init, seterr, WvPipe::setup, WvFileWatcher::WvFileWatcher, WvLoopback::WvLoopback, and WvModem::WvModem.

WvString WvStream::errstring [protected]
 

Definition at line 448 of file streams/wvstream.h.

Referenced by errstr, and seterr.

SelectRequest WvStream::force
 

'force' is the list of default SelectRequest values when you use the variant of select() that doesn't override them.

Definition at line 199 of file streams/wvstream.h.

Referenced by _select, force_select, init, WvStreamList::post_select, WvStreamClone::post_select, WvStreamList::pre_select, WvStreamClone::pre_select, and undo_force_select.

WvBuffer WvStream::inbuf [protected]
 

Definition at line 449 of file streams/wvstream.h.

Referenced by getline, WvStreamClone::pre_select, pre_select, read, and WvRSAStream::uread.

size_t WvStream::max_outbuf_size [protected]
 

Definition at line 450 of file streams/wvstream.h.

Referenced by init, outbuf_limit, and write.

WvBuffer WvStream::outbuf [protected]
 

Definition at line 449 of file streams/wvstream.h.

Referenced by flush, flush_then_close, WvStreamClone::post_select, post_select, WvStreamClone::pre_select, pre_select, and write.

bool WvStream::outbuf_delayed_flush [protected]
 

Definition at line 451 of file streams/wvstream.h.

Referenced by delay_output, init, and write.

size_t WvStream::personal_stack_size
 

Definition at line 363 of file streams/wvstream.h.

Referenced by callback, and init.

size_t WvStream::queue_min [protected]
 

Definition at line 452 of file streams/wvstream.h.

Referenced by init, WvStreamClone::pre_select, pre_select, queuemin, and read.

WvStream* WvStream::read_requires_writable
 

If this is set, select() doesn't return true for read unless the given stream also returns true for write.

Definition at line 205 of file streams/wvstream.h.

WvStream* WvStream::read_requires_writable
 

If this is set, select() doesn't return true for read unless the given stream also returns true for write.

Definition at line 205 of file include/wvstream.h.

Referenced by init, WvStreamClone::post_select, and post_select.

bool WvStream::running_callback [protected]
 

Definition at line 455 of file streams/wvstream.h.

Referenced by _callback, callback, continue_select, init, and ~WvStream.

int WvStream::rwfd [protected]
 

Definition at line 447 of file streams/wvstream.h.

Referenced by close, WvTCPConn::do_connect, getrfd, getwfd, WvFile::open, WvPipe::setup, WvStream, WvTCPListener::WvTCPListener, WvUDPStream::WvUDPStream, WvUnixConn::WvUnixConn, and WvUnixListener::WvUnixListener.

WvTask* WvStream::task [protected]
 

Definition at line 458 of file streams/wvstream.h.

WvTask* WvStream::task [protected]
 

Definition at line 458 of file include/wvstream.h.

Referenced by callback, continue_select, init, terminate_continue_select, and ~WvStream.

WvTaskMan* WvStream::taskman [static, protected]
 

Definition at line 457 of file streams/wvstream.h.

WvTaskMan * WvStream::taskman [static, protected]
 

Definition at line 26 of file wvstream.cc.

Referenced by callback, continue_select, terminate_continue_select, and ~WvStream.

void* WvStream::userdata [protected]
 

Definition at line 446 of file streams/wvstream.h.

void* WvStream::userdata [protected]
 

Definition at line 446 of file include/wvstream.h.

Referenced by _callback, WvUnixListener::accept_callback, WvTCPListener::accept_callback, WvUnixListener::auto_accept, WvTCPListener::auto_accept, autoforward_callback, init, and setcallback.

bool WvStream::uses_continue_select
 

return to the caller from execute(), but don't really return exactly; this uses WvTaskMan::yield() to return to the caller of callback() without losing our place in execute() itself. So, next time someone calls callback(), it will be as if continue_select() returned.

NOTE: execute() will won't be called recursively this way, but any other member function might get called, or member variables changed, or the state of the world updated while continue_select() runs. Don't assume that nothing has changed after a call to continue_select().

NOTE 2: if you're going to call continue_select(), you should set uses_continue_select=true before the first call to callback(). Otherwise your WvTask struct won't get created.

NOTE 3: if msec_timeout >= 0, this uses WvStream::alarm().

Definition at line 362 of file streams/wvstream.h.

Referenced by callback, continue_select, and init.

WvStream* WvStream::write_requires_readable
 

If this is set, select() doesn't return true for write unless the given stream also returns true for read.

Definition at line 211 of file streams/wvstream.h.

WvStream* WvStream::write_requires_readable
 

If this is set, select() doesn't return true for write unless the given stream also returns true for read.

Definition at line 211 of file include/wvstream.h.

Referenced by init, WvStreamClone::post_select, and post_select.

bool WvStream::wvstream_execute_called [private]
 

Definition at line 435 of file streams/wvstream.h.

Referenced by _callback, execute, and init.


The documentation for this class was generated from the following files:
Generated on Sun Aug 25 02:29:46 2002 for WvStreams by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002