WvStreams
iwvstream.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * The basic streaming I/O interface.
6 */
7#ifndef __IWVSTREAM_H
8#define __IWVSTREAM_H
9
10#include "wvbuf.h"
11#include "wverror.h"
12#include "wvtr1.h"
13#include "wvxplc.h"
14
15
16class WvAddr;
17class WvStream;
18
19
20/* The stream gets passed back as a parameter. */
21typedef wv::function<void()> IWvStreamCallback;
22typedef unsigned int WSID;
23
24class IWvStream : public WvErrorBase, public IObject
25{
26public:
27 static IWvStream *create(WvStringParm moniker, IObject *obj = NULL);
28
35 bool readable, writable, isexception;
36
37 SelectRequest() { }
38 SelectRequest(bool r, bool w, bool x = false)
39 { readable = r; writable = w; isexception = x; }
40
41 SelectRequest &operator |= (const SelectRequest &r)
42 { readable |= r.readable; writable |= r.writable;
43 isexception |= r.isexception; return *this; }
44 };
45
50 struct SelectInfo {
51 fd_set read, write, except; // set by pre_select, read by post_select
52 SelectRequest wants; // what is the user looking for?
53 int max_fd; // largest fd in read, write, or except
54 time_t msec_timeout; // max time to wait, or -1 for forever
55 bool inherit_request; // 'wants' values passed to child streams
56 bool global_sure; // should we run the globalstream callback
57 };
58
59 IWvStream();
60 virtual ~IWvStream();
61 virtual void close() = 0;
62 virtual bool isok() const = 0;
63 virtual void callback() = 0;
64
65 // FIXME: these really have no place in the interface...
66 virtual int getrfd() const = 0;
67 virtual int getwfd() const = 0;
68
69 // FIXME: evil, should go away (or be changed to localaddr/remoteaddr)
70 virtual const WvAddr *src() const = 0;
71
72 // needed for select().
73 // Some say that pre_select() should go away.
74 virtual void pre_select(SelectInfo &si) = 0;
75 virtual bool post_select(SelectInfo &si) = 0;
76
77 // these are now the official way to get/put data to your stream.
78 // The old uread() and uwrite() are just implementation details!
79 virtual size_t read(void *buf, size_t count) = 0;
80 virtual size_t write(const void *buf, size_t count) = 0;
81
82 // FIXME: these are the new fancy versions, but WvBuf needs to have
83 // a safely abstracted interface class (IWvBuf) before IWvStream will
84 // really be safe, if we include these.
85 virtual size_t read(WvBuf &outbuf, size_t count) = 0;
86 virtual size_t write(WvBuf &inbuf, size_t count = INT_MAX) = 0;
87
100 virtual void noread() = 0;
101
110 virtual void nowrite() = 0;
111
116 virtual void maybe_autoclose() = 0;
117
119 virtual bool isreadable() = 0;
120
122 virtual bool iswritable() = 0;
123
133 virtual bool flush(time_t msec_timeout) = 0;
134
141 virtual bool should_flush() = 0;
142
143 /*
144 * WARNING: these don't work as expected!
145 */
147 virtual IWvStreamCallback setreadcallback(IWvStreamCallback _callfunc) = 0;
148
150 virtual IWvStreamCallback setwritecallback(IWvStreamCallback _callfunc) = 0;
151
154 virtual IWvStreamCallback setexceptcallback(IWvStreamCallback _callfunc) = 0;
155 /*
156 * END WARNING
157 */
158
160 virtual IWvStreamCallback setclosecallback(IWvStreamCallback _callfunc) = 0;
161
162 /* Stream identification/debugging */
163 virtual const char *wsname() const = 0;
164 virtual void set_wsname(WvStringParm name) = 0;
165 virtual const char *wstype() const = 0; // This is not static due to, eg, WvStreamClone
166 virtual WSID wsid() const = 0;
167
173 virtual void outbuf_limit(size_t size) = 0;
174 virtual WvString getattr(WvStringParm name) const = 0;
175};
176
177DEFINE_IID(IWvStream, {0x7ca76e98, 0xb653, 0x43d7,
178 {0xb0, 0x56, 0x8b, 0x9d, 0xde, 0x9a, 0xbe, 0x9d}});
179
180
181#endif /* __IWVSTREAM_H */
The basic interface which is included by all other XPLC interfaces and objects.
Definition: IObject.h:65
virtual IWvStreamCallback setreadcallback(IWvStreamCallback _callfunc)=0
Sets a callback to be invoked when the stream is readable.
virtual bool isreadable()=0
Returns true if the stream is readable.
virtual bool flush(time_t msec_timeout)=0
flush the output buffer, if we can do it without delaying more than msec_timeout milliseconds at a ti...
virtual bool iswritable()=0
Returns true if the stream is writable (without using the outbuf).
virtual void nowrite()=0
Shuts down the writing side of the stream.
virtual void outbuf_limit(size_t size)=0
set the maximum size of outbuf, beyond which a call to write() will return 0.
virtual bool isok() const =0
By default, returns true if geterr() == 0.
virtual IWvStreamCallback setexceptcallback(IWvStreamCallback _callfunc)=0
Sets a callback to be invoked when the stream is in exception state.
virtual void maybe_autoclose()=0
Auto-close the stream if the time is right.
virtual void noread()=0
Shuts down the reading side of the stream.
virtual IWvStreamCallback setclosecallback(IWvStreamCallback _callfunc)=0
Sets a callback to be invoked on close().
virtual IWvStreamCallback setwritecallback(IWvStreamCallback _callfunc)=0
Sets a callback to be invoked when the stream is writable.
virtual bool should_flush()=0
Returns true if we want to flush the output buffer right now.
Base class for different address types, each of which will have the ability to convert itself to/from...
Definition: wvaddr.h:119
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:24
A class for managing error numbers and strings.
Definition: wverror.h:24
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:25
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50
A SelectRequest is a convenient way to remember what we want to do to a particular stream: read from ...
Definition: iwvstream.h:34
#define DEFINE_IID(iface, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11)
Used to define the IID of an interface.
Definition: uuid.h:134