3 //=============================================================================
7 * $Id: MEM_Acceptor.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Nanbor Wang <nanbor@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_MEM_ACCEPTOR_H
14 #define ACE_MEM_ACCEPTOR_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #include "ace/SOCK_Acceptor.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
27 #include "ace/MEM_Stream.h"
28 #include "ace/MEM_Addr.h"
30 #if !defined (ACE_HAS_WINCE)
31 #include "ace/OS_QoS.h"
32 #endif // ACE_HAS_WINCE
34 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
40 * @class ACE_MEM_Acceptor
42 * @brief Defines the format and interface for the acceptor side of the
45 * This class should be modified to prevent user passing a
46 * non-localhost endpoint as the acceptor listen point because
47 * it doesn't make any sense at all to make the listening
48 * endpoint visible (or connectable) anywhere outside of this
49 * machine. However, the type of endpoint is left as <ACE_Addr>
50 * so we can later changed to use UNIX-domain sockets with mmap stream
51 * if so desired. (Currently, using UNIX-domain sockets, i.e.,
52 * ACE_LSOCK_*, with this class will not work.)
54 class ACE_Export ACE_MEM_Acceptor
: public ACE_SOCK_Acceptor
57 // = Initialization methods.
58 /// Default constructor.
59 ACE_MEM_Acceptor (void);
62 ~ACE_MEM_Acceptor (void);
64 /// Initiate a passive mode socket.
65 ACE_MEM_Acceptor (const ACE_MEM_Addr
&remote_sap
,
67 int backlog
= ACE_DEFAULT_BACKLOG
,
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. Returns 0 on success and
77 int open (const ACE_MEM_Addr
&local_sap
,
79 int backlog
= ACE_DEFAULT_BACKLOG
,
82 /// Accept a new data transfer connection.
83 int accept (ACE_MEM_Stream
&new_ipc_sap
,
84 ACE_MEM_Addr
*remote_addr
= 0,
85 ACE_Time_Value
*timeout
= 0,
87 int reset_new_handle
= 0);
89 /// Perform operations that must occur after <ACE_OS::accept> is
91 int shared_accept_finish (ACE_MEM_Stream new_stream
,
93 int reset_new_handle
) const;
96 * Accessor/mutator of mmap filename prefix. By default, the
97 * <mmap_prefix_> is not set and the mmap filename is
98 * ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream),
99 * otherwise, it is <mmap_prefix_>_(port-number)_(&stream),
100 * <mmap_prefix_> should include _absolute_ path so the connector
101 * within the same host can located the mmap file. Example:
104 const ACE_TCHAR
*mmap_prefix (void) const;
105 void mmap_prefix (const ACE_TCHAR
*prefix
);
108 * Change the initial MMAP buffer size (in bytes) of the MEM_Stream
109 * this MEM_Acceptor creates.
111 void init_buffer_size (ACE_OFF_T bytes
);
113 /// Get the preferred signaling strategy.
114 ACE_MEM_IO::Signal_Strategy
preferred_strategy (void) const;
116 /// Set the preferred signaling strategy.
117 void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy
);
119 /// Return the local endpoint address in the referenced <ACE_Addr>.
120 /// Returns 0 if successful, else -1.
121 int get_local_addr (ACE_MEM_Addr
&) const;
123 /// Accessor to the mmap options.
124 /// @deprecated This method has been deprecated.
125 ACE_MEM_SAP::MALLOC_OPTIONS
& malloc_options (void);
128 typedef ACE_MEM_Addr PEER_ADDR
;
129 typedef ACE_MEM_Stream PEER_STREAM
;
131 /// Dump the state of an object.
132 void dump (void) const;
134 /// Declare the dynamic allocation hooks.
135 ACE_ALLOC_HOOK_DECLARE
;
138 // = The following methods should not be accessable externally
139 // because MEM_Acceptor do not support their semantics.
140 int open (const ACE_Addr
&local_sap
,
142 int protocol_family
= PF_INET
,
143 int backlog
= ACE_DEFAULT_BACKLOG
,
146 int open (const ACE_Addr
&local_sap
,
147 ACE_Protocol_Info
*protocolinfo
,
152 int backlog
= ACE_DEFAULT_BACKLOG
,
155 int accept (ACE_SOCK_Stream
&new_stream
,
156 ACE_Addr
*remote_addr
= 0,
157 ACE_Time_Value
*timeout
= 0,
159 int reset_new_handle
= 0) const;
161 #if !defined (ACE_HAS_WINCE)
162 int accept (ACE_SOCK_Stream
&new_stream
,
163 ACE_Accept_QoS_Params qos_params
,
164 ACE_Addr
*remote_addr
= 0,
165 ACE_Time_Value
*timeout
= 0,
167 int reset_new_handle
= 0) const;
168 #endif // ACE_HAS_WINCE
171 /// The filename prefix of the created mmap files. It should
172 /// contains the absolute path name of the file.
173 ACE_TCHAR
*mmap_prefix_
;
175 /// A cached MALLOC_OPTIONS. MEM_Accaptor use it to create the shared
176 /// mamory malloc upon every incoming connection.
177 ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_
;
179 /// Preferred signaling strategy.
180 ACE_MEM_IO::Signal_Strategy preferred_strategy_
;
183 ACE_END_VERSIONED_NAMESPACE_DECL
185 #if defined (__ACE_INLINE__)
186 #include "ace/MEM_Acceptor.inl"
187 #endif /* __ACE_INLINE__ */
189 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
191 #include /**/ "ace/post.h"
192 #endif /* ACE_MEM_ACCEPTOR_H */