WvStreams
wvtcpex.cc
1 /*
2  * A WvTCP example.
3  *
4  * Telnets to your local SMTP port, or any other port given
5  * on the command line.
6  */
7 
8 #include "wvtcp.h"
9 #include "wvistreamlist.h"
10 #include "wvlog.h"
11 
12 int main(int argc, char **argv)
13 {
14  WvLog err("tcp", WvLog::Error);
15  WvTCPConn sock(WvString(argc==2 ? argv[1] : "0.0.0.0:25"));
16 
17  wvcon->autoforward(sock);
18  sock.autoforward(*wvcon);
19 
20  WvIStreamList l;
21  l.add_after(l.tail, wvcon, false);
22  l.add_after(l.tail, &sock, false);
23 
24  while (wvcon->isok() && sock.isok())
25  {
26  if (l.select(-1))
27  l.callback();
28  }
29 
30  if (!wvcon->isok() && wvcon->geterr())
31  err("stdin: %s\n", wvcon->errstr());
32  else if (!sock.isok() && sock.geterr())
33  err("socket: %s\n", sock.errstr());
34 
35  return 0;
36 }
WvErrorBase::geterr
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
Definition: wverror.h:48
WvStream::select
bool select(time_t msec_timeout)
Return true if any of the requested features are true on the stream.
Definition: wvstream.h:376
WvStream::callback
virtual void callback()
if the stream has a callback function defined, call it now.
Definition: wvstream.cc:401
WvTCPConn
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
Definition: wvtcp.h:39
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvStream::autoforward
void autoforward(WvStream &s)
set the callback function for this stream to an internal routine that auto-forwards all incoming stre...
Definition: wvstream.cc:362
WvStream::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvstream.cc:445
WvIStreamList
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
Definition: wvistreamlist.h:20