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 
32 class WvTCPListener;
33 
39 class WvTCPConn : public WvFDStream
40 {
41  friend class WvTCPListener;
42 protected:
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 
58 public:
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 
125 protected:
126  virtual size_t uwrite(const void *buf, size_t count);
127 
128 public:
129  const char *wstype() const { return "WvTCPConn"; }
130 };
131 
132 
133 #endif // __WVTCP_H
WvTCPConn::src
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
WvTCPConn::low_delay
void low_delay()
function to set up a TCP socket the way we like In addition to the nice_tcpopts(),...
Definition: wvtcp.cc:171
WvTCPConn::WvTCPConn
WvTCPConn(int _fd, const WvIPPortAddr &_remaddr)
Start a WvTCPConn on an already-open socket (used by WvTCPListener)
Definition: wvtcp.cc:104
WvTCPConn::isok
virtual bool isok() const
Is this connection OK? Note: isok() will always be true if !resolved, even though fd==-1.
Definition: wvtcp.cc:375
WvResolver
ASynchronous DNS resolver functions, so that we can do non-blocking lookups.
Definition: wvresolver.h:24
WvTCPConn::do_connect
void do_connect()
Connect to the remote end - note the "Protected" above ;)
Definition: wvtcp.cc:191
WvTCPConn::~WvTCPConn
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
WvTCPListener
Class to easily create the Server side of a WvTCPConn.
Definition: wvtcplistener.h:16
WvTCPConn
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
Definition: wvtcp.h:39
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvTCPConn::nice_tcpopts
void nice_tcpopts()
function to set up a TCP socket the way we like (Read/Write, Non-Blocking, KeepAlive)
Definition: wvtcp.cc:160
WvIPPortAddr
An IP+Port address also includes a port number, with the resulting form www.xxx.yyy....
Definition: wvaddr.h:393
WvTCPConn::check_resolver
void check_resolver()
Resolve the remote address, if it was fed in non-IP form.
Definition: wvtcp.cc:236
WvTCPConn::pre_select
virtual void pre_select(SelectInfo &si)
override pre_select() to cause select() results when resolving names.
Definition: wvtcp.cc:291
WvTCPConn::debug_mode
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
WvTCPConn::uwrite
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
WvTCPConn::isconnected
bool isconnected() const
has the connection been completed yet?
Definition: wvtcp.h:107
WvTCPConn::localaddr
WvIPPortAddr localaddr()
the local address of this socket (ie.
Definition: wvtcp.cc:260
WvFdStream
Base class for streams built on Unix file descriptors.
Definition: wvfdstream.h:20
hostname
WvString hostname()
Do gethostname() without a fixed-length buffer.
Definition: strutils.cc:870
WvTCPConn::post_select
virtual bool post_select(SelectInfo &si)
override post_select() to set the 'connected' variable as soon as we are connected.
Definition: wvtcp.cc:320