#include <wvunixsocket.h>
Unlike WvTCPConn, WvUnixConn makes connections synchronously because either the remote server is there, or it isn't. For convenience, we'll just ignore situations where it's a local server but still slow.
FIXME: support SOCK_DGRAM mode somehow. This is a bit tricky since the listener/connection separation doesn't make as much sense then. I guess we could just ignore the listener or something...
FIXME: use the weird credential-passing stuff to exchange pid, uid, and gid with the remote end of the socket. See the unix(7) man page. This would be very cool for authentication purposes.
Definition at line 33 of file wvunixsocket.h.
Public Member Functions | |
WvUnixConn (const WvUnixAddr &_addr) | |
connect a new socket | |
const WvUnixAddr & | localaddr () |
the local address of this socket (ie. | |
virtual const WvUnixAddr * | src () const |
return the remote address (source of all incoming packets), which is a constant for any given connection. | |
const char * | wstype () const |
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. | |
void | set_nonblock (bool nonblock) |
Make the fds on this stream blocking or non-blocking. | |
void | set_close_on_exec (bool close_on_exec) |
Make the fds on this stream close-on-exec or not. | |
virtual void | close () |
Closes the file descriptors. | |
virtual bool | isok () const |
return true if the stream is actually usable right now | |
virtual size_t | uread (void *buf, size_t count) |
unbuffered I/O functions; these ignore the buffer, which is handled by read(). | |
virtual size_t | uwrite (const void *buf, size_t count) |
unbuffered I/O functions; these ignore the buffer, which is handled by write(). | |
virtual void | pre_select (SelectInfo &si) |
pre_select() sets up for eventually calling select(). | |
void | pre_select (SelectInfo &si, const SelectRequest &r) |
A more convenient version of pre_select() usable for overriding the 'want' value temporarily. | |
virtual bool | post_select (SelectInfo &si) |
post_select() is called after select(), and returns true if this object is now ready. | |
bool | post_select (SelectInfo &si, const SelectRequest &r) |
A more convenient version of post_select() usable for overriding the 'want' value temporarily. | |
virtual void | maybe_autoclose () |
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) |
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 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 void | noread () |
virtual void | nowrite () |
virtual bool | isreadable () |
virtual bool | iswritable () |
char * | getline (time_t wait_msec=0, 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. | |
char * | getline (int wait_msec, char separator= '\n', int readahead=1024) |
Auto-convert int to time_t. | |
char * | getline (double wait_msec, char separator= '\n', int readahead=1024) |
Auto-convert double to time_t. | |
char * | blocking_getline (time_t wait_msec, int separator= '\n', int readahead=1024) |
This is a version of getline() that allows you to block for more data to arrive. | |
char * | continue_getline (time_t wait_msec, int separator= '\n', int readahead=1024) |
This is a version of blocking_getline() that uses continue_select to avoid blocking other streams. | |
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 () |
void | flush_then_close (int msec_timeout) |
flush the output buffer automatically as select() is called. | |
void | 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();. | |
IWvStream::SelectRequest | get_select_request () |
Use get_select_request() to save the current state of the selection state of this stream. | |
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 WvCont::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. | |
IWvStreamCallback | setreadcallback (IWvStreamCallback _callback) |
Sets a callback to be invoked when the stream is readable. | |
IWvStreamCallback | setwritecallback (IWvStreamCallback _callback) |
Sets a callback to be invoked when the stream is writable. | |
IWvStreamCallback | setexceptcallback (IWvStreamCallback _callback) |
Sets a callback to be invoked when the stream is in exception state. | |
IWvStreamCallback | setclosecallback (IWvStreamCallback _callback) |
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. | |
void * | _callwrap (void *) |
A wrapper that's compatible with WvCont, but calls the "real" callback. | |
void | _callback () |
Actually call the registered callfunc and execute(). | |
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) |
const char * | wsname () const |
void | set_wsname (WvStringParm wsname) |
void | set_wsname (WVSTRING_FORMAT_DECL) |
WSID | wsid () const |
Static Public Member Functions | |
static void | autoforward_callback (WvStream &s, void *userdata) |
static IWvStream * | find_by_wsid (WSID wsid) |
Public Attributes | |
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. | |
bool | stop_read |
True if noread()/nowrite()/close() have been called, respectively. | |
bool | stop_write |
bool | closed |
Protected Member Functions | |
WvUnixConn (int _fd, const WvUnixAddr &_addr) | |
connect an already-open socket (used by WvUnixListener) | |
void | setfd (int fd) |
Sets the file descriptor for both reading and writing. | |
void | _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 | |
static void | debugger_streams_display_header (WvStringParm cmd, WvStreamsDebugger::ResultCallback result_cb) |
static void | debugger_streams_display_one_stream (WvStream *s, WvStringParm cmd, WvStreamsDebugger::ResultCallback result_cb) |
static void | debugger_streams_maybe_display_one_stream (WvStream *s, WvStringParm cmd, const WvStringList &args, WvStreamsDebugger::ResultCallback result_cb) |
Protected Attributes | |
WvUnixAddr | addr |
int | rfd |
The file descriptor for reading. | |
int | wfd |
The file descriptor for writing. | |
bool | shutdown_read |
Have we actually shut down the read/write sides? | |
bool | shutdown_write |
WvDynBuf | inbuf |
WvDynBuf | outbuf |
WvStreamCallback | callfunc |
void * | userdata |
WvCallback< void *, void * > | call_ctx |
IWvStreamCallback | readcb |
IWvStreamCallback | writecb |
IWvStreamCallback | exceptcb |
IWvStreamCallback | closecb |
size_t | max_outbuf_size |
bool | outbuf_delayed_flush |
bool | is_auto_flush |
bool | want_to_flush |
bool | is_flushing |
size_t | queue_min |
time_t | autoclose_time |
WvTime | alarm_time |
WvTime | last_alarm_check |
Static Protected Attributes | |
static WvStream * | globalstream = NULL |
Friends | |
class | WvUnixListener |
class | WvHTTPClientProxyStream |
const WvUnixAddr& WvUnixConn::localaddr | ( | ) | [inline] |
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 53 of file wvunixsocket.h.
const WvUnixAddr * WvUnixConn::src | ( | ) | const [virtual] |
return the remote address (source of all incoming packets), which is a constant for any given connection.
This doesn't make much sense in Unix domain sockets, so we just return localaddr() instead.
Reimplemented from WvStream.
Definition at line 103 of file wvunixsocket.cc.
void WvFdStream::setfd | ( | int | fd | ) | [inline, protected, inherited] |
Sets the file descriptor for both reading and writing.
Convenience method.
Definition at line 36 of file wvfdstream.h.
References WvFdStream::rfd, and WvFdStream::wfd.
Referenced by WvTCPConn::do_connect(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), and WvUnixConn().
int WvFdStream::getrfd | ( | ) | const [inline, virtual, inherited] |
Returns the Unix file descriptor for reading from this stream.
Returns: the file descriptor, or -1 if none
Reimplemented from WvStream.
Definition at line 63 of file wvfdstream.h.
References WvFdStream::rfd.
Referenced by WvModem::close(), UniFileSystemGen::get(), WvModemBase::hangup(), UniIniGen::refresh(), WvFdStream::set_close_on_exec(), WvFdStream::set_nonblock(), WvModem::speed(), and WvPipe::WvPipe().
int WvFdStream::getwfd | ( | ) | const [inline, virtual, inherited] |
Returns the Unix file descriptor for writing to this stream.
Returns: the file descriptor, or -1 if none
Reimplemented from WvStream.
Definition at line 70 of file wvfdstream.h.
References WvFdStream::wfd.
Referenced by WvLogFileBase::_end_line(), UniIniGen::commit(), WvPipe::finish(), WvFdStream::set_close_on_exec(), WvFdStream::set_nonblock(), and WvPipe::WvPipe().
int WvFdStream::getfd | ( | ) | const [inline, inherited] |
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 81 of file wvfdstream.h.
References WvFdStream::rfd, and WvFdStream::wfd.
Referenced by WvUnixListener::accept(), WvTCPListener::accept(), WvTCPConn::debug_mode(), WvTCPConn::do_connect(), WvTCPConn::localaddr(), WvTCPConn::low_delay(), WvTCPConn::nice_tcpopts(), WvTCPConn::post_select(), WvSSLStream::post_select(), WvUDPStream::uread(), WvIPRawStream::uread(), WvUDPStream::uwrite(), WvIPRawStream::uwrite(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), and WvUnixConn().
void WvFdStream::set_nonblock | ( | bool | nonblock | ) | [inherited] |
Make the fds on this stream blocking or non-blocking.
Definition at line 95 of file wvfdstream.cc.
References WvFdStream::getrfd(), WvFdStream::getwfd(), WvFdStream::rfd, and WvFdStream::wfd.
Referenced by WvTCPConn::nice_tcpopts(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), and WvUnixConn().
void WvFdStream::set_close_on_exec | ( | bool | close_on_exec | ) | [inherited] |
Make the fds on this stream close-on-exec or not.
Definition at line 105 of file wvfdstream.cc.
References WvFdStream::getrfd(), WvFdStream::getwfd(), WvFdStream::rfd, and WvFdStream::wfd.
Referenced by WvTCPConn::nice_tcpopts(), WvIPRawStream::WvIPRawStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), and WvUnixConn().
void WvFdStream::close | ( | ) | [virtual, inherited] |
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 WvAtomicFile, WvModemBase, WvModem, WvTCPListener, and WvUnixListener.
Definition at line 115 of file wvfdstream.cc.
References WvStream::close(), WvFdStream::rfd, and WvFdStream::wfd.
Referenced by WvUnixListener::close(), WvTCPListener::close(), WvModem::close(), WvDsp::close(), WvAtomicFile::close(), UniIniGen::commit(), WvPipe::finish(), UniIniGen::refresh(), WvFdStream::~WvFdStream(), and WvPipe::~WvPipe().
size_t WvFdStream::uread | ( | void * | buf, | |
size_t | count | |||
) | [virtual, inherited] |
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, and WvUnixListener.
Definition at line 138 of file wvfdstream.cc.
References WvFdStream::isok(), WvStream::read(), WvFdStream::rfd, and WvStream::seterr().
size_t WvFdStream::uwrite | ( | const void * | buf, | |
size_t | count | |||
) | [virtual, inherited] |
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 WvStream.
Reimplemented in WvIPRawStream, WvTCPConn, WvTCPListener, WvUDPStream, WvUnixDGSocket, and WvUnixListener.
Definition at line 160 of file wvfdstream.cc.
References WvFdStream::isok(), WvStream::seterr(), WvFdStream::wfd, and WvStream::write().
Referenced by WvColorLogConsole::_begin_line(), WvColorLogConsole::_end_line(), WvLogConsole::_mid_line(), WvColorLogConsole::_mid_line(), WvUnixDGSocket::post_select(), WvUnixDGSocket::uwrite(), and WvTCPConn::uwrite().
void WvFdStream::pre_select | ( | SelectInfo & | si | ) | [virtual, inherited] |
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 from WvStream.
Reimplemented in WvFile, WvTCPConn, and WvUnixDGSocket.
Definition at line 212 of file wvfdstream.cc.
References WvStream::pre_select(), WvFdStream::rfd, WvBufBaseCommonImpl< T >::used(), and WvFdStream::wfd.
Referenced by WvUnixDGSocket::pre_select(), WvTCPConn::pre_select(), WvFile::pre_select(), and WvDsp::pre_select().
bool WvFdStream::post_select | ( | SelectInfo & | si | ) | [virtual, inherited] |
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.
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 from WvStream.
Reimplemented in WvFile, WvTCPConn, and WvUnixDGSocket.
Definition at line 252 of file wvfdstream.cc.
References WvStream::isok(), WvFdStream::isok(), WvStream::post_select(), WvStream::read_requires_writable, WvFdStream::rfd, WvStream::select(), WvBufBaseCommonImpl< T >::used(), WvFdStream::wfd, and WvStream::write_requires_readable.
Referenced by WvUnixDGSocket::post_select(), WvTCPConn::post_select(), WvFile::post_select(), and WvDsp::post_select().
void WvStream::seterr | ( | int | _errnum | ) | [virtual, inherited] |
Override seterr() from WvError so that it auto-closes the stream.
Definition at line 415 of file wvstream.cc.
References WvStream::close(), and WvErrorBase::seterr().
Referenced by WvTCPConn::check_resolver(), WvTCPConn::do_connect(), WvTCPConn::post_select(), WvSSLStream::post_select(), UniIniGen::refresh(), WvSSLStream::uread(), WvFdStream::uread(), WvUDPStream::uwrite(), WvSSLStream::uwrite(), WvIPRawStream::uwrite(), WvFdStream::uwrite(), WvDsp::WvDsp(), WvIPRawStream::WvIPRawStream(), WvSSLStream::WvSSLStream(), WvTCPListener::WvTCPListener(), WvUDPStream::WvUDPStream(), and WvUnixConn().
size_t WvStream::read | ( | void * | buf, | |
size_t | count | |||
) | [virtual, inherited] |
read a data block on the stream.
Returns the actual amount read.
Definition at line 454 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::get(), WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), and WvBufBaseCommonImpl< T >::used().
Referenced by WvStream::drain(), UniFileSystemGen::get(), WvStream::read(), and WvFdStream::uread().
size_t WvStream::read | ( | WvBuf & | outbuf, | |
size_t | count | |||
) | [virtual, inherited] |
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.
Definition at line 425 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::free(), WvBufBaseCommonImpl< T >::merge(), WvStream::read(), and WvBufBaseCommonImpl< T >::unalloc().
void WvStream::unread | ( | WvBuf & | outbuf, | |
size_t | count | |||
) | [virtual, inherited] |
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 1159 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::merge(), and WvBufBaseCommonImpl< T >::zap().
size_t WvStream::write | ( | const void * | buf, | |
size_t | count | |||
) | [virtual, inherited] |
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).
Definition at line 496 of file wvstream.cc.
References WvStream::flush(), WvStream::isok(), WvBufBaseCommonImpl< T >::put(), WvBufBaseCommonImpl< T >::used(), and WvStream::uwrite().
Referenced by WvLogFileBase::_mid_line(), WvModem::close(), WvIStreamList::execute(), WvModemBase::hangup(), WvLog::operator()(), WvStream::print(), UniFileSystemGen::set(), WvProtoStream::uwrite(), WvFdStream::uwrite(), WvDsp::uwrite(), WvStream::write(), and UniClientConn::writecmd().
size_t WvStream::write | ( | WvBuf & | inbuf, | |
size_t | count = INT_MAX | |||
) | [virtual, inherited] |
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.
Definition at line 441 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::get(), WvBufBaseCommonImpl< T >::unget(), WvBufBaseCommonImpl< T >::used(), and WvStream::write().
size_t WvStream::write | ( | WvStringParm | s | ) | [inline, inherited] |
print a preformatted WvString to the stream.
see the simple version of write() way up above.
Definition at line 538 of file wvstream.h.
References WvFastString::cstr(), WvFastString::len(), and WvStream::write().
void WvStream::outbuf_limit | ( | size_t | size | ) | [inline, inherited] |
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 129 of file wvstream.h.
char* WvStream::getline | ( | time_t | wait_msec = 0 , |
|
char | separator = '\n' , |
|||
int | readahead = 1024 | |||
) | [inline, inherited] |
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 there is not a full line available, returns NULL. You can read what we have so far by calling read().
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.
wait_msec is provided so that legacy code does not break. But it really should be 0.
Definition at line 175 of file wvstream.h.
References WvStream::blocking_getline().
Referenced by WvProtoStream::execute(), WvIPRouteList::get_kernel(), and WvStream::getline().
char* WvStream::getline | ( | int | wait_msec, | |
char | separator = '\n' , |
|||
int | readahead = 1024 | |||
) | [inline, inherited] |
Auto-convert int to time_t.
Definition at line 182 of file wvstream.h.
References WvStream::getline().
char* WvStream::getline | ( | double | wait_msec, | |
char | separator = '\n' , |
|||
int | readahead = 1024 | |||
) | [inline, inherited] |
Auto-convert double to time_t.
Definition at line 189 of file wvstream.h.
References WvStream::getline().
char * WvStream::blocking_getline | ( | time_t | wait_msec, | |
int | separator = '\n' , |
|||
int | readahead = 1024 | |||
) | [inherited] |
This is a version of getline() that allows you to block for more data to arrive.
This should be used carefully, as blocking is generally unexpected in WvStreams programs.
If wait_msec < 0, it will wait forever for the 'separator' (often a bad idea!). If wait_msed == 0, this is the equivalent of getline().
Definition at line 566 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvStream::continue_select(), WvBufBaseCommonImpl< T >::get(), WvStream::isok(), WvBufBaseCommonImpl< T >::mutablepeek(), WvBufBaseCommonImpl< T >::put(), WvStream::queuemin(), WvStream::select(), WvStream::stop_read, WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), WvBufBaseCommonImpl< T >::used(), and WvStream::uses_continue_select.
Referenced by WvIPRouteList::get_kernel(), WvStream::getline(), and UniIniGen::refresh().
void WvStream::queuemin | ( | size_t | count | ) | [inline, inherited] |
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 232 of file wvstream.h.
Referenced by WvStream::blocking_getline().
void WvStream::delay_output | ( | bool | is_delayed | ) | [inline, inherited] |
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 246 of file wvstream.h.
void WvStream::auto_flush | ( | bool | is_automatic | ) | [inline, inherited] |
bool WvStream::flush | ( | time_t | msec_timeout | ) | [virtual, inherited] |
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).
Definition at line 671 of file wvstream.cc.
Referenced by WvLogFileBase::_end_line(), WvStream::close(), WvStream::flush_then_close(), WvStreamClone::post_select(), WvStream::post_select(), and WvStream::write().
void WvStream::flush_then_close | ( | int | msec_timeout | ) | [inherited] |
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 791 of file wvstream.cc.
References WvStream::flush(), and WvBufBaseCommonImpl< T >::used().
void WvStream::xpre_select | ( | SelectInfo & | si, | |
const SelectRequest & | r | |||
) | [inline, inherited] |
Like pre_select(), but still exists even if you override the other pre_select() in a subclass.
Sigh.
Definition at line 318 of file wvstream.h.
References WvStream::pre_select().
bool WvStream::xpost_select | ( | SelectInfo & | si, | |
const SelectRequest & | r | |||
) | [inline, inherited] |
Like post_select(), but still exists even if you override the other post_select() in a subclass.
Sigh.
Definition at line 339 of file wvstream.h.
References WvStream::post_select().
bool WvStream::select | ( | time_t | msec_timeout | ) | [inline, inherited] |
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 376 of file wvstream.h.
Referenced by WvStream::blocking_getline(), WvStream::continue_select(), WvModemBase::hangup(), WvStreamClone::post_select(), WvFdStream::post_select(), and WvStream::runonce().
bool WvStream::select | ( | time_t | msec_timeout, | |
bool | readable, | |||
bool | writable, | |||
bool | isex = false | |||
) | [inline, inherited] |
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 415 of file wvstream.h.
void WvStream::runonce | ( | time_t | msec_timeout = -1 |
) | [inline, inherited] |
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 391 of file wvstream.h.
References WvStream::callback(), and WvStream::select().
IWvStream::SelectRequest WvStream::get_select_request | ( | ) | [inherited] |
Use get_select_request() to save the current state of the selection state of this stream.
That way, you can call force_select() and undo_force_select() to restore this properly.
Definition at line 990 of file wvstream.cc.
void WvStream::force_select | ( | bool | readable, | |
bool | writable, | |||
bool | isexception = false | |||
) | [inherited] |
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 996 of file wvstream.cc.
Referenced by WvStreamClone::WvStreamClone().
void WvStream::undo_force_select | ( | bool | readable, | |
bool | writable, | |||
bool | isexception = false | |||
) | [inherited] |
Undo a previous force_select() - ie.
un-forces the options which are 'true', and leaves the false ones alone.
Definition at line 1007 of file wvstream.cc.
bool WvStream::continue_select | ( | time_t | msec_timeout | ) | [inherited] |
return to the caller from execute(), but don't really return exactly; this uses WvCont::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 WvCont won't get created.
NOTE 3: if msec_timeout >= 0, this uses WvStream::alarm().
Definition at line 1058 of file wvstream.cc.
References WvStream::alarm(), WvStream::alarm_was_ticking, WvStream::select(), WvStream::uses_continue_select, and WvCont::yield().
Referenced by WvStream::blocking_getline().
IWvStreamCallback WvStream::setreadcallback | ( | IWvStreamCallback | _callback | ) | [inherited] |
Sets a callback to be invoked when the stream is readable.
Definition at line 1113 of file wvstream.cc.
IWvStreamCallback WvStream::setwritecallback | ( | IWvStreamCallback | _callback | ) | [inherited] |
Sets a callback to be invoked when the stream is writable.
Definition at line 1123 of file wvstream.cc.
IWvStreamCallback WvStream::setexceptcallback | ( | IWvStreamCallback | _callback | ) | [inherited] |
Sets a callback to be invoked when the stream is in exception state.
Definition at line 1133 of file wvstream.cc.
IWvStreamCallback WvStream::setclosecallback | ( | IWvStreamCallback | _callback | ) | [inherited] |
Sets a callback to be invoked on close().
Definition at line 1143 of file wvstream.cc.
References WvStream::_callback(), and WvStream::isok().
void WvStream::noautoforward | ( | ) | [inherited] |
Stops autoforwarding.
Definition at line 330 of file wvstream.cc.
References WvStream::read_requires_writable, and WvStream::setcallback().
void WvStream::callback | ( | ) | [virtual, inherited] |
if the stream has a callback function defined, call it now.
otherwise call execute().
Definition at line 364 of file wvstream.cc.
References WvStream::_callback(), WvStream::_callwrap(), WvStream::alarm_remaining(), WvStream::alarm_was_ticking, WvStream::personal_stack_size, and WvStream::uses_continue_select.
Referenced by UniClientGen::flush_buffers(), and WvStream::runonce().
void WvStream::alarm | ( | time_t | msec_timeout | ) | [inherited] |
set an alarm, ie.
select() will return true after this many ms. The alarm is cleared when callback() is called.
Definition at line 1018 of file wvstream.cc.
Referenced by WvStream::continue_select(), WvSubProcQueueStream::execute(), and WvUnixDGSocket::post_select().
size_t WvStream::print | ( | WVSTRING_FORMAT_DECL | ) | [inline, inherited] |
preformat and write() a string.
Definition at line 546 of file wvstream.h.
References WvStream::write().
virtual void WvStream::execute | ( | ) | [inline, protected, virtual, inherited] |
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 UniConfDaemonConn, WvIStreamList, WvProtoStream, WvStreamClone, WvSubProcQueueStream, WvTimeoutStream, and WvTimeStream.
Definition at line 632 of file wvstream.h.
Referenced by WvStream::_callback(), WvTimeStream::execute(), WvTimeoutStream::execute(), WvStreamClone::execute(), and WvIStreamList::execute().
int WvFdStream::rfd [protected, inherited] |
The file descriptor for reading.
Definition at line 24 of file wvfdstream.h.
Referenced by WvFdStream::close(), WvFdStream::getfd(), WvFdStream::getrfd(), WvFdStream::isok(), WvFdStream::post_select(), WvFdStream::pre_select(), WvFdStream::set_close_on_exec(), WvFdStream::set_nonblock(), WvFdStream::setfd(), WvFdStream::uread(), and WvPipe::WvPipe().
int WvFdStream::wfd [protected, inherited] |
The file descriptor for writing.
Definition at line 27 of file wvfdstream.h.
Referenced by WvFdStream::close(), WvFdStream::getfd(), WvFdStream::getwfd(), WvFdStream::isok(), WvFdStream::post_select(), WvFdStream::pre_select(), WvFdStream::set_close_on_exec(), WvFdStream::set_nonblock(), WvFdStream::setfd(), WvFdStream::uwrite(), and WvPipe::WvPipe().
bool WvStream::uses_continue_select [inherited] |
If this is set, enables the use of continue_select().
Definition at line 45 of file wvstream.h.
Referenced by WvStream::blocking_getline(), WvStream::callback(), WvStream::continue_getline(), and WvStream::continue_select().
size_t WvStream::personal_stack_size [inherited] |
Specifies the stack size to reserve for continue_select().
Definition at line 48 of file wvstream.h.
Referenced by WvStream::callback().
bool WvStream::stop_read [inherited] |
True if noread()/nowrite()/close() have been called, respectively.
Definition at line 57 of file wvstream.h.
Referenced by WvStream::blocking_getline(), WvSSLStream::close(), and WvSSLStream::uread().