Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / include / wvtcp.h
blob27b71ecaf6fce70313d404181ec4c552f40e0da1
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * WvStream-based TCP connection and server classes.
6 */
7 #ifndef __WVTCP_H
8 #define __WVTCP_H
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
27 #include "wvfdstream.h"
28 #include "wvaddr.h"
29 #include "wvresolver.h"
32 class WvTCPListener;
34 /**
35 * WvTCPConn tries to make all outgoing connections asynchronously (in
36 * the background). You can tell the connection has been established
37 * when a select() call returns 'true' with writable==true.
39 class WvTCPConn : public WvFDStream
41 friend class WvTCPListener;
42 protected:
43 bool resolved, connected;
44 WvString hostname;
45 bool incoming;
46 WvIPPortAddr remaddr;
47 WvResolver dns;
49 /** Start a WvTCPConn on an already-open socket (used by WvTCPListener) */
50 WvTCPConn(int _fd, const WvIPPortAddr &_remaddr);
52 /** Connect to the remote end - note the "Protected" above ;) */
53 void do_connect();
55 /** Resolve the remote address, if it was fed in non-IP form */
56 void check_resolver();
58 public:
59 /**
60 * WvTCPConn tries to make all outgoing connections asynchronously (in
61 * the background). You can tell the connection has been established
62 * when a select() call returns 'true' with writable==true.
64 WvTCPConn(const WvIPPortAddr &_remaddr);
66 /** Resolve the hostname, then connect a new socket */
67 WvTCPConn(WvStringParm _hostname, uint16_t _port = 0);
69 /**
70 * Destructor - rarely do you need to call this - close()
71 * is a much better way to tear down a TCP Stream ;)
73 virtual ~WvTCPConn();
75 /**
76 * function to set up a TCP socket the way we like
77 * (Read/Write, Non-Blocking, KeepAlive)
79 void nice_tcpopts();
81 /**
82 * function to set up a TCP socket the way we like
83 * In addition to the nice_tcpopts(), set TCP_NODELAY
85 void low_delay();
87 /**
88 * function to set up a TCP socket the way we *don't* like: turn the
89 * timeouts way down so that network errors show up easily for debugging
91 void debug_mode();
93 /**
94 * the local address of this socket (ie. from getsockname())
95 * really useful only for transparent proxies, but always available.
96 * may be 0.0.0.0 if we did not bind explicitly!
98 WvIPPortAddr localaddr();
101 * return the remote address (source of all incoming packets),
102 * which is a constant for any given TCP connection.
104 virtual const WvIPPortAddr *src() const;
106 /** has the connection been completed yet? */
107 bool isconnected() const
108 { return connected; }
110 /** override pre_select() to cause select() results when resolving names. */
111 virtual void pre_select(SelectInfo &si);
114 * override post_select() to set the 'connected' variable as soon as we
115 * are connected.
117 virtual bool post_select(SelectInfo &si);
120 * Is this connection OK?
121 * Note: isok() will always be true if !resolved, even though fd==-1.
123 virtual bool isok() const;
125 protected:
126 virtual size_t uwrite(const void *buf, size_t count);
128 public:
129 const char *wstype() const { return "WvTCPConn"; }
133 #endif // __WVTCP_H