Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / SOCK_Acceptor.h
bloba4035fcd92d8090ef951dcdf0339829bbec5a0c1
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file SOCK_Acceptor.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_SOCK_ACCEPTOR_H
12 #define ACE_SOCK_ACCEPTOR_H
13 #include /**/ "ace/pre.h"
15 #include "ace/SOCK_Stream.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 class ACE_Time_Value;
24 class ACE_Accept_QoS_Params;
26 /**
27 * @class ACE_SOCK_Acceptor
29 * @brief Defines a factory that creates new ACE_Streams passively.
31 * The ACE_SOCK_Acceptor has its own "passive-mode" socket.
32 * This serves as a factory to create so-called "data-mode"
33 * sockets, which are what the ACE_SOCK_Stream encapsulates.
34 * Therefore, by inheriting from ACE_SOCK, ACE_SOCK_Acceptor
35 * gets its very own socket.
37 class ACE_Export ACE_SOCK_Acceptor : public ACE_SOCK
39 public:
40 /// Default constructor.
41 ACE_SOCK_Acceptor ();
43 /**
44 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
45 * @a local_sap is the address that we're going to listen for
46 * connections on. If @a reuse_addr is 1 then we'll use the
47 * @c SO_REUSEADDR to reuse this address.
48 * @a ipv6_only is used when opening a IPv6 acceptor. If non-zero,
49 * the socket will only accept connections from IPv6 peers. If zero
50 * the socket will accept both IPv4 and v6 if it is able to.
52 ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
53 int reuse_addr = 0,
54 int protocol_family = PF_UNSPEC,
55 int backlog = ACE_DEFAULT_BACKLOG,
56 int protocol = 0,
57 int ipv6_only = 0);
59 /// Initialize a passive-mode QoS-enabled acceptor socket.
60 ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
61 ACE_Protocol_Info *protocolinfo,
62 ACE_SOCK_GROUP g,
63 u_long flags,
64 int reuse_addr,
65 int protocol_family = PF_UNSPEC,
66 int backlog = ACE_DEFAULT_BACKLOG,
67 int protocol = 0,
68 int ipv6_only = 0);
70 /**
71 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
72 * @a local_sap is the address that we're going to listen for
73 * connections on. If @a reuse_addr is 1 then we'll use the
74 * @c SO_REUSEADDR to reuse this address.
75 * @a ipv6_only is used when opening a IPv6 acceptor. If non-zero,
76 * the socket will only accept connections from IPv6 peers. If zero
77 * the socket will accept both IPv4 and v6 if it is able to.
78 * @retval Returns 0 on success and
79 * -1 on failure.
81 int open (const ACE_Addr &local_sap,
82 int reuse_addr = 0,
83 int protocol_family = PF_UNSPEC,
84 int backlog = ACE_DEFAULT_BACKLOG,
85 int protocol = 0,
86 int ipv6_only = 0);
88 /// Initialize a passive-mode QoS-enabled acceptor socket. Returns 0
89 /// on success and -1 on failure.
90 int open (const ACE_Addr &local_sap,
91 ACE_Protocol_Info *protocolinfo,
92 ACE_SOCK_GROUP g,
93 u_long flags,
94 int reuse_addr,
95 int protocol_family = PF_UNSPEC,
96 int backlog = ACE_DEFAULT_BACKLOG,
97 int protocol = 0,
98 int ipv6_only = 0);
100 /// Close the socket. Returns 0 on success and -1 on failure.
101 int close ();
103 /// Default dtor.
104 ~ACE_SOCK_Acceptor ();
106 // = Passive connection <accept> methods.
108 * Accept a new ACE_SOCK_Stream connection. A @a timeout of 0
109 * means block forever, a @a timeout of {0, 0} means poll. @a restart
110 * == true means "restart if interrupted," i.e., if errno == EINTR.
111 * Note that @a new_stream inherits the "blocking mode" of @c this
112 * ACE_SOCK_Acceptor, i.e., if @c this acceptor factory is in
113 * non-blocking mode, the @a new_stream will be in non-blocking mode
114 * and vice versa.
116 int accept (ACE_SOCK_Stream &new_stream,
117 ACE_Addr *remote_addr = 0,
118 ACE_Time_Value *timeout = 0,
119 bool restart = true,
120 bool reset_new_handle = false) const;
123 * Accept a new ACE_SOCK_Stream connection using the QoS
124 * information in @a qos_params. A @a timeout of 0 means block
125 * forever, a @a timeout of {0, 0} means poll. @a restart == true means
126 * "restart if interrupted," i.e., if errno == EINTR. Note that
127 * @a new_stream inherits the "blocking mode" of @c this
128 * ACE_SOCK_Acceptor, i.e., if @c this acceptor factory is in
129 * non-blocking mode, the @a new_stream will be in non-blocking mode
130 * and vice versa.
132 int accept (ACE_SOCK_Stream &new_stream,
133 ACE_Accept_QoS_Params qos_params,
134 ACE_Addr *remote_addr = 0,
135 ACE_Time_Value *timeout = 0,
136 bool restart = true,
137 bool reset_new_handle = false) const;
139 // = Meta-type info
140 typedef ACE_INET_Addr PEER_ADDR;
141 typedef ACE_SOCK_Stream PEER_STREAM;
143 /// Dump the state of an object.
144 void dump () const;
146 /// Declare the dynamic allocation hooks.
147 ACE_ALLOC_HOOK_DECLARE;
149 protected:
150 /// Perform operations that must occur before <ACE_OS::accept> is
151 /// called.
152 int shared_accept_start (ACE_Time_Value *timeout,
153 bool restart,
154 int &in_blocking_mode) const;
156 /// Perform operations that must occur after <ACE_OS::accept> is
157 /// called.
158 int shared_accept_finish (ACE_SOCK_Stream new_stream,
159 int in_blocking_mode,
160 bool reset_new_handle) const;
163 * This method factors out the common <open> code and is called by
164 * both the QoS-enabled <open> method and the BSD-style <open>
165 * method.
167 int shared_open (const ACE_Addr &local_sap,
168 int protocol_family,
169 int backlog,
170 int ipv6_only);
172 private:
173 /// Do not allow this function to percolate up to this interface...
174 int get_remote_addr (ACE_Addr &) const;
177 ACE_END_VERSIONED_NAMESPACE_DECL
179 #if defined (__ACE_INLINE__)
180 #include "ace/SOCK_Acceptor.inl"
181 #endif /* __ACE_INLINE__ */
183 #include /**/ "ace/post.h"
184 #endif /* ACE_SOCK_ACCEPTOR_H */