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

iwvstream.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * The basic streaming I/O interface.
00006  */ 
00007 #ifndef __IWVSTREAM_H
00008 #define __IWVSTREAM_H
00009 
00010 #ifdef _WIN32
00011 #include "winsock2.h"
00012 #include "time.h"
00013 #endif
00014 
00015 #include "wvxplc.h"
00016 #include "wverror.h"
00017 #include "wvcallback.h"
00018 #include "wvbuf.h"
00019 
00020 
00021 class WvAddr;
00022 class WvStream;
00023 
00024 
00025 // parameters are: owning-stream, userdata
00026 typedef WvCallback<void, WvStream&, void*> WvStreamCallback;
00027 
00028 
00029 class IWvStream : public WvErrorBase, public IObject
00030 {
00031 public:
00037     struct SelectRequest {
00038         bool readable, writable, isexception;
00039         
00040         SelectRequest() { }
00041         SelectRequest(bool r, bool w, bool x = false)
00042                 { readable = r; writable = w; isexception = x; }
00043         
00044         SelectRequest &operator |= (const SelectRequest &r)
00045                 { readable |= r.readable; writable |= r.writable;
00046                     isexception |= r.isexception; return *this; }
00047     };
00048     
00053     struct SelectInfo {
00054         fd_set read, write, except; // set by pre_select, read by post_select
00055         SelectRequest wants;        // what is the user looking for?
00056         int max_fd;                 // largest fd in read, write, or except
00057         time_t msec_timeout;        // max time to wait, or -1 for forever
00058         bool inherit_request;       // 'wants' values passed to child streams
00059         bool global_sure;           // should we run the globalstream callback
00060     };
00061     
00062     IWvStream();
00063     virtual ~IWvStream();
00064     virtual void close() = 0;
00065     virtual bool isok() const = 0;
00066     virtual void callback() = 0;
00067     
00068     // FIXME: these really have no place in the interface...
00069     virtual int getrfd() const = 0;
00070     virtual int getwfd() const = 0;
00071 
00072     // FIXME: evil, should go away (or be changed to localaddr/remoteaddr)
00073     virtual const WvAddr *src() const = 0;
00074     
00075     // needed for select().
00076     // Some say that pre_select() should go away.
00077     virtual bool pre_select(SelectInfo &si) = 0;
00078     virtual bool post_select(SelectInfo &si) = 0;
00079     
00080     // these are now the official way to get/put data to your stream.
00081     // The old uread() and uwrite() are just implementation details!
00082     virtual size_t read(void *buf, size_t count) = 0;
00083     virtual size_t write(const void *buf, size_t count) = 0;
00084 
00085     // FIXME: these are the new fancy versions, but WvBuf needs to have
00086     // a safely abstracted interface class (IWvBuf) before IWvStream will
00087     // really be safe, if we include these.
00088     virtual size_t read(WvBuf &outbuf, size_t count) = 0;
00089     virtual size_t write(WvBuf &inbuf, size_t count = INT_MAX) = 0;
00090 
00103     virtual void noread() = 0;
00104 
00113     virtual void nowrite() = 0;
00114     
00119     virtual void maybe_autoclose() = 0;
00120     
00122     virtual bool isreadable() = 0;
00123     
00125     virtual bool iswritable() = 0;
00126     
00136     virtual bool flush(time_t msec_timeout) = 0;
00137 
00144     virtual bool should_flush() = 0;
00145 
00147     virtual void setclosecallback(WvStreamCallback _callfunc,
00148                                   void *_userdata) = 0;
00149 };
00150 
00151 
00152 // This ifdef makes ExchangeIt work
00153 #ifndef SWIG
00154 DEFINE_IID(IWvStream, {0x7ca76e98, 0xb653, 0x43d7,
00155     {0xb0, 0x56, 0x8b, 0x9d, 0xde, 0x9a, 0xbe, 0x9d}});
00156 #endif
00157 
00158 
00159 #endif /* __IWVSTREAM_H */

Generated on Sun Jul 10 15:34:12 2005 for WvStreams by  doxygen 1.4.0