#include <Acceptor.h>
Inheritance diagram for ACE_Oneshot_Acceptor< SVC_HANDLER, >:
Public Types | |
typedef ACE_PEER_ACCEPTOR_ADDR | addr_type |
typedef ACE_PEER_ACCEPTOR | acceptor_type |
typedef SVC_HANDLER | handler_type |
typedef ACE_TYPENAME SVC_HANDLER::stream_type | stream_type |
Public Member Functions | |
ACE_Oneshot_Acceptor (void) | |
Constructor. | |
ACE_Oneshot_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, ACE_Reactor *reactor=ACE_Reactor::instance(), ACE_Concurrency_Strategy< SVC_HANDLER > *=0) | |
int | open (const ACE_PEER_ACCEPTOR_ADDR &, ACE_Reactor *reactor=ACE_Reactor::instance(), ACE_Concurrency_Strategy< SVC_HANDLER > *=0) |
virtual | ~ACE_Oneshot_Acceptor (void) |
Close down the {Oneshot_Acceptor}. | |
virtual int | accept (SVC_HANDLER *=0, ACE_PEER_ACCEPTOR_ADDR *remote_addr=0, const ACE_Synch_Options &synch_options=ACE_Synch_Options::defaults, int restart=1, int reset_new_handle=0) |
virtual int | cancel (void) |
Cancel a oneshot acceptor that was started asynchronously. | |
virtual | operator ACE_PEER_ACCEPTOR & () const |
Return the underlying {PEER_ACCEPTOR} object. | |
virtual ACE_PEER_ACCEPTOR & | acceptor (void) const |
Return the underlying {PEER_ACCEPTOR} object. | |
virtual int | close (void) |
Close down the {Oneshot_Acceptor}. | |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Member Functions | |
virtual int | activate_svc_handler (SVC_HANDLER *svc_handler) |
int | shared_accept (SVC_HANDLER *svc_handler, ACE_PEER_ACCEPTOR_ADDR *remote_addr, ACE_Time_Value *timeout, int restart, int reset_new_handle) |
virtual ACE_HANDLE | get_handle (void) const |
Returns the listening acceptor's {ACE_HANDLE}. | |
virtual int | handle_close (ACE_HANDLE=ACE_INVALID_HANDLE, ACE_Reactor_Mask=ACE_Event_Handler::ALL_EVENTS_MASK) |
virtual int | handle_input (ACE_HANDLE) |
virtual int | handle_timeout (const ACE_Time_Value &tv, const void *arg) |
Called when an acceptor times out... | |
virtual int | init (int argc, ACE_TCHAR *argv[]) |
virtual int | fini (void) |
virtual int | info (ACE_TCHAR **, size_t) const |
Default version returns address info in {buf}. | |
virtual int | suspend (void) |
virtual int | resume (void) |
Private Member Functions | |
int | register_handler (SVC_HANDLER *svc_handler, const ACE_Synch_Options &options, int restart) |
Private Attributes | |
SVC_HANDLER * | svc_handler_ |
Hold the svc_handler_ across asynchrony boundaries. | |
int | restart_ |
Hold the restart flag across asynchrony boundaries. | |
ACE_PEER_ACCEPTOR | peer_acceptor_ |
Factory that establishes connections passively. | |
ACE_Concurrency_Strategy< SVC_HANDLER > * | concurrency_strategy_ |
Concurrency strategy for an Acceptor. | |
int | delete_concurrency_strategy_ |
This class works similarly to the regular {ACE_Acceptor}, with the following differences: 1. This class doesn't automagically register {this} with the {ACE_Reactor} since it expects to have its {accept} method called directly. However, it stashes the {ACE_Reactor} pointer away in case it's needed later to finish accepting a connection asynchronously. 2. The class doesn't need an {ACE_Creation_Strategy} (since the user supplies the SVC_HANDLER) or an {ACE_Accept_Strategy} (since this class only accepts one connection and then removes all traces of itself from the {ACE_Reactor} if it was registered for asynchronous accepts).
Definition at line 520 of file Acceptor.h.
|
Definition at line 526 of file Acceptor.h. |
|
Definition at line 525 of file Acceptor.h. |
|
Definition at line 527 of file Acceptor.h. |
|
Definition at line 528 of file Acceptor.h. |
|
Constructor.
Definition at line 887 of file Acceptor.cpp. References ACE_TRACE, and ACE_Event_Handler::reactor().
00888 : delete_concurrency_strategy_ (0) 00889 { 00890 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::ACE_Oneshot_Acceptor"); 00891 this->reactor (0); 00892 } |
|
Initialize the appropriate strategies for concurrency and then open the {peer_acceptor} at the designated {local_addr}. Note that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this method does NOT register {this} acceptor with the {reactor} at this point -- it just stashes the {reactor} away in case it's needed later. Definition at line 896 of file Acceptor.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, and LM_ERROR.
00899 : delete_concurrency_strategy_ (0) 00900 { 00901 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::ACE_Oneshot_Acceptor"); 00902 if (this->open (local_addr, reactor, cs) == -1) 00903 ACE_ERROR ((LM_ERROR, 00904 ACE_LIB_TEXT ("%p\n"), 00905 ACE_LIB_TEXT ("ACE_Oneshot_Acceptor::ACE_Oneshot_Acceptor"))); 00906 } |
|
Close down the {Oneshot_Acceptor}.
Definition at line 909 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
00910 { 00911 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::~ACE_Oneshot_Acceptor"); 00912 this->handle_close (); 00913 } |
|
Create a {SVC_HANDLER}, accept the connection into the {SVC_HANDLER}, and activate the {SVC_HANDLER}. Definition at line 1067 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, and EWOULDBLOCK.
01072 { 01073 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept"); 01074 // Note that if timeout == ACE_Time_Value (x, y) where (x > 0 || y > 01075 // 0) then this->connector_.connect() will block synchronously. If 01076 // <use_reactor> is set then we don't want this to happen (since we 01077 // want the ACE_Reactor to do the timeout asynchronously). 01078 // Therefore, we'll force this->connector_ to use ACE_Time_Value (0, 01079 // 0) in this case... 01080 01081 ACE_Time_Value *timeout; 01082 int use_reactor = synch_options[ACE_Synch_Options::USE_REACTOR]; 01083 01084 if (use_reactor) 01085 timeout = (ACE_Time_Value *) &ACE_Time_Value::zero; 01086 else 01087 timeout = (ACE_Time_Value *) synch_options.time_value (); 01088 01089 if (this->shared_accept (svc_handler, // stream 01090 remote_addr, // remote address 01091 timeout, // timeout 01092 restart, // restart 01093 reset_new_handle // reset new handler 01094 ) == -1) 01095 { 01096 if (use_reactor && errno == EWOULDBLOCK) 01097 // We couldn't accept right away, so let's wait in the 01098 // <ACE_Reactor>. 01099 this->register_handler (svc_handler, 01100 synch_options, 01101 restart); 01102 return -1; 01103 } 01104 return 0; 01105 } |
|
Return the underlying {PEER_ACCEPTOR} object.
Definition at line 1213 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR, and ACE_TRACE.
01214 { 01215 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::acceptor"); 01216 return (ACE_PEER_ACCEPTOR &) this->peer_acceptor_; 01217 } |
|
Bridge method for activating a {svc_handler} with the appropriate concurrency strategy. Default behavior is to activate the {SVC_HANDLER} as a "passive object." However, subclasses can override this strategy to do more sophisticated concurrency activations (such as creating the {SVC_HANDLER} as an "active object" via multi-threading or multi-processing). Definition at line 1017 of file Acceptor.cpp. References ACE_TRACE.
01018 { 01019 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::activate_svc_handler"); 01020 return this->concurrency_strategy_->activate_svc_handler 01021 (svc_handler, 01022 (void *) this); 01023 } |
|
Cancel a oneshot acceptor that was started asynchronously.
Definition at line 970 of file Acceptor.cpp. References ACE_TRACE, ACE_Reactor::cancel_timer(), and ACE_Event_Handler::reactor(). Referenced by ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_input().
00971 { 00972 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::cancel"); 00973 return this->reactor () && this->reactor ()->cancel_timer (this); 00974 } |
|
Close down the {Oneshot_Acceptor}.
Definition at line 916 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
00917 { 00918 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::close"); 00919 return this->handle_close (); 00920 } |
|
Dump the state of an object.
Definition at line 846 of file Acceptor.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00847 { 00848 #if defined (ACE_HAS_DUMP) 00849 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::dump"); 00850 00851 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00852 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nsvc_handler_ = %x"), this->svc_handler_)); 00853 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nrestart_ = %d"), this->restart_)); 00854 this->peer_acceptor_.dump (); 00855 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("delete_concurrency_strategy_ = %d"), 00856 delete_concurrency_strategy_)); 00857 this->concurrency_strategy_->dump (); 00858 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00859 #endif /* ACE_HAS_DUMP */ 00860 } |
|
Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Shared_Object. Definition at line 1156 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
01157 { 01158 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::fini"); 01159 return this->handle_close (); 01160 } |
|
Returns the listening acceptor's {ACE_HANDLE}.
Reimplemented from ACE_Event_Handler. Definition at line 1206 of file Acceptor.cpp. References ACE_TRACE.
01207 { 01208 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::get_handle"); 01209 return this->peer_acceptor_.get_handle (); 01210 } |
|
Perform termination activities when {this} is removed from the {reactor}. Reimplemented from ACE_Event_Handler. Definition at line 923 of file Acceptor.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_Reactor_Mask, ACE_TRACE, LM_ERROR, ACE_Event_Handler::reactor(), and ACE_Reactor::remove_handler(). Referenced by ACE_Oneshot_Acceptor< SVC_HANDLER, >::close(), ACE_Oneshot_Acceptor< SVC_HANDLER, >::fini(), and ACE_Oneshot_Acceptor< SVC_HANDLER, >::~ACE_Oneshot_Acceptor().
00925 { 00926 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_close"); 00927 00928 // Guard against multiple closes. 00929 if (this->delete_concurrency_strategy_) 00930 { 00931 delete this->concurrency_strategy_; 00932 this->delete_concurrency_strategy_ = 0; 00933 this->concurrency_strategy_ = 0; 00934 } 00935 // Note that if we aren't actually registered with the 00936 // ACE_Reactor then it's ok for this call to fail... 00937 00938 if (this->reactor ()) 00939 this->reactor ()->remove_handler 00940 (this, 00941 ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL); 00942 00943 if (this->peer_acceptor_.close () == -1) 00944 ACE_ERROR ((LM_ERROR, 00945 ACE_LIB_TEXT ("close\n"))); 00946 return 0; 00947 } |
|
Accept one connection from a client and activates the SVC_HANDLER. Reimplemented from ACE_Event_Handler. Definition at line 1111 of file Acceptor.cpp. References ACE_TRACE, ACE_Oneshot_Acceptor< SVC_HANDLER, >::cancel(), ACE_Event_Handler::reactor(), ACE_Reactor::remove_handler(), ACE_Oneshot_Acceptor< SVC_HANDLER, >::shared_accept(), and ACE_Reactor::uses_event_associations().
01112 { 01113 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_input"); 01114 int result = 0; 01115 01116 // Cancel any timer that might be pending. 01117 this->cancel (); 01118 01119 // Try to find out if the implementation of the reactor that we are 01120 // using requires us to reset the event association for the newly 01121 // created handle. This is because the newly created handle will 01122 // inherit the properties of the listen handle, including its event 01123 // associations. 01124 int reset_new_handle = this->reactor ()->uses_event_associations (); 01125 01126 // There is a use-case whereby this object will be gone upon return 01127 // from shared_accept - if the Svc_Handler deletes this Oneshot_Acceptor 01128 // during the shared_accept/activation steps. So, do whatever we need 01129 // to do with this object before calling shared_accept. 01130 if (this->reactor ()) 01131 this->reactor ()->remove_handler 01132 (this, 01133 ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL); 01134 01135 if (this->shared_accept (this->svc_handler_, // stream 01136 0, // remote address 01137 0, // timeout 01138 this->restart_, // restart 01139 reset_new_handle // reset new handle 01140 ) == -1) 01141 result = -1; 01142 01143 return result; 01144 } |
|
Called when an acceptor times out...
Reimplemented from ACE_Event_Handler. Definition at line 951 of file Acceptor.cpp. References ACE_TRACE, and ETIME.
00953 { 00954 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_timeout"); 00955 errno = ETIME; 00956 00957 if (this->svc_handler_->handle_timeout (tv, arg) == -1) 00958 this->svc_handler_->handle_close (this->svc_handler_->get_handle (), 00959 ACE_Event_Handler::TIMER_MASK); 00960 00961 // Since we aren't necessarily registered with the Reactor, don't 00962 // bother to check the return value here... 00963 if (this->reactor ()) 00964 this->reactor ()->remove_handler (this, 00965 ACE_Event_Handler::ACCEPT_MASK); 00966 return 0; 00967 } |
|
Default version returns address info in {buf}.
Reimplemented from ACE_Shared_Object. Definition at line 1163 of file Acceptor.cpp. References ACE_LIB_TEXT, ACE_PEER_ACCEPTOR_ADDR, ACE_TCHAR, ACE_TRACE, ACE_OS::sprintf(), ACE_OS::strdup(), ACE_OS::strlen(), and ACE_OS::strsncpy().
01165 { 01166 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::info"); 01167 ACE_TCHAR buf[BUFSIZ]; 01168 ACE_TCHAR addr_str[BUFSIZ]; 01169 ACE_PEER_ACCEPTOR_ADDR addr; 01170 01171 if (this->peer_acceptor_.get_local_addr (addr) == -1) 01172 return -1; 01173 else if (addr.addr_to_string (addr_str, sizeof addr_str) == -1) 01174 return -1; 01175 01176 ACE_OS::sprintf (buf, 01177 ACE_LIB_TEXT ("%s\t %s %s"), 01178 ACE_LIB_TEXT ("ACE_Oneshot_Acceptor"), 01179 addr_str, 01180 ACE_LIB_TEXT ("#oneshot acceptor factory\n")); 01181 01182 if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) 01183 return -1; 01184 else 01185 ACE_OS::strsncpy (*strp, buf, length); 01186 return static_cast<int> (ACE_OS::strlen (buf)); 01187 } |
|
Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Shared_Object. Definition at line 1149 of file Acceptor.cpp. References ACE_TCHAR, and ACE_TRACE.
01150 { 01151 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::init"); 01152 return -1; 01153 } |
|
Initialize the appropriate strategies for concurrency and then open the {peer_acceptor} at the designated {local_addr}. Note that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this method does NOT register {this} acceptor with the {reactor} at this point -- it just stashes the {reactor} away in case it's needed later. Definition at line 864 of file Acceptor.cpp. References ACE_NEW_RETURN, ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, and ACE_Strategy_Acceptor< SVC_HANDLER, >::open().
00867 { 00868 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::open"); 00869 this->reactor (reactor); 00870 00871 // Initialize the concurrency strategy. 00872 00873 if (con_s == 0) 00874 { 00875 ACE_NEW_RETURN (con_s, 00876 ACE_Concurrency_Strategy<SVC_HANDLER>, 00877 -1); 00878 this->delete_concurrency_strategy_ = 1; 00879 } 00880 this->concurrency_strategy_ = con_s; 00881 00882 // Reuse the addr, even if it is already in use...! 00883 return this->peer_acceptor_.open (local_addr, 1); 00884 } |
|
Return the underlying {PEER_ACCEPTOR} object.
Definition at line 1220 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR, and ACE_TRACE.
01221 { 01222 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::operator ACE_PEER_ACCEPTOR &"); 01223 return (ACE_PEER_ACCEPTOR &) this->peer_acceptor_; 01224 } |
|
Insert ourselves into the {ACE_Reactor} so that we can continue accepting this connection asynchronously. This method should NOT be called by developers directly. Definition at line 978 of file Acceptor.cpp. References ACE_TRACE.
00981 { 00982 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::register_handler"); 00983 // Can't do this if we don't have a Reactor. 00984 if (this->reactor () == 0) 00985 { 00986 errno = EINVAL; 00987 return -1; 00988 } 00989 else 00990 { 00991 this->svc_handler_ = svc_handler; 00992 this->restart_ = restart; 00993 ACE_Time_Value *tv = (ACE_Time_Value *) synch_options.time_value (); 00994 00995 if (tv != 0 00996 && this->reactor ()->schedule_timer (this, 00997 synch_options.arg (), 00998 *tv) == 0) 00999 return -1; 01000 else 01001 return this->reactor ()->register_handler 01002 (this, 01003 ACE_Event_Handler::ACCEPT_MASK); 01004 } 01005 } |
|
Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Service_Object. Definition at line 1197 of file Acceptor.cpp. References ACE_TRACE, ACE_Event_Handler::reactor(), and ACE_Reactor::resume_handler().
01198 { 01199 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::resume"); 01200 return this->reactor () && this->reactor ()->resume_handler (this); 01201 } |
|
Factors out the code shared between the {accept} and {handle_input} methods. Definition at line 1030 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, ETIME, and EWOULDBLOCK. Referenced by ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_input().
01035 { 01036 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::shared_accept"); 01037 if (svc_handler == 0) 01038 return -1; 01039 01040 // Accept connection into the Svc_Handler. 01041 else if (this->peer_acceptor_.accept (svc_handler->peer (), // stream 01042 remote_addr, // remote address 01043 timeout, // timeout 01044 restart, // restart 01045 reset_new_handle // reset new handle 01046 ) == -1) 01047 { 01048 // Check whether we just timed out or whether we failed... 01049 if (!(errno == EWOULDBLOCK || errno == ETIME)) 01050 // Close down handler to avoid memory leaks. 01051 svc_handler->close (0); 01052 return -1; 01053 } 01054 // Activate the <svc_handler> using the designated concurrency 01055 // strategy (note that this method becomes responsible for handling 01056 // errors and freeing up the memory if things go awry...) 01057 else 01058 return this->activate_svc_handler (svc_handler); 01059 } |
|
Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Service_Object. Definition at line 1190 of file Acceptor.cpp. References ACE_TRACE, ACE_Event_Handler::reactor(), and ACE_Reactor::suspend_handler().
01191 { 01192 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::suspend"); 01193 return this->reactor () && this->reactor ()->suspend_handler (this); 01194 } |
|
Declare the dynamic allocation hooks.
Definition at line 585 of file Acceptor.h. |
|
Concurrency strategy for an Acceptor.
Definition at line 664 of file Acceptor.h. |
|
1 if Acceptor created the concurrency strategy and thus should delete it, else 0. Definition at line 668 of file Acceptor.h. |
|
Factory that establishes connections passively.
Definition at line 661 of file Acceptor.h. |
|
Hold the restart flag across asynchrony boundaries.
Definition at line 658 of file Acceptor.h. |
|
Hold the svc_handler_ across asynchrony boundaries.
Definition at line 655 of file Acceptor.h. |