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 }