#include <wvtcp.h>
Inherits WvFDStream.
Collaboration diagram for WvTCPConn:
You can tell the connection has been established when a select() call returns 'true' with writable==true.
Definition at line 39 of file wvtcp.h.
Public Member Functions | |
WvTCPConn (const WvIPPortAddr &_remaddr) | |
WvTCPConn tries to make all outgoing connections asynchronously (in the background). | |
WvTCPConn (WvStringParm _hostname, __u16 _port=0) | |
Resolve the hostname, then connect a new socket. | |
virtual | ~WvTCPConn () |
Destructor - rarely do you need to call this - close() is a much better way to tear down a TCP Stream ;). | |
void | nice_tcpopts () |
function to set up a TCP socket the way we like (Read/Write, Non-Blocking, KeepAlive) | |
void | low_delay () |
function to set up a TCP socket the way we like In addition to the nice_tcpopts(), set TCP_NODELAY | |
void | debug_mode () |
function to set up a TCP socket the way we *don't* like: turn the timeouts way down so that network errors show up easily for debugging | |
WvIPPortAddr | localaddr () |
the local address of this socket (ie. | |
virtual const WvIPPortAddr * | src () const |
return the remote address (source of all incoming packets), which is a constant for any given TCP connection. | |
bool | isconnected () const |
has the connection been completed yet? | |
virtual bool | pre_select (SelectInfo &si) |
override pre_select() to cause select() results when resolving names. | |
virtual bool | post_select (SelectInfo &si) |
override post_select() to set the 'connected' variable as soon as we are connected. | |
virtual bool | isok () const |
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1. | |
int | getrfd () const |
Returns the Unix file descriptor for reading from this stream. | |
int | getwfd () const |
Returns the Unix file descriptor for writing to this stream. | |
int | getfd () const |
Returns the Unix file descriptor for reading and writing. | |
virtual void | close () |
Closes the file descriptors. | |
virtual size_t | uread (void *buf, size_t count) |
unbuffered I/O functions; these ignore the buffer, which is handled by read(). | |
bool | pre_select (SelectInfo &si, const SelectRequest &r) |
A more convenient version of pre_select() usable for overriding the 'want' value temporarily. | |
bool | post_select (SelectInfo &si, const SelectRequest &r) |
A more convenient version of post_select() usable for overriding the 'want' value temporarily. | |
virtual void | noread () |
Shuts down the reading side of the stream. | |
virtual void | nowrite () |
Shuts down the writing side of the stream. | |
virtual void | seterr (int _errnum) |
Override seterr() from WvError so that it auto-closes the stream. | |
void | seterr (WvStringParm specialerr) |
void | seterr (WVSTRING_FORMAT_DECL) |
void | seterr (const WvError &err) |
virtual size_t | read (void *buf, size_t count) |
read a data block on the stream. | |
virtual size_t | read (WvBuf &outbuf, size_t count) |
Reads up to 'count' bytes of data from the stream into the buffer. | |
virtual size_t | continue_read (time_t wait_msec, void *buf, size_t count) |
Read exactly count bytes from the stream. | |
virtual size_t | continue_read (time_t wait_msec, WvBuf &outbuf, size_t count) |
Read exactly count bytes from the stream, using continue_select(). | |
virtual void | unread (WvBuf &outbuf, size_t count) |
Puts data back into the stream's internal buffer. | |
virtual size_t | write (const void *buf, size_t count) |
Write data to the stream. | |
virtual size_t | write (WvBuf &inbuf, size_t count=INT_MAX) |
Writes data to the stream from the given buffer. | |
size_t | write (WvStringParm s) |
print a preformatted WvString to the stream. | |
void | outbuf_limit (size_t size) |
set the maximum size of outbuf, beyond which a call to write() will return 0. | |
virtual bool | isreadable () |
Returns true if the stream is readable. | |
virtual bool | iswritable () |
Returns true if the stream is writable (without using the outbuf). | |
char * | getline (time_t wait_msec, char separator= '\n', int readahead=1024) |
read up to one line of data from the stream and return a pointer to the internal buffer containing this line. | |
void | queuemin (size_t count) |
force read() to not return any bytes unless 'count' bytes can be read at once. | |
void | drain () |
drain the input buffer (read and discard data until select(0) returns false) | |
void | delay_output (bool is_delayed) |
force write() to always buffer output. | |
void | auto_flush (bool is_automatic) |
if true, force write() to call flush() each time, the default behavour. | |
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 time. | |
virtual bool | should_flush () |
Returns true if we want to flush the output buffer right now. | |
void | flush_then_close (int msec_timeout) |
flush the output buffer automatically as select() is called. | |
bool | xpre_select (SelectInfo &si, const SelectRequest &r) |
Like pre_select(), but still exists even if you override the other pre_select() in a subclass. | |
bool | xpost_select (SelectInfo &si, const SelectRequest &r) |
Like post_select(), but still exists even if you override the other post_select() in a subclass. | |
bool | select (time_t msec_timeout) |
Return true if any of the requested features are true on the stream. | |
bool | select (time_t msec_timeout, bool readable, bool writable, bool isex=false) |
This version of select() sets forceable==false, so we use the exact readable/writable/isexception options provided. | |
void | runonce (time_t msec_timeout=-1) |
Exactly the same as: if (select(timeout)) callback();. | |
void | 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. | |
void | undo_force_select (bool readable, bool writable, bool isexception=false) |
Undo a previous force_select() - ie. | |
bool | continue_select (time_t msec_timeout) |
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. | |
void | 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 | setcallback (WvStreamCallback _callfunc, void *_userdata) |
define the callback function for this stream, called whenever the callback() member is run, and passed the 'userdata' pointer. | |
void | setclosecallback (WvStreamCallback _callfunc, void *_userdata) |
Sets a callback to be invoked on close(). | |
void | autoforward (WvStream &s) |
set the callback function for this stream to an internal routine that auto-forwards all incoming stream data to the given output stream. | |
void | noautoforward () |
Stops autoforwarding. | |
virtual void | callback () |
if the stream has a callback function defined, call it now. | |
void | alarm (time_t msec_timeout) |
set an alarm, ie. | |
time_t | 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(). | |
size_t | print (WvStringParm s) |
size_t | print (WVSTRING_FORMAT_DECL) |
preformat and write() a string. | |
size_t | operator() (WvStringParm s) |
size_t | operator() (WVSTRING_FORMAT_DECL) |
virtual unsigned int | addRef () |
virtual unsigned int | release () |
virtual int | geterr () const |
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. | |
virtual WvString | errstr () const |
void | noerr () |
Reset our error state - there's no error condition anymore. | |
Static Public Member Functions | |
void | autoforward_callback (WvStream &s, void *userdata) |
Public Attributes | |
SelectRequest | force |
'force' is the list of default SelectRequest values when you use the variant of select() that doesn't override them. | |
WvStream * | read_requires_writable |
If this is set, select() doesn't return true for read unless the given stream also returns true for write. | |
WvStream * | write_requires_readable |
If this is set, select() doesn't return true for write unless the given stream also returns true for read. | |
bool | uses_continue_select |
If this is set, enables the use of continue_select(). | |
size_t | personal_stack_size |
Specifies the stack size to reserve for continue_select(). | |
bool | alarm_was_ticking |
This will be true during callback execution if the callback was triggered by the alarm going off. | |
Static Public Attributes | |
const XUUID | XIID |
Protected Member Functions | |
WvTCPConn (int _fd, const WvIPPortAddr &_remaddr) | |
Start a WvTCPConn on an already-open socket (used by WvTCPListener). | |
void | do_connect () |
Connect to the remote end - note the "Protected" above ;). | |
void | check_resolver () |
Resolve the remote address, if it was fed in non-IP form. | |
virtual size_t | uwrite (const void *buf, size_t count) |
unbuffered I/O functions; these ignore the buffer, which is handled by write(). | |
void | setfd (int fd) |
Sets the file descriptor for both reading and writing. | |
bool | _build_selectinfo (SelectInfo &si, time_t msec_timeout, bool readable, bool writable, bool isexcept, bool forceable) |
int | _do_select (SelectInfo &si) |
bool | _process_selectinfo (SelectInfo &si, bool forceable) |
bool | flush_outbuf (time_t msec_timeout) |
virtual bool | flush_internal (time_t msec_timeout) |
virtual void | execute () |
The callback() function calls execute(), and then calls the user- specified callback if one is defined. | |
Static Protected Member Functions | |
void | _callback (void *stream) |
actually do the callback for an arbitrary stream. | |
Protected Attributes | |
bool | resolved |
bool | connected |
WvString | hostname |
WvIPPortAddr | remaddr |
WvResolver | dns |
int | rfd |
The file descriptor for reading. | |
int | wfd |
The file descriptor for writing. | |
WvTaskMan * | taskman |
WvDynBuf | inbuf |
WvDynBuf | outbuf |
WvStreamCallback | callfunc |
WvStreamCallback | closecb_func |
void * | userdata |
void * | closecb_data |
size_t | max_outbuf_size |
bool | outbuf_delayed_flush |
bool | is_auto_flush |
bool | want_nowrite |
bool | want_to_flush |
bool | is_flushing |
size_t | queue_min |
time_t | autoclose_time |
WvTime | alarm_time |
WvTime | last_alarm_check |
bool | running_callback |
bool | wvstream_execute_called |
WvTask * | task |
int | errnum |
WvString | errstring |
Static Protected Attributes | |
WvStream * | globalstream = NULL |
Friends | |
class | WvTCPListener |
|
Start a WvTCPConn on an already-open socket (used by WvTCPListener).
Definition at line 52 of file wvtcp.cc. References connected, nice_tcpopts(), remaddr, and resolved. |
|
WvTCPConn tries to make all outgoing connections asynchronously (in the background). You can tell the connection has been established when a select() call returns 'true' with writable==true. Definition at line 42 of file wvtcp.cc. References connected, do_connect(), remaddr, and resolved. |
|
Resolve the hostname, then connect a new socket.
Definition at line 62 of file wvtcp.cc. References connected, dns, do_connect(), WvString::edit(), WvResolver::findaddr(), hostname, hostname(), WvIPPortAddr::port, remaddr, resolved, and WvStringParm. |
|
Destructor - rarely do you need to call this - close() is a much better way to tear down a TCP Stream ;).
|
|
Definition at line 699 of file wvstream.cc. References WvStream::globalstream, WvStream::isok(), and WvStream::pre_select(). |
|
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 156 of file wvstream.cc. References WvStream::callfunc, WvStream::execute(), WvStream::running_callback, WvStream::userdata, and WvStream::wvstream_execute_called. Referenced by WvStream::callback(). |
|
Definition at line 736 of file wvstream.cc. References WvStream::seterr(). |
|
Definition at line 767 of file wvstream.cc. References WvStream::globalstream, WvStream::isok(), and WvStream::post_select(). |
|
Implements IObject. |
|
set an alarm, ie. select() will return true after this many ms. The alarm is cleared when callback() is called. Definition at line 826 of file wvstream.cc. References WvStream::alarm_time, msecadd(), and wvtime(). Referenced by UniClientGen::clientdelta(), WvStream::continue_read(), WvStream::continue_select(), UniClientGen::do_select(), WvHttpStream::execute(), itertest3(), WvDelayedCallback< InnerCallback >::operator()(), runtests(), WvFtpStream::WvFtpStream(), WvHttpStream::WvHttpStream(), and WvTimeoutStream::WvTimeoutStream(). |
|
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 835 of file wvstream.cc. References WvStream::alarm_time, WvStream::last_alarm_check, msecdiff(), tvdiff(), wvtime(), and WvTime. Referenced by WvStream::callback(), WvStreamList::pre_select(), WvStream::pre_select(), and WvIStreamList::pre_select(). |
|
if true, force write() to call flush() each time, the default behavour. otherwise, flush() is granted special meaning when explicitly invoked by the client and write() may empty the output buffer, but will not explicitly flush(). Definition at line 358 of file wvstream.h. References WvStream::is_auto_flush. |
|
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 128 of file wvstream.cc. References WvStream::autoforward_callback(), WvStream::read_requires_writable, and WvStream::setcallback(). |
|
Definition at line 142 of file wvstream.cc. References WvStream::read(), and WvStream::write(). Referenced by WvStream::autoforward(). |
|
if the stream has a callback function defined, call it now. otherwise call execute(). Implements IWvStream. Definition at line 178 of file wvstream.cc. References WvStream::_callback(), WvStream::alarm_remaining(), WvStream::alarm_time, WvStream::alarm_was_ticking, WvTaskMan::get(), WvTask::isrunning(), WvStream::personal_stack_size, WvTaskMan::run(), WvTask::start(), WvTaskMan::start(), WvStream::task, WvStream::taskman, TRACE, and WvStream::uses_continue_select. Referenced by UniClientGen::do_select(), WvStreamList::execute(), fcopy(), main(), WvStream::runonce(), and runtests(). |
|
Resolve the remote address, if it was fed in non-IP form.
Definition at line 168 of file wvtcp.cc. References dns, do_connect(), WvResolver::findaddr(), hostname, WvIPPortAddr::port, remaddr, resolved, and WvStream::seterr(). Referenced by post_select(), and pre_select(). |
|
Closes the file descriptors. If it is undesirable for the file descriptors to be closed by this stream, duplicate the file descriptors using dup() before creating the stream. Reimplemented from WvStream. Reimplemented in WvModemBase, WvModem, WvTCPListener, and WvUnixListener. Definition at line 67 of file wvfdstream.cc. References WvStream::close(), WvFDStream::rfd, and WvFDStream::wfd. Referenced by WvUnixListener::close(), WvTCPListener::close(), WvModem::close(), WvDsp::close(), UniIniGen::commit(), WvFtpStream::execute(), WvPipe::finish(), WvConf::load_file(), WvLockDev::lock(), WvFileWatcher::make_ok(), WvFile::open(), UniIniGen::refresh(), WvFileWatcher::WvFileWatcher(), WvFDStream::~WvFDStream(), WvPipe::~WvPipe(), and WvUnixConn::~WvUnixConn(). |
|
Read exactly count bytes from the stream, using continue_select().
Definition at line 298 of file wvstream.cc. References WvBufBaseCommonImpl< T >::alloc(), WvStream::continue_read(), WvBufBaseCommonImpl< T >::free(), WvBufBaseCommonImpl< T >::unalloc(), and WvBuf. |
|
Read exactly count bytes from the stream. Notes: must be using continue_select to use this function. if timeout strikes or !isok() before count bytes could be read, nothing is read and 0 is returned. resets queuemin to 0. FIXME: yes, that means if the stream closes, continue_read might not read the last bit of data. You can use read() for that if you want. Definition at line 362 of file wvstream.cc. References WvStream::alarm(), WvStream::continue_select(), WvStream::isok(), WvStream::queuemin(), WvStream::read(), and WvStream::uses_continue_select. Referenced by WvStream::continue_read(). |
|
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 856 of file wvstream.cc. References WvStream::alarm(), WvStream::alarm_was_ticking, WvStream::running_callback, WvStream::select(), WvStream::task, WvStream::taskman, TRACE, WvStream::uses_continue_select, WvTaskMan::whoami(), and WvTaskMan::yield(). Referenced by WvStream::continue_read(), and WvStream::getline(). |
|
function to set up a TCP socket the way we *don't* like: turn the timeouts way down so that network errors show up easily for debugging
Definition at line 133 of file wvtcp.cc. References WvFDStream::getfd(). |
|
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 346 of file wvstream.h. References WvStream::outbuf_delayed_flush, and WvStream::want_to_flush. Referenced by WvHTTPStream::pre_select(). |
|
Connect to the remote end - note the "Protected" above ;).
Definition at line 139 of file wvtcp.cc. References WvFDStream::getfd(), nice_tcpopts(), remaddr, WvStream::seterr(), WvFDStream::setfd(), WvIPPortAddr::sockaddr(), and WvIPAddr::sockaddr_len(). Referenced by check_resolver(), and WvTCPConn(). |
|
drain the input buffer (read and discard data until select(0) returns false)
Definition at line 541 of file wvstream.cc. References WvStream::isreadable(), and WvStream::read(). Referenced by WvModemBase::hangup(), and WvDsp::pre_select(). |
|
Reimplemented in WvHTTPStream, and WvStreamClone. Definition at line 20 of file wverror.cc. References WvError::errnum, and WvError::errstring. Referenced by UniIniGen::commit(), WvStreamClone::errstr(), main(), UniIniGen::refresh(), WvError::seterr(), UniConfDaemon::setupsslsocket(), UniConfDaemon::setuptcpsocket(), UniConfDaemon::setupunixsocket(), WvX509Mgr::WvX509Mgr(), and WvHttpPool::~WvHttpPool(). |
|
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, WvUrlStream, WvHttpStream, WvFtpStream, WvHttpPool, WvIStreamList, WvProtoStream, WvStreamClone, WvStreamList, WvTimeoutStream, WvTimeStream, UniConfDaemonConn, and MySocket. Definition at line 259 of file wvstream.cc. References WvStream::wvstream_execute_called. Referenced by WvStream::_callback(), WvTimeStream::execute(), WvTimeoutStream::execute(), WvStreamList::execute(), WvStreamClone::execute(), WvIStreamList::execute(), and WvDailyEvent::execute(). |
|
flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a time. (-1 means wait forever) Returns true if the flushing finished (the output buffer is empty). Implements IWvStream. Definition at line 549 of file wvstream.cc. References WvStream::flush_internal(), WvStream::flush_outbuf(), WvStream::is_flushing, TRACE, and WvStream::want_to_flush. Referenced by WvStream::close(), WvEncoderStream::flush_internal(), WvStream::flush_then_close(), WvStreamClone::post_select(), and WvStream::write(). |
|
Reimplemented in WvEncoderStream, and WvStreamClone. Definition at line 634 of file wvstream.cc. Referenced by WvStream::flush(), and WvStream::flush_outbuf(). |
|
|
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 653 of file wvstream.cc. References WvStream::autoclose_time, WvStream::flush(), WvStream::outbuf, TRACE, and WvBufBaseCommonImpl< T >::used(). Referenced by main(). |
|
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 810 of file wvstream.cc. References WvStream::force. Referenced by WvSSLStream::WvSSLStream(), and WvStreamClone::WvStreamClone(). |
|
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, and WvStreamClone. Definition at line 44 of file wverror.h. Referenced by UniIniGen::commit(), WvStreamClone::geterr(), WvEncoderStream::isok(), WvConf::load_file(), WvLockDev::lock(), main(), WvHTTPStream::pre_select(), UniIniGen::refresh(), WvConf::save(), WvError::seterr(), WvMagicCircle::WvMagicCircle(), and WvHttpPool::~WvHttpPool(). |
|
Returns the Unix file descriptor for reading and writing. Asserts that the file descriptors for reading and writing are the same before returning. Returns: the file descriptor, or -1 if none Definition at line 78 of file wvfdstream.h. References WvFDStream::rfd, and WvFDStream::wfd. Referenced by WvUnixListener::accept(), WvTCPListener::accept(), debug_mode(), do_connect(), WvUDPStream::enable_broadcasts(), WvIPRawStream::enable_broadcasts(), localaddr(), low_delay(), nice_tcpopts(), post_select(), WvSSLStream::post_select(), WvUDPStream::uread(), WvIPRawStream::uread(), WvUDPStream::uwrite(), WvIPRawStream::uwrite(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), WvUnixConn::WvUnixConn(), and WvUnixListener::WvUnixListener(). |
|
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 'separator' 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 next time, or you can read what we have so far by calling read(). If wait_msec < 0, waits forever for a newline (often a bad idea!) If wait_msec=0, never waits. Otherwise, waits up to wait_msec milliseconds until a newline appears. Readahead specifies the maximum amount of data that the stream is allowed to read in one shot. It is expected that there will be no NULL characters on the line. If uses_continue_select is true, getline() will use continue_select() rather than select() to wait for its timeout. Definition at line 460 of file wvstream.cc. References WvBufBaseCommonImpl< T >::alloc(), WvStream::continue_select(), WvBufBaseCommonImpl< T >::get(), WvStream::inbuf, WvStream::isok(), msecadd(), msecdiff(), WvBufBaseCommonImpl< T >::mutablepeek(), WvBufBase< unsigned char >::put(), WvStream::queuemin(), WvStream::select(), WvBufBase< unsigned char >::strchr(), WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), WvBufBaseCommonImpl< T >::used(), and wvtime(). Referenced by concallback(), WvProtoStream::execute(), WvHttpStream::execute(), WvFtpStream::execute(), WvIPRouteList::get_kernel(), WvConf::load_file(), WvLockDev::lock(), main(), mycallback(), WvLockFile::readpid(), UniIniGen::refresh(), WvInterfaceDict::update(), and WvHTTPStream::uread(). |
|
Returns the Unix file descriptor for reading from this stream. Returns: the file descriptor, or -1 if none Reimplemented from WvStream. Definition at line 60 of file wvfdstream.h. Referenced by WvModem::close(), WvModemBase::get_real_speed(), WvModemBase::hangup(), WvConf::load_file(), WvFileWatcher::make_ok(), WvFileWatcher::pre_select(), WvModem::speed(), and WvPipe::WvPipe(). |
|
Returns the Unix file descriptor for writing to this stream. Returns: the file descriptor, or -1 if none Reimplemented from WvStream. Definition at line 67 of file wvfdstream.h. Referenced by WvPipe::finish(), WvConf::save(), and WvPipe::WvPipe(). |
|
has the connection been completed yet?
Definition at line 106 of file wvtcp.h. Referenced by pre_select(), and WvHTTPStream::pre_select(). |
|
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1.
Reimplemented from WvFDStream. Definition at line 290 of file wvtcp.cc. References WvFDStream::isok(), and resolved. Referenced by WvFtpStream::execute(), localaddr(), main(), and pre_select(). |
|
Returns true if the stream is readable.
Implements IWvStream. Definition at line 448 of file wvstream.cc. References WvStream::isok(), and WvStream::select(). Referenced by WvStream::drain(). |
|
Returns true if the stream is writable (without using the outbuf).
Implements IWvStream. Definition at line 454 of file wvstream.cc. References WvStream::isok(), and WvStream::select(). |
|
the local address of this socket (ie. from getsockname()) really useful only for transparent proxies, but always available. may be 0.0.0.0 if we did not bind explicitly! Definition at line 191 of file wvtcp.cc. References WvFDStream::getfd(), isok(), and SO_ORIGINAL_DST. |
|
function to set up a TCP socket the way we like In addition to the nice_tcpopts(), set TCP_NODELAY
Definition at line 119 of file wvtcp.cc. References WvFDStream::getfd(). |
|
function to set up a TCP socket the way we like (Read/Write, Non-Blocking, KeepAlive)
Definition at line 105 of file wvtcp.cc. References WvFDStream::getfd(). Referenced by do_connect(), and WvTCPConn(). |
|
Stops autoforwarding.
Definition at line 135 of file wvstream.cc. References WvStream::read_requires_writable, and WvStream::setcallback(). |
|
Reset our error state - there's no error condition anymore.
|
|
Shuts down the reading side of the stream. Subsequent calls to read() will fail. Reimplemented from WvStream. Definition at line 137 of file wvfdstream.cc. References WvFDStream::rfd. Referenced by WvDsp::WvDsp(). |
|
Shuts down the writing side of the stream. Subsequent calls to write() will fail. Reimplemented from WvStream. Definition at line 149 of file wvfdstream.cc. References WvStream::nowrite(), WvFDStream::rfd, WvBufBaseCommonImpl< T >::used(), and WvFDStream::wfd. Referenced by WvDsp::WvDsp(). |
|
Reimplemented in WvLog. Definition at line 624 of file wvstream.h. References WvStream::write(), and WVSTRING_FORMAT_CALL. |
|
Reimplemented in WvLog. Definition at line 618 of file wvstream.h. References WvStream::write(), and WvStringParm. Referenced by WvLog::operator()(). |
|
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. (dcoombs: 12/15/2000) FIXME: there must be a better way. This confuses the semantics of write(); can you trust it to always write all the bytes, or not? Definition at line 273 of file wvstream.h. References WvStream::max_outbuf_size. |
|
A more convenient version of post_select() usable for overriding the 'want' value temporarily.
Definition at line 447 of file wvstream.h. References WvStream::post_select(). |
|
override post_select() to set the 'connected' variable as soon as we are connected.
Reimplemented from WvFDStream. Definition at line 254 of file wvtcp.cc. References check_resolver(), connected, WvFDStream::getfd(), WvFDStream::post_select(), and WvStream::seterr(). Referenced by WvFtpStream::post_select(). |
|
A more convenient version of pre_select() usable for overriding the 'want' value temporarily.
Definition at line 406 of file wvstream.h. References WvStream::pre_select(). |
|
override pre_select() to cause select() results when resolving names.
Reimplemented from WvFDStream. Definition at line 218 of file wvtcp.cc. References check_resolver(), dns, hostname, isconnected(), isok(), WvFDStream::pre_select(), WvResolver::pre_select(), and resolved. Referenced by WvFtpStream::pre_select(). |
|
preformat and write() a string.
Definition at line 622 of file wvstream.h. References WvStream::write(), and WVSTRING_FORMAT_CALL. |
|
Definition at line 616 of file wvstream.h. References WvStream::write(), and WvStringParm. Referenced by WvConf::addfile(), cmptest(), concallback(), do_addfile(), WvLogBuffer::dump(), WvConfigSection::dump(), WvLockFile::lock(), WvLockDev::lock(), main(), mycallback(), namelookup(), WvLog::operator()(), WvLog::perror(), WvHTTPStream::pre_select(), printkey(), printsection(), runtests(), WvConf::save(), test(), trymount(), and usage(). |
|
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. WARNING: getline() sets queuemin to 0 automatically! Definition at line 332 of file wvstream.h. References WvStream::queue_min. Referenced by WvStream::continue_read(), and WvStream::getline(). |
|
Reads up to 'count' bytes of data from the stream into the buffer. Returns the actual amount read. If 'count' is greater than the amount of free space available in the buffer, only reads at most that amount. You should specify a reasonable upper bound on how much data should be read at once. Implements IWvStream. Definition at line 282 of file wvstream.cc. References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::free(), WvBufBaseCommonImpl< T >::merge(), WvStream::read(), WvBufBaseCommonImpl< T >::unalloc(), WvBuf, and WvDynBuf. |
|
read a data block on the stream. Returns the actual amount read. Implements IWvStream. Definition at line 327 of file wvstream.cc. References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::get(), WvStream::inbuf, WvStream::queue_min, TRACE, WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), and WvBufBaseCommonImpl< T >::used(). Referenced by WvStream::autoforward_callback(), WvStream::continue_read(), WvStream::drain(), WvHttpStream::execute(), WvFtpStream::execute(), WvPipe::ignore_read(), main(), WvStream::read(), and WvHTTPStream::uread(). |
|
Implements IObject. |
|
Exactly the same as: if (select(timeout)) callback();. ...except that the above is deprecated, because it assumes callbacks aren't called automatically and that the return value of one-parameter select() is actually meaningful. Update your main loop to call runonce() instead of the above. Almost all modern programs should use msec_timeout = -1. Definition at line 492 of file wvstream.h. References WvStream::callback(), and WvStream::select(). |
|
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. WARNING: the difference between the one-parameter and multi-parameter versions of select() is *incredibly* confusing. Make sure you use the right one! DEPRECATED. Call isreadable() or iswritable() instead, if msec_timeout was going to be zero. Other values of msec_timeout are not really recommended anyway. Definition at line 516 of file wvstream.h. |
|
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(). DEPRECATED. Call runonce() instead. Definition at line 477 of file wvstream.h. Referenced by WvStream::continue_select(), UniClientGen::do_select(), fcopy(), WvEncoderStream::flush_internal(), WvStream::flush_outbuf(), WvStream::getline(), WvModemBase::hangup(), WvStream::isreadable(), WvStream::iswritable(), main(), WvStreamClone::post_select(), WvFDStream::post_select(), WvHTTPStream::pre_select(), WvStream::runonce(), runtests(), and WvFileWatcher::uread(). |
|
define the callback function for this stream, called whenever the callback() member is run, and passed the 'userdata' pointer.
Definition at line 573 of file wvstream.h. References WvStream::callfunc, and WvStream::userdata. Referenced by WvUnixListener::accept_callback(), WvTCPListener::accept_callback(), WvUnixListener::auto_accept(), WvTCPListener::auto_accept(), WvStream::autoforward(), main(), WvStream::noautoforward(), runtests(), UniConfDaemon::setupsslsocket(), UniConfDaemon::setuptcpsocket(), UniConfDaemon::setupunixsocket(), UniClientGen::UniClientGen(), WvDelayedCallback< InnerCallback >::WvDelayedCallback(), and WvDelayedCallback< InnerCallback >::~WvDelayedCallback(). |
|
Sets a callback to be invoked on close().
Implements IWvStream. Definition at line 577 of file wvstream.h. References WvStream::closecb_data, and WvStream::closecb_func. |
|
Definition at line 64 of file wverror.cc. References WvError::errstr(), WvError::geterr(), and WvError::seterr(). |
|
Reimplemented from WvError. Definition at line 202 of file wvstream.h. References WvStream::seterr(), and WVSTRING_FORMAT_CALL. |
|
Reimplemented from WvError. Definition at line 200 of file wvstream.h. References WvError::seterr(), and WvStringParm. |
|
Override seterr() from WvError so that it auto-closes the stream.
Reimplemented from WvError. Definition at line 272 of file wvstream.cc. References WvStream::close(), and WvError::seterr(). Referenced by WvStream::_do_select(), check_resolver(), do_connect(), WvHttpStream::execute(), WvFtpStream::execute(), WvConf::load_file(), WvFile::open(), post_select(), WvSSLStream::post_select(), WvHTTPStream::pre_select(), WvDsp::realtime(), WvStream::seterr(), WvSSLStream::uread(), WvHTTPStream::uread(), WvFDStream::uread(), WvUDPStream::uwrite(), WvSSLStream::uwrite(), WvIPRawStream::uwrite(), WvFDStream::uwrite(), WvDsp::WvDsp(), WvIPRawStream::WvIPRawStream(), WvSSLStream::WvSSLStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), WvUnixConn::WvUnixConn(), and WvUnixListener::WvUnixListener(). |
|
Sets the file descriptor for both reading and writing. Convenience method. Definition at line 33 of file wvfdstream.h. References WvFDStream::rfd, and WvFDStream::wfd. Referenced by do_connect(), WvFile::open(), WvPipe::setup(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), WvUnixConn::WvUnixConn(), and WvUnixListener::WvUnixListener(). |
|
Returns true if we want to flush the output buffer right now. This allows us to implement delayed_flush(), flush_then_close(), etc, but it's still super-ugly and probably needs to go away. (In fact, all our buffer flushing is super-ugly right now.) Implements IWvStream. Definition at line 566 of file wvstream.cc. Referenced by WvFDStream::post_select(), and WvStream::write(). |
|
return the remote address (source of all incoming packets), which is a constant for any given TCP connection.
Reimplemented from WvStream. |
|
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 885 of file wvstream.cc. References WvStream::close(), WvTask::isrunning(), WvTask::recycle(), WvTaskMan::run(), WvStream::task, and WvStream::taskman. |
|
Undo a previous force_select() - ie. un-forces the options which are 'true', and leaves the false ones alone. Definition at line 818 of file wvstream.cc. References WvStream::force. Referenced by WvFile::open(), and WvSSLStream::post_select(). |
|
Puts data back into the stream's internal buffer. We cheat so that there's no restriction on how much (or what) data can be unread(). This is different from WvBuf::unget() (which is rather restrictive). Definition at line 904 of file wvstream.cc. References WvStream::inbuf, WvBufBaseCommonImpl< T >::merge(), WvBuf, WvDynBuf, and WvBufBaseCommonImpl< T >::zap(). |
|
unbuffered I/O functions; these ignore the buffer, which is handled by read(). Don't call these functions explicitly unless you have a _really_ good reason. This is what you would override in a derived class. Reimplemented from WvStream. Reimplemented in WvIPRawStream, WvTCPListener, WvUDPStream, WvUnixListener, and WvFileWatcher. Definition at line 85 of file wvfdstream.cc. References WvFDStream::isok(), and WvStream::seterr(). Referenced by WvFileWatcher::uread(). |
|
unbuffered I/O functions; these ignore the buffer, which is handled by write(). Don't call these functions explicitly unless you have a _really_ good reason. This is what you would override in a derived class. Reimplemented from WvFDStream. Definition at line 296 of file wvtcp.cc. References WvFDStream::uwrite(). |
|
print a preformatted WvString to the stream. see the simple version of write() way up above. Definition at line 614 of file wvstream.h. References WvFastString::cstr(), WvFastString::len(), WvStream::write(), and WvStringParm. |
|
Writes data to the stream from the given buffer. Returns the actual amount written. If count is greater than the amount of data available in the buffer, only writes at most that amount. Implements IWvStream. Definition at line 314 of file wvstream.cc. References WvBufBaseCommonImpl< T >::get(), WvBufBaseCommonImpl< T >::unget(), WvBufBaseCommonImpl< T >::used(), WvStream::write(), and WvBuf. |
|
Write data to the stream. Returns the actual amount written. Since WvStream has an output buffer, it *always* successfully "writes" the full amount (but you might have to flush the buffers later so it actually gets sent). Implements IWvStream. Definition at line 397 of file wvstream.cc. References WvStream::flush(), WvStream::flush_outbuf(), WvStream::isok(), WvStream::max_outbuf_size, WvStream::outbuf, WvStream::outbuf_delayed_flush, WvBufBase< unsigned char >::put(), WvStream::should_flush(), WvBufBaseCommonImpl< T >::used(), and WvStream::uwrite(). Referenced by WvLogFileBase::_mid_line(), WvStream::autoforward_callback(), WvHttpStream::execute(), WvFtpStream::execute(), WvModemBase::hangup(), main(), WvStream::operator()(), WvLog::operator()(), WvStream::print(), WvProtoStream::uwrite(), WvDsp::uwrite(), WvStream::write(), and WvPamStream::WvPamStream(). |
|
Like post_select(), but still exists even if you override the other post_select() in a subclass. Sigh. Definition at line 440 of file wvstream.h. References WvStream::post_select(). |
|
Like pre_select(), but still exists even if you override the other pre_select() in a subclass. Sigh. Definition at line 419 of file wvstream.h. References WvStream::pre_select(). |
|
|
|
Definition at line 690 of file wvstream.h. Referenced by WvStream::alarm(), WvStream::alarm_remaining(), and WvStream::callback(). |
|
This will be true during callback execution if the callback was triggered by the alarm going off.
Definition at line 183 of file wvstream.h. Referenced by WvStream::callback(), UniClientGen::conncallback(), and WvStream::continue_select(). |
|
Definition at line 689 of file wvstream.h. Referenced by WvStream::flush_outbuf(), and WvStream::flush_then_close(). |
|
Definition at line 673 of file wvstream.h. Referenced by WvStream::_callback(), and WvStream::setcallback(). |
|
Definition at line 676 of file wvstream.h. Referenced by WvStream::close(), and WvStream::setclosecallback(). |
|
Definition at line 674 of file wvstream.h. Referenced by WvStream::close(), and WvStream::setclosecallback(). |
|
Definition at line 43 of file wvtcp.h. Referenced by post_select(), and WvTCPConn(). |
|
Definition at line 46 of file wvtcp.h. Referenced by check_resolver(), pre_select(), and WvTCPConn(). |
|
Definition at line 22 of file wverror.h. Referenced by WvError::errstr(), and WvError::seterr(). |
|
Definition at line 23 of file wverror.h. Referenced by WvError::errstr(), and WvError::seterr(). |
|
'force' is the list of default SelectRequest values when you use the variant of select() that doesn't override them.
Definition at line 159 of file wvstream.h. Referenced by WvStream::force_select(), and WvStream::undo_force_select(). |
|
Definition at line 38 of file wvstream.cc. Referenced by WvStream::_build_selectinfo(), and WvStream::_process_selectinfo(). |
|
Definition at line 44 of file wvtcp.h. Referenced by check_resolver(), pre_select(), and WvTCPConn(). |
|
Definition at line 672 of file wvstream.h. Referenced by WvStream::getline(), WvStream::pre_select(), WvStream::read(), and WvStream::unread(). |
|
Definition at line 679 of file wvstream.h. Referenced by WvStream::auto_flush(). |
|
Definition at line 686 of file wvstream.h. Referenced by WvStream::flush(). |
|
Definition at line 691 of file wvstream.h. Referenced by WvStream::alarm_remaining(). |
|
Definition at line 677 of file wvstream.h. Referenced by WvStream::outbuf_limit(), and WvStream::write(). |
|
Definition at line 672 of file wvstream.h. Referenced by WvStream::flush_outbuf(), WvStream::flush_then_close(), and WvStream::write(). |
|
Definition at line 678 of file wvstream.h. Referenced by WvStream::delay_output(), and WvStream::write(). |
|
Specifies the stack size to reserve for continue_select().
Definition at line 177 of file wvstream.h. Referenced by WvStream::callback(). |
|
Definition at line 688 of file wvstream.h. Referenced by WvStream::queuemin(), and WvStream::read(). |
|
If this is set, select() doesn't return true for read unless the given stream also returns true for write.
Definition at line 165 of file wvstream.h. Referenced by WvStream::autoforward(), and WvStream::noautoforward(). |
|
Definition at line 45 of file wvtcp.h. Referenced by check_resolver(), do_connect(), and WvTCPConn(). |
|
Definition at line 43 of file wvtcp.h. Referenced by check_resolver(), isok(), pre_select(), and WvTCPConn(). |
|
The file descriptor for reading.
Definition at line 24 of file wvfdstream.h. Referenced by WvFDStream::close(), WvFDStream::getfd(), WvFDStream::isok(), WvFDStream::noread(), WvFDStream::nowrite(), WvFDStream::post_select(), WvFDStream::pre_select(), WvFDStream::setfd(), and WvFDStream::uwrite(). |
|
Definition at line 692 of file wvstream.h. Referenced by WvStream::_callback(), WvStream::continue_select(), and WvStream::~WvStream(). |
|
Definition at line 695 of file wvstream.h. Referenced by WvStream::callback(), WvStream::continue_select(), WvStream::terminate_continue_select(), and WvStream::~WvStream(). |
|
Definition at line 670 of file wvstream.h. Referenced by WvStream::callback(), WvStream::continue_select(), WvStream::terminate_continue_select(), and WvStream::~WvStream(). |
|
Definition at line 675 of file wvstream.h. Referenced by WvStream::_callback(), and WvStream::setcallback(). |
|
If this is set, enables the use of continue_select().
Definition at line 174 of file wvstream.h. Referenced by WvStream::callback(), WvStream::continue_read(), and WvStream::continue_select(). |
|
Definition at line 680 of file wvstream.h. Referenced by WvStream::nowrite(). |
|
Definition at line 683 of file wvstream.h. Referenced by WvStream::delay_output(), WvStream::flush(), and WvStream::flush_outbuf(). |
|
The file descriptor for writing.
Definition at line 27 of file wvfdstream.h. Referenced by WvFDStream::close(), WvFDStream::getfd(), WvFDStream::isok(), WvFDStream::nowrite(), WvFDStream::post_select(), WvFDStream::pre_select(), and WvFDStream::setfd(). |
|
If this is set, select() doesn't return true for write unless the given stream also returns true for read.
Definition at line 171 of file wvstream.h. |
|
Definition at line 693 of file wvstream.h. Referenced by WvStream::_callback(), and WvStream::execute(). |
|
Definition at line 139 of file wvstream.h. |