monotone

monotone Mtn Source Tree

Root/netxx/streamserver.h

1/*
2 * Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
3 * All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * 3. Neither the name of the Author nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/** @file
34 * This file contains the definition of the Netxx::StreamServer class.
35**/
36
37#ifndef _netxx_streamserver_h_
38#define _netxx_streamserver_h_
39
40// Netxx includes
41#include <netxx/types.h>
42#include <netxx/timeout.h>
43#include <netxx/address.h>
44#include <netxx/peer.h>
45
46namespace Netxx {
47
48 // forward declaration
49 class ProbeInfo;
50 class ServerBase;
51
52/**
53 * The Netxx::StreamServer class is used for stream based servers like TCP
54 * through IPv4, TCP through IPv6 and TCP through Local Domain Sockets.
55**/
56class StreamServer {
57public:
58 //####################################################################
59 /**
60 * Create a StreamServer that will bind to all local addresses using the
61 * given port. You can also set a timeout value and a listen(2) backlog
62 * value.
63 *
64 * @param port The port to use on all local interfaces.
65 * @param timeout The timeout to use. Default is to block.
66 * @param listen_backlog The listen(2) backlog parameter.
67 * @author Peter Jones
68 **/
69 //####################################################################
70 StreamServer (port_type port, const Timeout &timeout=Timeout(), int listen_backlog=128);
71
72 //####################################################################
73 /**
74 * Create a StreamServer that will bind to each address given in addr.
75 * You can also set the timeout and listen(2) backlog value.
76 *
77 * @param addr The addresses to bind to.
78 * @param timeout The timeout to use. Default is to block.
79 * @param listen_backlog The listen(2) backlog parameter.
80 * @author Peter Jones
81 **/
82 //####################################################################
83 StreamServer (const Address &addr, const Timeout &timeout=Timeout(), int listen_backlog=128);
84
85 //####################################################################
86 /**
87 * Clean up after the StreamServer. Any sockets in use will be closed.
88 *
89 * @author Peter Jones
90 **/
91 //####################################################################
92 ~StreamServer (void);
93
94 //####################################################################
95 /**
96 * Try to accept a connection from a Peer. The returned value will
97 * indicate whether or not a connection was established or a timeout
98 * occured. This member function will throw an exception if there is an
99 * error.
100 *
101 * @return A Peer that contains info about the connected peer.
102 * @return An invalid Peer to signal a timeout.
103 * @see Netxx::Peer
104 * @author Peter Jones
105 **/
106 //####################################################################
107 Peer accept_connection (void);
108
109 //####################################################################
110 /**
111 * Get information about how this StreamServer should be probed from the
112 * Netxx::Probe class.
113 *
114 * @return A Netxx::ProbeInfo object.
115 * @author Peter Jones
116 **/
117 //####################################################################
118 const ProbeInfo* get_probe_info (void) const;
119
120 friend bool operator== (const StreamServer &ss, socket_type fd);
121 friend bool operator== (socket_type fd, const StreamServer &ss);
122 friend bool operator!= (const StreamServer &ss, socket_type fd);
123 friend bool operator!= (socket_type fd, const StreamServer &ss);
124
125private:
126 ServerBase *pimpl_;
127 StreamServer (const StreamServer&);
128 StreamServer& operator= (const StreamServer&);
129 void init (const Address &addr, int backlog);
130
131}; // end Netxx::StreamServer class
132} // end Netxx namespace
133#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status