WvStreams
|
00001 /* 00002 * A WvTCP example. 00003 * 00004 * Telnets to your local SMTP port, or any other port given 00005 * on the command line. 00006 */ 00007 00008 #include "wvtcp.h" 00009 #include "wvistreamlist.h" 00010 #include "wvlog.h" 00011 00012 int main(int argc, char **argv) 00013 { 00014 WvLog err("tcp", WvLog::Error); 00015 WvTCPConn sock(WvString(argc==2 ? argv[1] : "0.0.0.0:25")); 00016 00017 wvcon->autoforward(sock); 00018 sock.autoforward(*wvcon); 00019 00020 WvIStreamList l; 00021 l.add_after(l.tail, wvcon, false); 00022 l.add_after(l.tail, &sock, false); 00023 00024 while (wvcon->isok() && sock.isok()) 00025 { 00026 if (l.select(-1)) 00027 l.callback(); 00028 } 00029 00030 if (!wvcon->isok() && wvcon->geterr()) 00031 err("stdin: %s\n", wvcon->errstr()); 00032 else if (!sock.isok() && sock.geterr()) 00033 err("socket: %s\n", sock.errstr()); 00034 00035 return 0; 00036 }