WvStreams
wvbufstream.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * WvBufStream stores data written by write(), and returns it in read().
6  *
7  * See wvbufstream.h.
8  */
9 #include "wvbufstream.h"
10 
11 
12 WvBufStream::WvBufStream()
13 {
14  dead = eof = false;
15 }
16 
17 
18 WvBufStream::~WvBufStream()
19 {
20  close();
21 }
22 
23 
25 {
26  dead = true;
28 }
29 
30 
31 // if uread() is called, someone has already exhausted inbuf... so now it's
32 // time to close our stream so they know they're at EOF.
33 size_t WvBufStream::uread(void *buf, size_t size)
34 {
35  if (eof)
36  close();
37  return 0;
38 }
39 
40 
41 size_t WvBufStream::uwrite(const void *buf, size_t size)
42 {
43  inbuf.put(buf, size);
44  return size;
45 }
46 
47 
48 bool WvBufStream::isok() const
49 {
50  return !dead;
51 }
52 
53 
55 {
57 
58  if (si.wants.writable || eof)
59  si.msec_timeout = 0;
60 }
61 
62 
64 {
65  return WvStream::post_select(si) || si.wants.writable || eof;
66 }
WvBufStream::pre_select
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvbufstream.cc:54
WvBufStream::post_select
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvbufstream.cc:63
WvBufStream::close
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
Definition: wvbufstream.cc:24
WvStream::close
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
Definition: wvstream.cc:341
WvBufStream::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvbufstream.cc:48
IWvStream::SelectInfo
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50
WvBufStream::uwrite
virtual size_t uwrite(const void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Definition: wvbufstream.cc:41
WvStream::post_select
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvstream.cc:875
WvBufStream::uread
virtual size_t uread(void *buf, size_t size)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
Definition: wvbufstream.cc:33
WvStream::pre_select
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvstream.cc:844