3 //=============================================================================
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 //=============================================================================
11 #ifndef ACE_MEM_ACCEPTOR_H
12 #define ACE_MEM_ACCEPTOR_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/ACE_export.h"
17 #include "ace/SOCK_Acceptor.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
25 #include "ace/MEM_Stream.h"
26 #include "ace/MEM_Addr.h"
28 #if !defined (ACE_HAS_WINCE)
29 #include "ace/OS_QoS.h"
30 #endif // ACE_HAS_WINCE
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 * @class ACE_MEM_Acceptor
40 * @brief Defines the format and interface for the acceptor side of the
43 * This class should be modified to prevent user passing a
44 * non-localhost endpoint as the acceptor listen point because
45 * it doesn't make any sense at all to make the listening
46 * endpoint visible (or connectable) anywhere outside of this
47 * machine. However, the type of endpoint is left as <ACE_Addr>
48 * so we can later changed to use UNIX-domain sockets with mmap stream
49 * if so desired. (Currently, using UNIX-domain sockets, i.e.,
50 * ACE_LSOCK_*, with this class will not work.)
52 class ACE_Export ACE_MEM_Acceptor
: public ACE_SOCK_Acceptor
55 /// Default constructor.
56 ACE_MEM_Acceptor (void);
59 ~ACE_MEM_Acceptor (void);
61 /// Initiate a passive mode socket.
62 ACE_MEM_Acceptor (const ACE_MEM_Addr
&remote_sap
,
64 int backlog
= ACE_DEFAULT_BACKLOG
,
68 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
69 * @a local_sap is the address that we're going to listen for
70 * connections on. If @a reuse_addr is 1 then we'll use the
71 * @c SO_REUSEADDR to reuse this address. Returns 0 on success and
74 int open (const ACE_MEM_Addr
&local_sap
,
76 int backlog
= ACE_DEFAULT_BACKLOG
,
79 /// Accept a new data transfer connection.
80 int accept (ACE_MEM_Stream
&new_ipc_sap
,
81 ACE_MEM_Addr
*remote_addr
= 0,
82 ACE_Time_Value
*timeout
= 0,
84 bool reset_new_handle
= false);
86 /// Perform operations that must occur after <ACE_OS::accept> is
88 int shared_accept_finish (ACE_MEM_Stream new_stream
,
90 bool reset_new_handle
) const;
93 * Accessor/mutator of mmap filename prefix. By default, the
94 * <mmap_prefix_> is not set and the mmap filename is
95 * ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream),
96 * otherwise, it is <mmap_prefix_>_(port-number)_(&stream),
97 * <mmap_prefix_> should include _absolute_ path so the connector
98 * within the same host can located the mmap file. Example:
101 const ACE_TCHAR
*mmap_prefix (void) const;
102 void mmap_prefix (const ACE_TCHAR
*prefix
);
105 * Change the initial MMAP buffer size (in bytes) of the MEM_Stream
106 * this MEM_Acceptor creates.
108 void init_buffer_size (ACE_OFF_T bytes
);
110 /// Get the preferred signaling strategy.
111 ACE_MEM_IO::Signal_Strategy
preferred_strategy (void) const;
113 /// Set the preferred signaling strategy.
114 void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy
);
116 /// Return the local endpoint address in the referenced <ACE_Addr>.
117 /// Returns 0 if successful, else -1.
118 int get_local_addr (ACE_MEM_Addr
&) const;
121 typedef ACE_MEM_Addr PEER_ADDR
;
122 typedef ACE_MEM_Stream PEER_STREAM
;
124 /// Dump the state of an object.
125 void dump (void) const;
127 /// Declare the dynamic allocation hooks.
128 ACE_ALLOC_HOOK_DECLARE
;
131 // = The following methods should not be accessable externally
132 // because MEM_Acceptor do not support their semantics.
133 int open (const ACE_Addr
&local_sap
,
135 int protocol_family
= PF_INET
,
136 int backlog
= ACE_DEFAULT_BACKLOG
,
139 int open (const ACE_Addr
&local_sap
,
140 ACE_Protocol_Info
*protocolinfo
,
145 int backlog
= ACE_DEFAULT_BACKLOG
,
148 int accept (ACE_SOCK_Stream
&new_stream
,
149 ACE_Addr
*remote_addr
= 0,
150 ACE_Time_Value
*timeout
= 0,
152 bool reset_new_handle
= false) const;
154 #if !defined (ACE_HAS_WINCE)
155 int accept (ACE_SOCK_Stream
&new_stream
,
156 ACE_Accept_QoS_Params qos_params
,
157 ACE_Addr
*remote_addr
= 0,
158 ACE_Time_Value
*timeout
= 0,
160 bool reset_new_handle
= false) const;
161 #endif // ACE_HAS_WINCE
164 /// The filename prefix of the created mmap files. It should
165 /// contains the absolute path name of the file.
166 ACE_TCHAR
*mmap_prefix_
;
168 /// A cached MALLOC_OPTIONS. MEM_Accaptor use it to create the shared
169 /// mamory malloc upon every incoming connection.
170 ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_
;
172 /// Preferred signaling strategy.
173 ACE_MEM_IO::Signal_Strategy preferred_strategy_
;
176 ACE_END_VERSIONED_NAMESPACE_DECL
178 #if defined (__ACE_INLINE__)
179 #include "ace/MEM_Acceptor.inl"
180 #endif /* __ACE_INLINE__ */
182 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
184 #include /**/ "ace/post.h"
185 #endif /* ACE_MEM_ACCEPTOR_H */