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
12int 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
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}
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
virtual bool isok() const
return true if the stream is actually usable right now
Definition wvstream.cc:445
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
bool select(time_t msec_timeout)
Return true if any of the requested features are true on the stream.
virtual void callback()
if the stream has a callback function defined, call it now.
Definition wvstream.cc:401
WvString is an implementation of a simple and efficient printable-string class.
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
virtual bool isok() const
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1.
Definition wvtcp.cc:375