00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A buffered loopback stream. 00006 */ 00007 #ifndef __WVBUFSTREAM_H 00008 #define __WVBUFSTREAM_H 00009 00010 #include "wvstream.h" 00011 00012 /** 00013 * WvBufStream stores data written by write(), and returns it 00014 * later on in read(). 00015 * 00016 * Handy for making virtual streams, like WvHttpPool. 00017 * 00018 * After seteof(), the stream closes itself (without error) once the inbuf 00019 * is emptied out by read(). 00020 * 00021 * FIXME: WvStream itself should probably deal better with streams that go 00022 * !isok() with stuff still in inbuf. Then we could skip seteof() altogether, 00023 * and just do close() when we're done write()ing data. For now, it's just 00024 * too unreliable to do that, since streams do things like drop out of 00025 * WvStreamLists automatically when they're !isok(), even if they still have 00026 * data in inbuf. 00027 * 00028 * 2003/12/09: This is cleaned up a lot by WvStream's new noread()/nowrite() 00029 * functions, but we still need to actually *use* them in WvBufStream... 00030 */ 00031 class WvBufStream : public WvStream 00032 { 00033 bool dead, /*!< true if the stream has been closed */ 00034 eof; /*!< true if the sender has no more data to write(). */ 00035 00036 public: 00037 // when we close, set this pointer to NULL. A bit hacky... 00038 WvStream **death_notify; 00039 00040 WvBufStream(); 00041 virtual ~WvBufStream(); 00042 00043 virtual void close(); 00044 00045 virtual size_t uread(void *buf, size_t size); 00046 virtual size_t uwrite(const void *buf, size_t size); 00047 virtual bool isok() const; 00048 virtual bool pre_select(SelectInfo &si); 00049 00050 void seteof() { eof = true; } 00051 }; 00052 00053 00054 #endif // __WVBUFSTREAM_H