WvStreams
wvfdstream.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Base class for streams built on Unix file descriptors.
6  */
7 #ifndef __WVFDSTREAM_H
8 #define __WVFDSTREAM_H
9 
10 #include "wvstream.h"
11 
20 class WvFdStream : public WvStream
21 {
22 protected:
24  int rfd;
25 
27  int wfd;
28 
30  bool shutdown_read, shutdown_write;
31 
36  void setfd(int fd)
37  { rfd = wfd = fd; }
38 
39 public:
44  WvFdStream(int rwfd = -1);
45 
54  WvFdStream(int rfd, int wfd);
55 
57  virtual ~WvFdStream();
58 
63  int getrfd() const
64  { return rfd; }
65 
70  int getwfd() const
71  { return wfd; }
72 
81  int getfd() const
82  {
83  assert(rfd == wfd);
84  return rfd;
85  }
86 
88  void set_nonblock(bool nonblock);
89 
91  void set_close_on_exec(bool close_on_exec);
92 
93  /***** Overridden members *****/
94 
103  virtual void close();
104  virtual bool isok() const;
105  virtual size_t uread(void *buf, size_t count);
106  virtual size_t uwrite(const void *buf, size_t count);
107  virtual void pre_select(SelectInfo &si);
108  virtual bool post_select(SelectInfo &si);
109  virtual void maybe_autoclose();
110 
111 public:
112  const char *wstype() const { return "WvFdStream"; }
113 };
114 
115 typedef WvFdStream WvFDStream;
116 
117 #endif // __WVFDSTREAM_H
WvFdStream::~WvFdStream
virtual ~WvFdStream()
Destroys the stream and invokes close().
Definition: wvfdstream.cc:68
WvFdStream::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvfdstream.cc:134
WvFdStream::uread
virtual size_t uread(void *buf, size_t count)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
Definition: wvfdstream.cc:140
WvFdStream::uwrite
virtual size_t uwrite(const void *buf, size_t count)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Definition: wvfdstream.cc:162
WvFdStream::getrfd
int getrfd() const
Returns the Unix file descriptor for reading from this stream.
Definition: wvfdstream.h:63
WvFdStream::post_select
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvfdstream.cc:254
WvFdStream::setfd
void setfd(int fd)
Sets the file descriptor for both reading and writing.
Definition: wvfdstream.h:36
WvFdStream::WvFdStream
WvFdStream(int rwfd=-1)
Creates a WvStream from an existing file descriptor.
Definition: wvfdstream.cc:54
WvFdStream::maybe_autoclose
virtual void maybe_autoclose()
Auto-close the stream if the time is right.
Definition: wvfdstream.cc:186
WvFdStream::getfd
int getfd() const
Returns the Unix file descriptor for reading and writing.
Definition: wvfdstream.h:81
WvFdStream::set_close_on_exec
void set_close_on_exec(bool close_on_exec)
Make the fds on this stream close-on-exec or not.
Definition: wvfdstream.cc:107
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvFdStream::close
virtual void close()
Closes the file descriptors.
Definition: wvfdstream.cc:117
WvFdStream::getwfd
int getwfd() const
Returns the Unix file descriptor for writing to this stream.
Definition: wvfdstream.h:70
WvFdStream
Base class for streams built on Unix file descriptors.
Definition: wvfdstream.h:20
WvFdStream::pre_select
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvfdstream.cc:214
WvFdStream::set_nonblock
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
Definition: wvfdstream.cc:97
WvFdStream::shutdown_read
bool shutdown_read
Have we actually shut down the read/write sides?
Definition: wvfdstream.h:30
WvFdStream::wfd
int wfd
The file descriptor for writing.
Definition: wvfdstream.h:27
WvFdStream::rfd
int rfd
The file descriptor for reading.
Definition: wvfdstream.h:24