WvStreams
wvbufstream.cc
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * WvBufStream stores data written by write(), and returns it in read().
00006  * 
00007  * See wvbufstream.h.
00008  */ 
00009 #include "wvbufstream.h"
00010 
00011 
00012 WvBufStream::WvBufStream()
00013 {
00014     dead = eof = false; 
00015 }
00016 
00017 
00018 WvBufStream::~WvBufStream()
00019 {
00020     close();
00021 }
00022 
00023 
00024 void WvBufStream::close()
00025 {
00026     dead = true; 
00027     WvStream::close();
00028 }
00029 
00030 
00031 // if uread() is called, someone has already exhausted inbuf... so now it's
00032 // time to close our stream so they know they're at EOF.
00033 size_t WvBufStream::uread(void *buf, size_t size)
00034 {
00035     if (eof)
00036         close();
00037     return 0; 
00038 }
00039 
00040 
00041 size_t WvBufStream::uwrite(const void *buf, size_t size)
00042 {
00043     inbuf.put(buf, size);
00044     return size;
00045 }
00046 
00047 
00048 bool WvBufStream::isok() const
00049 {
00050     return !dead;
00051 }
00052 
00053 
00054 void WvBufStream::pre_select(SelectInfo &si)
00055 {
00056     WvStream::pre_select(si);
00057 
00058     if (si.wants.writable || eof)
00059         si.msec_timeout = 0;
00060 }
00061 
00062 
00063 bool WvBufStream::post_select(SelectInfo &si)
00064 {
00065     return WvStream::post_select(si) || si.wants.writable || eof;
00066 }