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"
27 #include "ace/OS_QoS.h"
29 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 * @class ACE_MEM_Acceptor
37 * @brief Defines the format and interface for the acceptor side of the
40 * This class should be modified to prevent user passing a
41 * non-localhost endpoint as the acceptor listen point because
42 * it doesn't make any sense at all to make the listening
43 * endpoint visible (or connectable) anywhere outside of this
44 * machine. However, the type of endpoint is left as <ACE_Addr>
45 * so we can later changed to use UNIX-domain sockets with mmap stream
46 * if so desired. (Currently, using UNIX-domain sockets, i.e.,
47 * ACE_LSOCK_*, with this class will not work.)
49 class ACE_Export ACE_MEM_Acceptor
: public ACE_SOCK_Acceptor
52 /// Default constructor.
58 /// Initiate a passive mode socket.
59 ACE_MEM_Acceptor (const ACE_MEM_Addr
&remote_sap
,
61 int backlog
= ACE_DEFAULT_BACKLOG
,
65 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
66 * @a local_sap is the address that we're going to listen for
67 * connections on. If @a reuse_addr is 1 then we'll use the
68 * @c SO_REUSEADDR to reuse this address. Returns 0 on success and
71 int open (const ACE_MEM_Addr
&local_sap
,
73 int backlog
= ACE_DEFAULT_BACKLOG
,
76 /// Accept a new data transfer connection.
77 int accept (ACE_MEM_Stream
&new_ipc_sap
,
78 ACE_MEM_Addr
*remote_addr
= 0,
79 ACE_Time_Value
*timeout
= 0,
81 bool reset_new_handle
= false);
83 /// Perform operations that must occur after <ACE_OS::accept> is
85 int shared_accept_finish (ACE_MEM_Stream new_stream
,
87 bool reset_new_handle
) const;
90 * Accessor/mutator of mmap filename prefix. By default, the
91 * <mmap_prefix_> is not set and the mmap filename is
92 * ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream),
93 * otherwise, it is <mmap_prefix_>_(port-number)_(&stream),
94 * <mmap_prefix_> should include _absolute_ path so the connector
95 * within the same host can located the mmap file. Example:
98 const ACE_TCHAR
*mmap_prefix () const;
99 void mmap_prefix (const ACE_TCHAR
*prefix
);
102 * Change the initial MMAP buffer size (in bytes) of the MEM_Stream
103 * this MEM_Acceptor creates.
105 void init_buffer_size (ACE_OFF_T bytes
);
107 /// Get the preferred signaling strategy.
108 ACE_MEM_IO::Signal_Strategy
preferred_strategy () const;
110 /// Set the preferred signaling strategy.
111 void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy
);
113 /// Return the local endpoint address in the referenced <ACE_Addr>.
114 /// Returns 0 if successful, else -1.
115 int get_local_addr (ACE_MEM_Addr
&) const;
118 typedef ACE_MEM_Addr PEER_ADDR
;
119 typedef ACE_MEM_Stream PEER_STREAM
;
121 /// Dump the state of an object.
124 /// Declare the dynamic allocation hooks.
125 ACE_ALLOC_HOOK_DECLARE
;
128 // = The following methods should not be accessable externally
129 // because MEM_Acceptor do not support their semantics.
130 int open (const ACE_Addr
&local_sap
,
132 int protocol_family
= PF_INET
,
133 int backlog
= ACE_DEFAULT_BACKLOG
,
136 int open (const ACE_Addr
&local_sap
,
137 ACE_Protocol_Info
*protocolinfo
,
142 int backlog
= ACE_DEFAULT_BACKLOG
,
145 int accept (ACE_SOCK_Stream
&new_stream
,
146 ACE_Addr
*remote_addr
= 0,
147 ACE_Time_Value
*timeout
= 0,
149 bool reset_new_handle
= false) const;
151 int accept (ACE_SOCK_Stream
&new_stream
,
152 ACE_Accept_QoS_Params qos_params
,
153 ACE_Addr
*remote_addr
= 0,
154 ACE_Time_Value
*timeout
= 0,
156 bool reset_new_handle
= false) const;
159 /// The filename prefix of the created mmap files. It should
160 /// contains the absolute path name of the file.
161 ACE_TCHAR
*mmap_prefix_
;
163 /// A cached MALLOC_OPTIONS. MEM_Accaptor use it to create the shared
164 /// mamory malloc upon every incoming connection.
165 ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_
;
167 /// Preferred signaling strategy.
168 ACE_MEM_IO::Signal_Strategy preferred_strategy_
;
171 ACE_END_VERSIONED_NAMESPACE_DECL
173 #if defined (__ACE_INLINE__)
174 #include "ace/MEM_Acceptor.inl"
175 #endif /* __ACE_INLINE__ */
177 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
179 #include /**/ "ace/post.h"
180 #endif /* ACE_MEM_ACCEPTOR_H */