WvStreams
wvloopback2.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Implementation of a two-way version of WvLoopback. See wvloopback2.h.
6  */
7 #include "wvloopback2.h"
8 #include "wvsocketpair.h"
9 
10 void wvloopback2(IWvStream *&s1, IWvStream *&s2)
11 {
12  int socks[2];
13 
14  if (wvsocketpair(SOCK_STREAM, socks))
15  {
16  int errnum = errno;
17  s1 = new WvStream;
18  s2 = new WvStream;
19  s1->seterr(errnum);
20  s2->seterr(errnum);
21  return;
22  }
23 
24  WvFdStream *f1 = new WvFdStream(socks[0], socks[0]);
25  WvFdStream *f2 = new WvFdStream(socks[1], socks[1]);
26 
27  f1->set_close_on_exec(true);
28  f2->set_close_on_exec(true);
29  f1->set_nonblock(true);
30  f2->set_nonblock(true);
31 
32  s1 = f1;
33  s2 = f2;
34 }
IWvStream
Definition: iwvstream.h:24
WvErrorBase::seterr
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
Definition: wverror.cc:144
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
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvFdStream
Base class for streams built on Unix file descriptors.
Definition: wvfdstream.h:20
WvFdStream::set_nonblock
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
Definition: wvfdstream.cc:97