WvStreams
wvtcp.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * WvStream-based TCP connection and server classes.
6 */
7#ifndef __WVTCP_H
8#define __WVTCP_H
9
10#include "wvautoconf.h"
11#include <stdio.h>
12#if HAVE_SYS_TYPES_H
13# include <sys/types.h>
14#endif
15#if STDC_HEADERS
16# include <stdlib.h>
17# include <stddef.h>
18#else
19# if HAVE_STDLIB_H
20# include <stdlib.h>
21# endif
22#endif
23#if HAVE_SYS_SOCKET_H
24# include <sys/socket.h>
25#endif
26
27#include "wvfdstream.h"
28#include "wvaddr.h"
29#include "wvresolver.h"
30
31
32class WvTCPListener;
33
39class WvTCPConn : public WvFDStream
40{
41 friend class WvTCPListener;
42protected:
43 bool resolved, connected;
45 bool incoming;
46 WvIPPortAddr remaddr;
47 WvResolver dns;
48
50 WvTCPConn(int _fd, const WvIPPortAddr &_remaddr);
51
53 void do_connect();
54
56 void check_resolver();
57
58public:
64 WvTCPConn(const WvIPPortAddr &_remaddr);
65
67 WvTCPConn(WvStringParm _hostname, uint16_t _port = 0);
68
73 virtual ~WvTCPConn();
74
79 void nice_tcpopts();
80
85 void low_delay();
86
91 void debug_mode();
92
99
104 virtual const WvIPPortAddr *src() const;
105
107 bool isconnected() const
108 { return connected; }
109
111 virtual void pre_select(SelectInfo &si);
112
117 virtual bool post_select(SelectInfo &si);
118
123 virtual bool isok() const;
124
125protected:
126 virtual size_t uwrite(const void *buf, size_t count);
127
128public:
129 const char *wstype() const { return "WvTCPConn"; }
130};
131
132
133#endif // __WVTCP_H
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
Base class for streams built on Unix file descriptors.
Definition wvfdstream.h:21
An IP+Port address also includes a port number, with the resulting form www.xxx.yyy....
Definition wvaddr.h:394
ASynchronous DNS resolver functions, so that we can do non-blocking lookups.
Definition wvresolver.h:25
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
Definition wvtcp.h:40
virtual bool isok() const
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1.
Definition wvtcp.cc:375
void debug_mode()
function to set up a TCP socket the way we don't like: turn the timeouts way down so that network err...
Definition wvtcp.cc:185
void low_delay()
function to set up a TCP socket the way we like In addition to the nice_tcpopts(),...
Definition wvtcp.cc:171
void nice_tcpopts()
function to set up a TCP socket the way we like (Read/Write, Non-Blocking, KeepAlive)
Definition wvtcp.cc:160
virtual bool post_select(SelectInfo &si)
override post_select() to set the 'connected' variable as soon as we are connected.
Definition wvtcp.cc:320
void check_resolver()
Resolve the remote address, if it was fed in non-IP form.
Definition wvtcp.cc:236
virtual ~WvTCPConn()
Destructor - rarely do you need to call this - close() is a much better way to tear down a TCP Stream...
Definition wvtcp.cc:152
virtual size_t uwrite(const void *buf, size_t count)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Definition wvtcp.cc:381
bool isconnected() const
has the connection been completed yet?
Definition wvtcp.h:107
virtual void pre_select(SelectInfo &si)
override pre_select() to cause select() results when resolving names.
Definition wvtcp.cc:291
virtual const WvIPPortAddr * src() const
return the remote address (source of all incoming packets), which is a constant for any given TCP con...
Definition wvtcp.cc:285
void do_connect()
Connect to the remote end - note the "Protected" above ;)
Definition wvtcp.cc:191
WvIPPortAddr localaddr()
the local address of this socket (ie.
Definition wvtcp.cc:260
Class to easily create the Server side of a WvTCPConn.
WvString hostname()
Do gethostname() without a fixed-length buffer.
Definition strutils.cc:870