WvStreams
|
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server, then you must feed the constructor a WvX509Mgr object. More...
#include <wvsslstream.h>
Public Member Functions | |
WvSSLStream (IWvStream *_slave, WvX509Mgr *_x509=NULL, WvSSLValidateCallback _vcb=0, bool _is_server=false) | |
Start an SSL connection on the stream _slave. More... | |
virtual | ~WvSSLStream () |
Cleans up everything (calls close + frees up the SSL Objects used) | |
virtual void | pre_select (SelectInfo &si) |
pre_select() sets up for eventually calling ::select(). More... | |
virtual bool | post_select (SelectInfo &si) |
post_select() is called after ::select(), and returns true if this object is now ready. More... | |
virtual void | close () |
Close this stream. More... | |
virtual bool | isok () const |
return true if the stream is actually usable right now | |
virtual void | noread () |
Shuts down the reading side of the stream. More... | |
virtual void | nowrite () |
Shuts down the writing side of the stream. More... | |
const char * | wstype () const |
virtual void | setclone (IWvStream *clone) |
WvStreamClone takes ownership of the given stream; it will WVRELEASE() the stream when you setclone() it to something else or destroy this object. More... | |
virtual bool | flush_internal (time_t msec_timeout) |
WvStream overrides. More... | |
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. More... | |
virtual WvString | errstr () const |
void | 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 const WvAddr * | src () const |
get the remote address from which the last data block was received. More... | |
virtual void | execute () |
The callback() function calls execute(), and then calls the user- specified callback if one is defined. More... | |
virtual WvString | getattr (WvStringParm name) const |
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 WvErrorBase &err) |
virtual size_t | read (void *buf, size_t count) |
read a data block on the stream. More... | |
virtual size_t | read (WvBuf &outbuf, size_t count) |
Reads up to 'count' bytes of data from the stream into the buffer. More... | |
virtual void | unread (WvBuf &outbuf, size_t count) |
Puts data back into the stream's internal buffer. More... | |
virtual size_t | write (const void *buf, size_t count) |
Write data to the stream. More... | |
virtual size_t | write (WvBuf &inbuf, size_t count=INT_MAX) |
Writes data to the stream from the given buffer. More... | |
size_t | write (WvStringParm s) |
print a preformatted WvString to the stream. More... | |
void | outbuf_limit (size_t size) |
set the maximum size of outbuf, beyond which a call to write() will return 0. More... | |
virtual void | maybe_autoclose () |
Auto-close the stream if the time is right. More... | |
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=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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | auto_flush (bool is_automatic) |
if true, force write() to call flush() each time, the default behavour. More... | |
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. More... | |
virtual bool | should_flush () |
Returns true if we want to flush the output buffer right now. More... | |
void | flush_then_close (int msec_timeout) |
flush the output buffer automatically as select() is called. More... | |
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. More... | |
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. More... | |
bool | select (time_t msec_timeout) |
Return true if any of the requested features are true on the stream. More... | |
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. More... | |
void | runonce (time_t msec_timeout=-1) |
Exactly the same as: if (select(timeout)) callback();. More... | |
IWvStream::SelectRequest | get_select_request () |
Use get_select_request() to save the current state of the selection state of this stream. More... | |
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. More... | |
void | undo_force_select (bool readable, bool writable, bool isexception=false) |
Undo a previous force_select() - ie. More... | |
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. More... | |
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 (IWvStreamCallback _callfunc) |
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(). More... | |
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. More... | |
void | alarm (time_t msec_timeout) |
set an alarm, ie. More... | |
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 |
void | seterr_both (int _errnum, WvStringParm specialerr) |
void | seterr_both (int _errnum, WVSTRING_FORMAT_DECL) |
void | noerr () |
Reset our error state - there's no error condition anymore. | |
virtual unsigned int | addRef ()=0 |
Indicate you are using this object. More... | |
virtual unsigned int | release ()=0 |
Indicate that you are finished using this object. More... | |
virtual IObject * | getInterface (const UUID &)=0 |
Returns the requested XPLC interface. More... | |
virtual IWeakRef * | getWeakRef ()=0 |
Return a weak reference to this object. More... | |
Static Public Member Functions | |
static void | autoforward_callback (WvStream &input, WvStream &output) |
static IWvStream * | find_by_wsid (WSID wsid) |
static IWvStream * | create (WvStringParm moniker, IObject *obj=NULL) |
static WvString | strerror (int errnum) |
A replacement for the operating system ::strerror() function that can map more kinds of error strings (especially in win32). | |
Public Attributes | |
IWvStream * | cloned |
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 |
Static Public Attributes | |
static WvSSLGlobalValidateCallback | global_vcb = 0 |
Protected Member Functions | |
virtual size_t | uwrite (const void *buf, size_t len) |
unbuffered I/O functions; these ignore the buffer, which is handled by write(). More... | |
virtual size_t | uread (void *buf, size_t len) |
unbuffered I/O functions; these ignore the buffer, which is handled by read(). More... | |
void | setattr (WvStringParm name, WvStringParm value) |
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 int | getrfd () const |
virtual int | getwfd () const |
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 | |
WvX509Mgr * | x509 |
SSL_CTX * | ctx |
SSL Context - used to create SSL Object. | |
SSL * | ssl |
Main SSL Object - after SSL_set_fd() we make all calls through the connection through here. | |
WvString | my_type |
WvDynBuf | inbuf |
WvDynBuf | outbuf |
IWvStreamCallback | callfunc |
wv::function< 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 |
int | errnum |
WvString | errstring |
Static Protected Attributes | |
static WvStream * | globalstream = NULL |
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server, then you must feed the constructor a WvX509Mgr object.
Definition at line 35 of file wvsslstream.h.
WvSSLStream::WvSSLStream | ( | IWvStream * | _slave, |
WvX509Mgr * | _x509 = NULL , |
||
WvSSLValidateCallback | _vcb = 0 , |
||
bool | _is_server = false |
||
) |
Start an SSL connection on the stream _slave.
The x509 structure is optional for a client, and mandatory for a server. You need to keep the X509 object around for the entire life of this object!
Definition at line 169 of file wvsslstream.cc.
References IObject::addRef(), WvX509Mgr::bind_ssl(), ctx, WvX509Mgr::isok(), WvStream::seterr(), and ssl.
|
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 from WvStreamClone.
Definition at line 611 of file wvsslstream.cc.
References WvStreamClone::pre_select(), and WvBufBaseCommonImpl< T >::used().
|
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.
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 WvStreamClone.
Definition at line 638 of file wvsslstream.cc.
References WvX509::encode(), WvX509::errstr(), WvX509::get_subject(), WvFdStream::getfd(), IWvStream::isok(), WvX509::isok(), IWvStream::isreadable(), IWvStream::iswritable(), WvStreamClone::post_select(), WvStream::seterr(), ssl, WvBufBaseCommonImpl< T >::used(), and WvX509::validate().
|
virtual |
Close this stream.
Note that this does close the inner stream. However, see ~WvStreamClone() for a note about destroying vs. closing the stream.
Reimplemented from WvStreamClone.
Definition at line 553 of file wvsslstream.cc.
References WvStreamClone::close(), ctx, IWvStream::isok(), isok(), ssl, and WvStream::stop_read.
Referenced by uwrite(), and ~WvSSLStream().
|
virtual |
Shuts down the reading side of the stream.
This is the opposite of nowrite(), but the name is actually slightly misleading; subsequent calls to read() might not fail; rather, if the other end of the connection tries to write to us, they should fail.
After noread(), if the read buffer (if any) is empty once, we promise that it will never refill.
If you call both noread() and nowrite(), then the stream does close() automatically once all buffers are empty.
Reimplemented from WvStreamClone.
Definition at line 583 of file wvsslstream.cc.
References WvStreamClone::noread(), and WvStreamClone::nowrite().
Referenced by uread().
|
virtual |
Shuts down the writing side of the stream.
Subsequent calls to write() will fail. But if there's data in the output buffer, it will still be flushed.
If you call both noread() and nowrite(), then the stream does close() automatically once all buffers are empty.
Reimplemented from WvStreamClone.
Definition at line 599 of file wvsslstream.cc.
References WvStreamClone::noread(), and WvStreamClone::nowrite().
Referenced by uread().
|
protectedvirtual |
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 WvStreamClone.
Definition at line 430 of file wvsslstream.cc.
References close(), WvBufBaseCommonImpl< T >::free(), WvBufBaseCommonImpl< T >::get(), WvStream::seterr(), ssl, WvErrorBase::strerror(), WvBufBaseCommonImpl< T >::unget(), WvBufBaseCommonImpl< T >::used(), and WvBufBaseCommonImpl< T >::zap().
|
protectedvirtual |
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 WvStreamClone.
Definition at line 310 of file wvsslstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::free(), IWvStream::isok(), isok(), noread(), nowrite(), WvStream::seterr(), ssl, WvStream::stop_read, WvErrorBase::strerror(), WvBufBaseCommonImpl< T >::unalloc(), WvBufBaseCommonImpl< T >::used(), and WvBufBaseCommonImpl< T >::zap().
|
virtualinherited |
WvStreamClone takes ownership of the given stream; it will WVRELEASE() the stream when you setclone() it to something else or destroy this object.
If this is undesirable, you should addRef() the stream before passing it in here.
Note: setclone() changes the cloned stream's various callbacks. It removes the callbacks from the old stream when you setclone() to something else. This means it is not safe to clone the same stream more than once at a time, but it is safe to un-clone and then re-clone a stream (as long as you watch its reference count).
Note: calling setclone() more than once on the same stream can cause weird interactions with buffering. Be careful. It is often best to flush your output buffer before calling setclone().
Reimplemented in WvWinStreamClone, and WvQtStreamClone.
Definition at line 181 of file wvstreamclone.cc.
References IWvStream::setclosecallback(), and WvStream::stop_read.
Referenced by WvWinStreamClone::setclone(), WvQtStreamClone::setclone(), WvStreamClone::WvStreamClone(), and WvStreamClone::~WvStreamClone().
|
virtualinherited |
WvStream overrides.
These generally just call the cloned stream's version.
Reimplemented from WvStream.
Reimplemented in WvEncoderStream.
Definition at line 94 of file wvstreamclone.cc.
References IWvStream::flush(), IWvStream::nowrite(), and WvBufBaseCommonImpl< T >::used().
Referenced by WvEncoderStream::flush_internal().
|
virtualinherited |
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 from WvErrorBase.
Definition at line 149 of file wvstreamclone.cc.
References WvErrorBase::geterr().
Referenced by WvHttpStream::close(), WvFtpStream::close(), WvStreamClone::isok(), WvDBusConn::~WvDBusConn(), and ~WvSSLStream().
|
virtualinherited |
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 from WvStream.
Definition at line 264 of file wvstreamclone.cc.
|
virtualinherited |
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 from WvStream.
Reimplemented in WvUrlStream, WvFtpStream, WvHttpStream, WvProtoStream, and UniConfDaemonConn.
Definition at line 272 of file wvstreamclone.cc.
References WvStream::execute().
Referenced by UniConfDaemonConn::execute(), WvProtoStream::execute(), and WvHttpStream::execute().
|
virtualinherited |
read a data block on the stream.
Returns the actual amount read.
Implements IWvStream.
Definition at line 490 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::get(), WvStream::maybe_autoclose(), WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), and WvBufBaseCommonImpl< T >::used().
Referenced by WvDBusServerAuth::authorize(), WvStream::drain(), WvHttpStream::execute(), UniFileSystemGen::get(), WvStream::read(), and WvFdStream::uread().
|
virtualinherited |
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 461 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvBufBaseCommonImpl< T >::free(), WvBufBaseCommonImpl< T >::merge(), WvStream::read(), and WvBufBaseCommonImpl< T >::unalloc().
|
virtualinherited |
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 1191 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::merge(), and WvBufBaseCommonImpl< T >::zap().
Referenced by WvHttpStream::execute().
|
virtualinherited |
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 532 of file wvstream.cc.
References WvStream::flush(), WvStream::isok(), WvStream::should_flush(), WvBufBaseCommonImpl< T >::used(), and WvStream::uwrite().
Referenced by WvLogFileBase::_mid_line(), WvDBusClientAuth::authorize(), WvModem::close(), WvIStreamList::execute(), WvHttpStream::execute(), WvModemBase::hangup(), WvLog::operator()(), WvStream::print(), WvDBusConn::send(), UniFileSystemGen::set(), WvProtoStream::uwrite(), WvFdStream::uwrite(), WvStream::write(), and UniClientConn::writecmd().
|
virtualinherited |
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 477 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::get(), WvBufBaseCommonImpl< T >::unget(), WvBufBaseCommonImpl< T >::used(), and WvStream::write().
|
inlineinherited |
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 WvStream::write().
|
inlinevirtualinherited |
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?
Implements IWvStream.
Definition at line 129 of file wvstream.h.
|
virtualinherited |
Auto-close the stream if the time is right.
If noread() and nowrite() and all buffers are empty, then we can probably close.
Implements IWvStream.
Reimplemented in WvFdStream.
Definition at line 583 of file wvstream.cc.
References WvStream::close(), WvStream::stop_read, and WvBufBaseCommonImpl< T >::used().
Referenced by WvStream::blocking_getline(), WvFdStream::maybe_autoclose(), WvStream::noread(), WvStream::nowrite(), WvStream::pre_select(), and WvStream::read().
|
inlineinherited |
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(), WvHttpStream::execute(), WvIPRouteList::get_kernel(), and WvStream::getline().
|
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 602 of file wvstream.cc.
References WvBufBaseCommonImpl< T >::alloc(), WvStream::continue_select(), WvBufBaseCommonImpl< T >::get(), WvStream::isok(), WvStream::maybe_autoclose(), WvBufBaseCommonImpl< T >::mutablepeek(), WvStream::queuemin(), WvStream::select(), WvStream::stop_read, WvBufBase< unsigned char >::strchr(), WvBufBaseCommonImpl< T >::unalloc(), WvStream::uread(), WvBufBaseCommonImpl< T >::used(), and WvStream::uses_continue_select.
Referenced by WvResolver::findaddr(), WvIPRouteList::get_kernel(), WvStream::getline(), and UniIniGen::refresh().
|
inlineinherited |
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().
|
inlineinherited |
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.
|
inlineinherited |
|
virtualinherited |
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 707 of file wvstream.cc.
Referenced by WvLogFileBase::_end_line(), WvStream::close(), WvStream::flush_then_close(), WvStreamClone::post_select(), WvStream::post_select(), and WvStream::write().
|
virtualinherited |
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 724 of file wvstream.cc.
Referenced by WvFdStream::post_select(), WvStream::post_select(), and WvStream::write().
|
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 827 of file wvstream.cc.
References WvStream::flush(), and WvBufBaseCommonImpl< T >::used().
|
inlineinherited |
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().
Referenced by WvResolver::pre_select().
|
inlineinherited |
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().
Referenced by WvResolver::post_select().
|
inlineinherited |
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(), WvResolver::findaddr(), WvModemBase::hangup(), WvStream::isreadable(), WvStream::iswritable(), WvStreamClone::post_select(), WvFdStream::post_select(), and WvStream::runonce().
|
inlineinherited |
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.
|
inlineinherited |
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().
Referenced by WvDBusConn::send_and_wait().
|
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 1020 of file wvstream.cc.
|
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 1026 of file wvstream.cc.
Referenced by WvStreamClone::WvStreamClone().
|
inherited |
Undo a previous force_select() - ie.
un-forces the options which are 'true', and leaves the false ones alone.
Definition at line 1037 of file wvstream.cc.
|
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 1088 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().
|
virtualinherited |
Sets a callback to be invoked on close().
Implements IWvStream.
Definition at line 1175 of file wvstream.cc.
References WvStream::_callback(), and WvStream::isok().
|
virtualinherited |
if the stream has a callback function defined, call it now.
otherwise call execute().
Implements IWvStream.
Definition at line 401 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().
|
inherited |
set an alarm, ie.
select() will return true after this many ms. The alarm is cleared when callback() is called.
Definition at line 1048 of file wvstream.cc.
Referenced by WvStream::continue_select(), WvSubProcQueueStream::execute(), WvHttpStream::execute(), and WvUnixDGSocket::post_select().
|
pure virtualinherited |
Indicate you are using this object.
This increases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.
This called a "strong reference", because they will prevent the object from being destroyed. They should thus be used carefully, as they control the lifetime of the object. For example, you do not need to call addRef() on object passed as parameters, unless you intend on keeping them.
addRef() is often called automatically for you in XPLC, but you'll have to call release() by hand sometimes unless you use xplc_ptr.
Referenced by WvIStreamList::execute(), IObjectImplInternal::getInterface(), StaticServiceHandler::getObject(), WeakRef::getObject(), WvIStreamList::post_select(), WvQtStreamClone::WvQtStreamClone(), and WvSSLStream().
|
pure virtualinherited |
Indicate that you are finished using this object.
This decreases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.
You will usually need to manually release() any object given to you by any other XPLC function, unless you give the object to someone else who will call release.
If you use xplc_ptr, it will do this for you.
Referenced by WvIStreamList::execute(), mutate(), NewMoniker::resolve(), and MonikerService::resolve().
Returns the requested XPLC interface.
Will return NULL if the interface is not supported. The returned interface has been addRef()ed, so you will need to release() it when done. Note that the interface returned may be a pointer to the same object or a different one - that's none of your business. Asking for the IObject interface should always return the same pointer for a given logical object, so this can be used for comparison by identity.
You should probably use the convenient mutate() and get() functions instead of this, or use an xplc_ptr, which mutates the object for you.
|
pure virtualinherited |