WvStreams
wvloopback.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Implementation of the WvLoopback stream. WvLoopback uses a
6  * socketpair() to create a stream that allows you to read()
7  * everything written to it, even (especially) across a fork() call.
8  */
9 #include "wvloopback.h"
10 #include "wvsocketpair.h"
11 #include "wvmoniker.h"
12 #include "wvlinkerhack.h"
13 
14 WV_LINK(WvLoopback);
15 
16 static IWvStream *create_loopback(WvStringParm, IObject *)
17 {
18  return new WvLoopback();
19 }
20 
21 static WvMoniker<IWvStream> reg("loop", create_loopback);
22 
23 
24 WvLoopback::WvLoopback()
25 {
26  int socks[2];
27 
28  if (wvsocketpair(SOCK_STREAM, socks))
29  {
30  seterr(errno);
31  return;
32  }
33 
34  rfd = socks[0];
35  wfd = socks[1];
36 
37  set_close_on_exec(true);
38  set_nonblock(true);
39 }
IWvStream
Definition: iwvstream.h:24
WvStream::seterr
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
Definition: wvstream.cc:451
WvMoniker
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:61
WvFdStream::set_close_on_exec
void set_close_on_exec(bool close_on_exec)
Make the fds on this stream close-on-exec or not.
Definition: wvfdstream.cc:107
IObject
Definition: IObject.h:65
WvLoopback
Implementation of a WvLoopback stream.
Definition: wvloopback.h:16
WvFdStream::set_nonblock
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
Definition: wvfdstream.cc:97
WvFdStream::wfd
int wfd
The file descriptor for writing.
Definition: wvfdstream.h:27
WvFdStream::rfd
int rfd
The file descriptor for reading.
Definition: wvfdstream.h:24