#include <MEM_Acceptor.h>
Inheritance diagram for ACE_MEM_Acceptor:
Public Types | |
typedef ACE_MEM_Addr | PEER_ADDR |
typedef ACE_MEM_Stream | PEER_STREAM |
Public Member Functions | |
ACE_MEM_Acceptor (void) | |
Default constructor. | |
~ACE_MEM_Acceptor (void) | |
destructor. | |
ACE_MEM_Acceptor (const ACE_MEM_Addr &remote_sap, int reuse_addr=0, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) | |
Initiate a passive mode socket. | |
int | open (const ACE_MEM_Addr &local_sap, int reuse_addr=0, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) |
int | accept (ACE_MEM_Stream &new_ipc_sap, ACE_MEM_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) |
Accept a new data transfer connection. | |
int | shared_accept_finish (ACE_MEM_Stream new_stream, int in_blocking_mode, int reset_new_handle) const |
const ACE_TCHAR * | mmap_prefix (void) const |
void | mmap_prefix (const ACE_TCHAR *prefix) |
void | init_buffer_size (off_t bytes) |
ACE_MEM_IO::Signal_Strategy | preferred_strategy (void) const |
Get the preferred signaling strategy. | |
void | preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy) |
Set the preferred signaling strategy. | |
int | get_local_addr (ACE_MEM_Addr &) const |
ACE_MEM_SAP::MALLOC_OPTIONS & | malloc_options (void) |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Member Functions | |
int | open (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_INET, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) |
int | open (const ACE_Addr &local_sap, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr, int protocol_family, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) |
int | accept (ACE_SOCK_Stream &new_stream, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) const |
int | accept (ACE_SOCK_Stream &new_stream, ACE_Accept_QoS_Params qos_params, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) const |
Private Attributes | |
ACE_TCHAR * | mmap_prefix_ |
ACE_MEM_SAP::MALLOC_OPTIONS | malloc_options_ |
ACE_MEM_IO::Signal_Strategy | preferred_strategy_ |
Preferred signaling strategy. |
This class should be modified to prevent user passing a non-localhost endpoint as the acceptor listen point because it doesn't make any sense at all to make the listening endpoint visible (or connectable) anywhere outside of this machine. However, the type of endpoint is left as so we can later changed to use UNIX-domain sockets with mmap stream if so desired. (Currently, using UNIX-domain sockets, i.e., ACE_LSOCK_*, with this class will not work.)
Definition at line 54 of file MEM_Acceptor.h.
|
Reimplemented from ACE_SOCK_Acceptor. Definition at line 128 of file MEM_Acceptor.h. |
|
Reimplemented from ACE_SOCK_Acceptor. Definition at line 129 of file MEM_Acceptor.h. |
|
Default constructor.
Definition at line 32 of file MEM_Acceptor.cpp. References ACE_DEFAULT_BASE_ADDR, and ACE_TRACE.
00033 : mmap_prefix_ (0), 00034 malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0), 00035 preferred_strategy_ (ACE_MEM_IO::Reactive) 00036 { 00037 ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor"); 00038 } |
|
destructor.
Definition at line 40 of file MEM_Acceptor.cpp. References ACE_TRACE, and mmap_prefix_.
00041 { 00042 ACE_TRACE ("ACE_MEM_Acceptor::~ACE_MEM_Acceptor"); 00043 delete[] this->mmap_prefix_; 00044 } |
|
Initiate a passive mode socket.
Definition at line 48 of file MEM_Acceptor.cpp. References ACE_DEFAULT_BASE_ADDR, ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open().
00052 : mmap_prefix_ (0), 00053 malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0), 00054 preferred_strategy_ (ACE_MEM_IO::Reactive) 00055 { 00056 ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor"); 00057 if (this->open (remote_sap, 00058 reuse_addr, 00059 backlog, 00060 protocol) == -1) 00061 ACE_ERROR ((LM_ERROR, 00062 ACE_LIB_TEXT ("ACE_MEM_Acceptor::ACE_MEM_Acceptor"))); 00063 } |
|
Accept a new connection using the QoS information in . A of 0 means block forever, a of {0, 0} means poll. == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that inherits the "blocking mode" of , i.e., if acceptor factory is in non-blocking mode, the will be in non-blocking mode and vice versa. Reimplemented from ACE_SOCK_Acceptor. Definition at line 35 of file MEM_Acceptor.inl.
00041 { 00042 return this->ACE_SOCK_Acceptor::accept 00043 (new_stream, qos_params, remote_addr, timeout, restart, reset_new_handle); 00044 } |
|
Accept a new connection. A of 0 means block forever, a of {0, 0} means poll. == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that inherits the "blocking mode" of , i.e., if acceptor factory is in non-blocking mode, the will be in non-blocking mode and vice versa. Reimplemented from ACE_SOCK_Acceptor. Definition at line 23 of file MEM_Acceptor.inl.
00028 { 00029 return this->ACE_SOCK_Acceptor::accept 00030 (new_stream, remote_addr, timeout, restart, reset_new_handle); 00031 } |
|
Accept a new data transfer connection.
Definition at line 82 of file MEM_Acceptor.cpp. References ACE_ERROR, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_MEM_STREAM_MIN_BUFFER, ACE_NONBLOCK, ACE_TCHAR, ACE_TRACE, ACE_IPC_SAP::disable(), ACE_IPC_SAP::get_handle(), ACE_SOCK::get_local_addr(), ACE_INET_Addr::get_port_number(), ACE::get_temp_dir(), ACE_MEM_IO::init(), LM_DEBUG, LM_ERROR, malloc_options_, MAXPATHLEN, ACE_MMAP_Memory_Pool_Options::minimum_bytes_, mmap_prefix_, preferred_strategy_, ACE::recv(), ACE::send(), ACE_IPC_SAP::set_handle(), ACE_MEM_Addr::set_port_number(), shared_accept_finish(), ACE_SOCK_Acceptor::shared_accept_start(), ACE_OS::sprintf(), ACE_OS::strcat(), ACE_OS::strlen(), ACE_OS::unique_name(), and ACE_OS::unlink().
00087 { 00088 ACE_TRACE ("ACE_MEM_Acceptor::accept"); 00089 00090 int in_blocking_mode = 1; 00091 if (this->shared_accept_start (timeout, 00092 restart, 00093 in_blocking_mode) == -1) 00094 return -1; 00095 else 00096 { 00097 sockaddr *addr = 0; 00098 struct sockaddr_in inet_addr; 00099 int *len_ptr = 0; 00100 int len = 0; 00101 00102 if (remote_sap != 0) 00103 { 00104 addr = reinterpret_cast<sockaddr *> (&inet_addr); 00105 len = sizeof (inet_addr); 00106 len_ptr = &len; 00107 } 00108 00109 do 00110 // On Win32 the third parameter to <accept> must be a NULL 00111 // pointer if to ignore the client's address. 00112 new_stream.set_handle (ACE_OS::accept (this->get_handle (), 00113 addr, 00114 len_ptr)); 00115 while (new_stream.get_handle () == ACE_INVALID_HANDLE 00116 && restart != 0 00117 && errno == EINTR 00118 && timeout == 0); 00119 00120 if (remote_sap != 0) 00121 { 00122 ACE_INET_Addr temp (reinterpret_cast<sockaddr_in *> (addr), 00123 len); 00124 remote_sap->set_port_number(temp.get_port_number ()); 00125 } 00126 } 00127 00128 if (this->shared_accept_finish (new_stream, 00129 in_blocking_mode, 00130 reset_new_handle) == -1) 00131 return -1; 00132 00133 // Allocate 2 * MAXPATHLEN so we can accomodate the unique 00134 // name that gets appended later 00135 ACE_TCHAR buf [2 * MAXPATHLEN + 1]; 00136 00137 ACE_INET_Addr local_addr; 00138 if (new_stream.get_local_addr (local_addr) == -1) 00139 return -1; 00140 00141 if (this->mmap_prefix_ != 0) 00142 { 00143 ACE_OS::sprintf (buf, 00144 ACE_LIB_TEXT ("%s_%d_"), 00145 this->mmap_prefix_, 00146 local_addr.get_port_number ()); 00147 } 00148 else 00149 { 00150 ACE_TCHAR name[25]; 00151 // - 24 is so we can append name to the end. 00152 if (ACE::get_temp_dir (buf, MAXPATHLEN - 24) == -1) 00153 { 00154 ACE_ERROR ((LM_ERROR, 00155 ACE_LIB_TEXT ("Temporary path too long, ") 00156 ACE_LIB_TEXT ("defaulting to current directory\n"))); 00157 buf[0] = 0; 00158 } 00159 00160 ACE_OS::sprintf (name, 00161 ACE_LIB_TEXT ("MEM_Acceptor_%d_"), 00162 local_addr.get_port_number ()); 00163 ACE_OS::strcat (buf, name); 00164 } 00165 ACE_TCHAR unique [MAXPATHLEN]; 00166 ACE_OS::unique_name (&new_stream, unique, MAXPATHLEN); 00167 00168 ACE_OS::strcat (buf, unique); 00169 00170 // Make sure we have a fresh start. 00171 ACE_OS::unlink (buf); 00172 00173 new_stream.disable (ACE_NONBLOCK); 00174 ACE_HANDLE new_handle = new_stream.get_handle (); 00175 00176 // Protocol negociation: 00177 // Tell the client side what level of signaling strategy 00178 // we support. 00179 ACE_MEM_IO::Signal_Strategy client_signaling = 00180 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM) 00181 this->preferred_strategy_; 00182 #else 00183 // We don't support MT. 00184 ACE_MEM_IO::Reactive; 00185 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */ 00186 if (ACE::send (new_handle, &client_signaling, 00187 sizeof (ACE_INT16)) == -1) 00188 ACE_ERROR_RETURN ((LM_DEBUG, 00189 ACE_LIB_TEXT ("ACE_MEM_Acceptor::accept error sending strategy\n")), 00190 -1); 00191 00192 // Now we get the signaling strategy the client support. 00193 if (ACE::recv (new_handle, &client_signaling, 00194 sizeof (ACE_INT16)) == -1) 00195 ACE_ERROR_RETURN ((LM_DEBUG, 00196 ACE_LIB_TEXT ("ACE_MEM_Acceptor::%p error receiving strategy\n"), ACE_LIB_TEXT ("accept")), 00197 -1); 00198 00199 // Ensure minimum buffer size 00200 if (this->malloc_options_.minimum_bytes_ < ACE_MEM_STREAM_MIN_BUFFER) 00201 this->malloc_options_.minimum_bytes_ = ACE_MEM_STREAM_MIN_BUFFER; 00202 00203 // Client will decide what signaling strategy to use. 00204 00205 // Now set up the shared memory malloc pool. 00206 if (new_stream.init (buf, 00207 static_cast<ACE_MEM_IO::Signal_Strategy> (client_signaling), 00208 &this->malloc_options_) == -1) 00209 return -1; 00210 00211 // @@ Need to handle timeout here. 00212 ACE_UINT16 buf_len = static_cast<ACE_UINT16> ((ACE_OS::strlen (buf) + 1) * 00213 sizeof (ACE_TCHAR)); 00214 00215 // No need to worry about byte-order because both parties should always 00216 // be on the same machine. 00217 if (ACE::send (new_handle, &buf_len, sizeof (ACE_UINT16)) == -1) 00218 return -1; 00219 00220 // Now send the pathname of the mmap file. 00221 if (ACE::send (new_handle, buf, buf_len) == -1) 00222 return -1; 00223 return 0; 00224 } |
|
Dump the state of an object.
Reimplemented from ACE_SOCK_Acceptor. Definition at line 23 of file MEM_Acceptor.cpp. References ACE_TRACE.
00024 { 00025 #if defined (ACE_HAS_DUMP) 00026 ACE_TRACE ("ACE_MEM_Acceptor::dump"); 00027 #endif /* ACE_HAS_DUMP */ 00028 } |
|
Return the local endpoint address in the referenced . Returns 0 if successful, else -1. Definition at line 48 of file MEM_Acceptor.inl. References ACE_SOCK::get_local_addr(), ACE_INET_Addr::get_port_number(), and ACE_MEM_Addr::set_port_number().
00049 { 00050 ACE_INET_Addr temp; 00051 00052 this->ACE_SOCK_Acceptor::get_local_addr (temp); 00053 sap.set_port_number (temp.get_port_number ()); 00054 return 0; 00055 } |
|
Change the initial MMAP buffer size (in bytes) of the MEM_Stream this MEM_Acceptor creates. Definition at line 89 of file MEM_Acceptor.inl. References malloc_options_, and ACE_MMAP_Memory_Pool_Options::minimum_bytes_.
00090 { 00091 this->malloc_options_.minimum_bytes_ = bytes; 00092 } |
|
Accessor to the mmap options.
Definition at line 95 of file MEM_Acceptor.inl. References malloc_options_.
00096 { 00097 // @@ This function has been deprecated and will be removed in the 00098 // future. 00099 00100 return this->malloc_options_; 00101 } |
|
Definition at line 64 of file MEM_Acceptor.inl. References ACE_TCHAR, mmap_prefix_, and ACE::strnew().
00065 { 00066 if (prefix == 0) 00067 { 00068 this->mmap_prefix_ = 0; 00069 } 00070 else 00071 { 00072 this->mmap_prefix_ = ACE::strnew (prefix); 00073 } 00074 } |
|
Accessor/mutator of mmap filename prefix. By default, the is not set and the mmap filename is ${(TMP|TEMP)}//ACE_MEM_Acceptor_(port-number)_(&stream), otherwise, it is _(port-number)_(&stream), should include _absolute_ path so the connector within the same host can located the mmap file. Example: /tmp/mmapfile. Definition at line 58 of file MEM_Acceptor.inl. References mmap_prefix_.
00059 { 00060 return this->mmap_prefix_; 00061 } |
|
Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure. Reimplemented from ACE_SOCK_Acceptor. Definition at line 8 of file MEM_Acceptor.inl. References ACE_SOCK_GROUP.
00016 { 00017 return this->ACE_SOCK_Acceptor::open 00018 (local_sap, protocolinfo, g, flags, reuse_addr, protocol_family, 00019 backlog, protocol); 00020 } |
|
Initialize a passive-mode BSD-style acceptor socket (no QoS). is the address that we're going to listen for connections on. If is 1 then we'll use the to reuse this address. Returns 0 on success and -1 on failure. Reimplemented from ACE_SOCK_Acceptor. |
|
Initialize a passive-mode BSD-style acceptor socket (no QoS). local_sap is the address that we're going to listen for connections on. If reuse_addr is 1 then we'll use the Definition at line 66 of file MEM_Acceptor.cpp. References ACE_TRACE, ACE_MEM_Addr::get_local_addr(), and ACE_SOCK_Acceptor::open(). Referenced by ACE_MEM_Acceptor().
00070 { 00071 ACE_TRACE ("ACE_MEM_Acceptor::open"); 00072 return this->ACE_SOCK_Acceptor::open (remote_sap.get_local_addr (), 00073 reuse_addr, 00074 PF_INET, 00075 back_log, 00076 protocol); 00077 } |
|
Set the preferred signaling strategy.
Definition at line 83 of file MEM_Acceptor.inl. References preferred_strategy_.
00084 { 00085 this->preferred_strategy_ = strategy; 00086 } |
|
Get the preferred signaling strategy.
Definition at line 77 of file MEM_Acceptor.inl. References preferred_strategy_.
00078 { 00079 return this->preferred_strategy_; 00080 } |
|
Perform operations that must occur after <ACE_OS::accept> is called. Definition at line 227 of file MEM_Acceptor.cpp. References ACE_NONBLOCK, ACE_TRACE, ACE::clr_flags(), and ACE_IPC_SAP::get_handle(). Referenced by accept().
00230 { 00231 ACE_TRACE ("ACE_MEM_Acceptor::shared_accept_finish ()"); 00232 00233 ACE_HANDLE new_handle = new_stream.get_handle (); 00234 00235 // Check to see if we were originally in blocking mode, and if so, 00236 // set the <new_stream>'s handle and <this> handle to be in blocking 00237 // mode. 00238 if (in_blocking_mode) 00239 { 00240 // Save/restore errno. 00241 ACE_Errno_Guard error (errno); 00242 00243 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode 00244 // originally. 00245 ACE::clr_flags (this->get_handle (), 00246 ACE_NONBLOCK); 00247 ACE::clr_flags (new_handle, 00248 ACE_NONBLOCK); 00249 } 00250 00251 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) 00252 if (reset_new_handle) 00253 // Reset the event association inherited by the new handle. 00254 ::WSAEventSelect ((SOCKET) new_handle, 0, 0); 00255 #else 00256 ACE_UNUSED_ARG (reset_new_handle); 00257 #endif /* ACE_WIN32 */ 00258 if (new_handle == ACE_INVALID_HANDLE) 00259 return -1; 00260 00261 return 0; 00262 } |
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK_Acceptor. Definition at line 135 of file MEM_Acceptor.h. |
|
A cached MALLOC_OPTIONS. MEM_Accaptor use it to create the shared mamory malloc upon every incoming connection. Definition at line 177 of file MEM_Acceptor.h. Referenced by accept(), init_buffer_size(), and malloc_options(). |
|
The filename prefix of the created mmap files. It should contains the absolute path name of the file. Definition at line 173 of file MEM_Acceptor.h. Referenced by accept(), mmap_prefix(), and ~ACE_MEM_Acceptor(). |
|
Preferred signaling strategy.
Definition at line 180 of file MEM_Acceptor.h. Referenced by accept(), and preferred_strategy(). |