WvStreams
include/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
57
58public:
64 WvTCPConn(const WvIPPortAddr &_remaddr);
65
67 WvTCPConn(WvStringParm _hostname, uint16_t _port = 0);
68
73 virtual ~WvTCPConn();
74
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...
Base class for streams built on Unix file descriptors.
An IP+Port address also includes a port number, with the resulting form www.xxx.yyy....
ASynchronous DNS resolver functions, so that we can do non-blocking lookups.
WvString is an implementation of a simple and efficient printable-string class.
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
WvTCPConn(const WvIPPortAddr &_remaddr)
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
virtual const WvIPPortAddr * src() const
return the remote address (source of all incoming packets), which is a constant for any given TCP con...
virtual bool isok() const
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1.
virtual void pre_select(SelectInfo &si)
override pre_select() to cause select() results when resolving names.
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...
void low_delay()
function to set up a TCP socket the way we like In addition to the nice_tcpopts(),...
virtual bool post_select(SelectInfo &si)
override post_select() to set the 'connected' variable as soon as we are connected.
void nice_tcpopts()
function to set up a TCP socket the way we like (Read/Write, Non-Blocking, KeepAlive)
virtual ~WvTCPConn()
Destructor - rarely do you need to call this - close() is a much better way to tear down a TCP Stream...
virtual size_t uwrite(const void *buf, size_t count)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
void check_resolver()
Resolve the remote address, if it was fed in non-IP form.
bool isconnected() const
has the connection been completed yet?
WvTCPConn(WvStringParm _hostname, uint16_t _port=0)
Resolve the hostname, then connect a new socket.
WvTCPConn(int _fd, const WvIPPortAddr &_remaddr)
Start a WvTCPConn on an already-open socket (used by WvTCPListener)
void do_connect()
Connect to the remote end - note the "Protected" above ;)
WvIPPortAddr localaddr()
the local address of this socket (ie.
Class to easily create the Server side of a WvTCPConn.
WvString hostname()
Do gethostname() without a fixed-length buffer.
Definition strutils.cc:870
the data structure used by pre_select()/post_select() and internally by select().