Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

wvfdstream.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Base class for streams built on Unix file descriptors.
00006  */ 
00007 #ifndef __WVFDSTREAM_H
00008 #define __WVFDSTREAM_H
00009 
00010 #include "wvstream.h"
00011 
00012 /**
00013  * Base class for streams built on Unix file descriptors.
00014  * 
00015  * WvFDStream distinguishes between read and write file descriptors
00016  * at creation time.  Additionally, the reading and writing halves
00017  * may be independently shut down by calling noread() or nowrite().
00018  * 
00019  */
00020 class WvFDStream : public WvStream
00021 {
00022 protected:
00023     /** The file descriptor for reading. */
00024     int rfd;
00025 
00026     /** The file descriptor for writing. */
00027     int wfd;
00028 
00029     /**
00030      * Sets the file descriptor for both reading and writing.
00031      * Convenience method.
00032      */
00033     void setfd(int fd)
00034         { rfd = wfd = fd; }
00035 
00036 public:
00037     /**
00038      * Creates a WvStream from an existing file descriptor.
00039      * "rwfd" is the file descriptor for reading and writing
00040      */
00041     WvFDStream(int rwfd = -1);
00042     
00043     /**
00044      * Creates a WvStream from two existing file descriptors.
00045      * 
00046      * The file decriptors may be the same.
00047      * 
00048      * "rfd" is the file descriptor for reading
00049      * "wfd" is the file descriptor for writing
00050      */
00051     WvFDStream(int rfd, int wfd);
00052 
00053     /** Destroys the stream and invokes close(). */
00054     virtual ~WvFDStream();
00055 
00056     /**
00057      * Returns the Unix file descriptor for reading from this stream.
00058      * Returns: the file descriptor, or -1 if none
00059      */
00060     int getrfd() const
00061         { return rfd; }
00062     
00063     /**
00064      * Returns the Unix file descriptor for writing to this stream.
00065      * Returns: the file descriptor, or -1 if none
00066      */
00067     int getwfd() const
00068         { return wfd; }
00069 
00070     /**
00071      * Returns the Unix file descriptor for reading and writing.
00072      * 
00073      * Asserts that the file descriptors for reading and writing
00074      * are the same before returning.
00075      * 
00076      * Returns: the file descriptor, or -1 if none
00077      */
00078     int getfd() const
00079     {
00080         assert(rfd == wfd);
00081         return rfd;
00082     }
00083 
00084     /***** Overridden members *****/
00085     
00086     /**
00087      * Closes the file descriptors.
00088      * 
00089      * If it is undesirable for the file descriptors to be closed by
00090      * this stream, duplicate the file descriptors using dup() before
00091      * creating the stream.
00092      * 
00093      */
00094     virtual void close();
00095     virtual bool isok() const;
00096     virtual size_t uread(void *buf, size_t count);
00097     virtual size_t uwrite(const void *buf, size_t count);
00098     virtual bool pre_select(SelectInfo &si);
00099     virtual bool post_select(SelectInfo &si);
00100     virtual void noread();
00101     virtual void nowrite();
00102 };
00103 
00104 #endif // __WVFDSTREAM_H

Generated on Wed Dec 15 15:08:11 2004 for WvStreams by  doxygen 1.3.9.1