00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A WvSplitStream uses two different file descriptors: one for input 00006 * and another for output. See wvsplitstream.h. 00007 * 00008 * NOTE: this file is a pain to maintain, because many of these functions 00009 * are almost (but not quite) exactly like the ones in WvStream. If 00010 * WvStream changes, you need to change this too. 00011 */ 00012 #include "wvsplitstream.h" 00013 #include <sys/types.h> 00014 #include <sys/time.h> 00015 #include <assert.h> 00016 00017 // a console stream made from stdin/stdout. 00018 static WvSplitStream wvconsole(0,1); 00019 WvStream *wvcon = &wvconsole; 00020 00021 00022 WvSplitStream::WvSplitStream(int _rfd, int _wfd) 00023 : WvStream(_rfd) 00024 { 00025 rfd = _rfd; 00026 wfd = _wfd; 00027 } 00028 00029 00030 WvSplitStream::WvSplitStream() 00031 : WvStream() 00032 { 00033 rfd = wfd = -1; 00034 } 00035 00036 00037 WvSplitStream::~WvSplitStream() 00038 { 00039 close(); 00040 } 00041 00042 00043 void WvSplitStream::close() 00044 { 00045 WvStream::close(); 00046 rfd = -1; 00047 wfd = -1; 00048 } 00049 00050 00051 int WvSplitStream::getrfd() const 00052 { 00053 return rfd; 00054 } 00055 00056 00057 int WvSplitStream::getwfd() const 00058 { 00059 return wfd; 00060 } 00061 00062 00063 void WvSplitStream::noread() 00064 { 00065 if (rfd == wfd) 00066 close(); 00067 else 00068 { 00069 ::close(rfd); 00070 rfd = wfd; 00071 } 00072 } 00073 00074 00075 void WvSplitStream::nowrite() 00076 { 00077 if (rfd == wfd) 00078 close(); 00079 else 00080 { 00081 ::close(wfd); 00082 wfd = rfd; 00083 } 00084 } 00085