WvStreams
wvconstream.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Declarations for wvcon, wvin, wvout, and wverr global streams.
6 */
7#include "wvfdstream.h"
8#include "wvmoniker.h"
9#include "wvlinkerhack.h"
10
11WV_LINK(WvConStream);
12
13// just like WvFDStream, but doesn't close the fd
15{
16public:
17 bool isopen;
18
19 _WvConStream(int _rfd, int _wfd, WvStringParm name = WvString::null);
20 virtual ~_WvConStream();
21 virtual void close();
22 virtual bool isok() const;
23};
24
25
26_WvConStream::_WvConStream(int _rfd, int _wfd,
27 WvStringParm name)
28 : WvFDStream(_rfd, _wfd)
29{
30 isopen = true;
31 if (!name.isnull())
32 set_wsname(name);
33}
34
35
36_WvConStream::~_WvConStream()
37{
38 close();
39}
40
41
43{
44 isopen = false;
45 setfd(-1); // prevent WvFdStream from closing our fds
47}
48
49
51{
52 return isopen;
53}
54
55
56// console streams
57#ifdef _WIN32
58
59#include "streams.h"
60SocketFromFDMaker _zero(_dup(0), fd2socket_fwd, false);
61SocketFromFDMaker _one(1, socket2fd_fwd, true);
62SocketFromFDMaker _two(2, socket2fd_fwd, true);
63
64static _WvConStream _wvcon(_zero.GetSocket(), _one.GetSocket(), "wvcon");
65static _WvConStream _wvin(_zero.GetSocket(), -1, "wvin");
66static _WvConStream _wvout(-1, _one.GetSocket(), "wvout");
67static _WvConStream _wverr(-1, _two.GetSocket(), "wverr");
68
69#else // _WIN32
70
71static _WvConStream _wvcon(0, 1, "wvcon");
72static _WvConStream _wvin(0, -1, "wvin");
73static _WvConStream _wvout(-1, 1, "wvout");
74static _WvConStream _wverr(-1, 2, "wverr");
75
76#endif // !_WIN32
77
78WvStream *wvcon = &_wvcon;
79WvStream *wvin = &_wvin;
80WvStream *wvout = &_wvout;
81WvStream *wverr = &_wverr;
82
83
84static IWvStream *create_stdin(WvStringParm s, IObject*)
85{
86 wvin->addRef();
87 return wvin;
88}
89static IWvStream *create_stdout(WvStringParm s, IObject*)
90{
91 wvout->addRef();
92 return wvout;
93}
94static IWvStream *create_stderr(WvStringParm s, IObject*)
95{
96 wverr->addRef();
97 return wverr;
98}
99static IWvStream *create_stdio(WvStringParm s, IObject*)
100{
101 wvcon->addRef();
102 return wvcon;
103}
104
105static WvMoniker<IWvStream> reg0("stdin", create_stdin);
106static WvMoniker<IWvStream> reg1("stdout", create_stdout);
107static WvMoniker<IWvStream> reg2("stderr", create_stderr);
108static WvMoniker<IWvStream> reg3("stdio", create_stdio);
109
The basic interface which is included by all other XPLC interfaces and objects.
Definition IObject.h:65
virtual unsigned int addRef()=0
Indicate you are using this object.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
bool isnull() const
returns true if this string is null
Definition wvstring.h:290
Base class for streams built on Unix file descriptors.
Definition wvfdstream.h:21
void setfd(int fd)
Sets the file descriptor for both reading and writing.
Definition wvfdstream.h:36
virtual void close()
Closes the file descriptors.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition wvmoniker.h:62
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition wvstream.h:25
virtual void close()
Closes the file descriptors.
virtual bool isok() const
return true if the stream is actually usable right now