#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 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 521 of file Acceptor.h.
|
Definition at line 527 of file Acceptor.h. |
|
Definition at line 526 of file Acceptor.h. |
|
Definition at line 528 of file Acceptor.h. |
|
Definition at line 529 of file Acceptor.h. |
|
Constructor.
Definition at line 885 of file Acceptor.cpp. References ACE_TRACE, and ACE_Event_Handler::reactor().
00886 : delete_concurrency_strategy_ (0) 00887 { 00888 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::ACE_Oneshot_Acceptor"); 00889 this->reactor (0); 00890 } |
|
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 894 of file Acceptor.cpp. References ACE_ERROR, ACE_PEER_ACCEPTOR_ADDR, ACE_TEXT, ACE_TRACE, and LM_ERROR.
00897 : delete_concurrency_strategy_ (0) 00898 { 00899 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::ACE_Oneshot_Acceptor"); 00900 if (this->open (local_addr, reactor, cs) == -1) 00901 ACE_ERROR ((LM_ERROR, 00902 ACE_TEXT ("%p\n"), 00903 ACE_TEXT ("ACE_Oneshot_Acceptor::ACE_Oneshot_Acceptor"))); 00904 } |
|
Close down the {Oneshot_Acceptor}.
Definition at line 907 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
00908 { 00909 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::~ACE_Oneshot_Acceptor"); 00910 this->handle_close (); 00911 } |
|
Create a {SVC_HANDLER}, accept the connection into the {SVC_HANDLER}, and activate the {SVC_HANDLER}. Definition at line 1065 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, and EWOULDBLOCK.
01070 { 01071 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept"); 01072 // Note that if timeout == ACE_Time_Value (x, y) where (x > 0 || y > 01073 // 0) then this->connector_.connect() will block synchronously. If 01074 // <use_reactor> is set then we don't want this to happen (since we 01075 // want the ACE_Reactor to do the timeout asynchronously). 01076 // Therefore, we'll force this->connector_ to use ACE_Time_Value (0, 01077 // 0) in this case... 01078 01079 ACE_Time_Value *timeout; 01080 int use_reactor = synch_options[ACE_Synch_Options::USE_REACTOR]; 01081 01082 if (use_reactor) 01083 timeout = (ACE_Time_Value *) &ACE_Time_Value::zero; 01084 else 01085 timeout = (ACE_Time_Value *) synch_options.time_value (); 01086 01087 if (this->shared_accept (svc_handler, // stream 01088 remote_addr, // remote address 01089 timeout, // timeout 01090 restart, // restart 01091 reset_new_handle // reset new handler 01092 ) == -1) 01093 { 01094 if (use_reactor && errno == EWOULDBLOCK) 01095 // We couldn't accept right away, so let's wait in the 01096 // <ACE_Reactor>. 01097 this->register_handler (svc_handler, 01098 synch_options, 01099 restart); 01100 return -1; 01101 } 01102 return 0; 01103 } |
|
Return the underlying {PEER_ACCEPTOR} object.
Definition at line 1211 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR, and ACE_TRACE.
01212 { 01213 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::acceptor"); 01214 return (ACE_PEER_ACCEPTOR &) this->peer_acceptor_; 01215 } |
|
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 1015 of file Acceptor.cpp. References ACE_TRACE.
01016 { 01017 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::activate_svc_handler"); 01018 return this->concurrency_strategy_->activate_svc_handler 01019 (svc_handler, 01020 (void *) this); 01021 } |
|
Cancel a oneshot acceptor that was started asynchronously.
Definition at line 968 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().
00969 { 00970 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::cancel"); 00971 return this->reactor () && this->reactor ()->cancel_timer (this); 00972 } |
|
Close down the {Oneshot_Acceptor}.
Definition at line 914 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
00915 { 00916 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::close"); 00917 return this->handle_close (); 00918 } |
|
Dump the state of an object.
Definition at line 844 of file Acceptor.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, and LM_DEBUG.
00845 { 00846 #if defined (ACE_HAS_DUMP) 00847 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::dump"); 00848 00849 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00850 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nsvc_handler_ = %x"), this->svc_handler_)); 00851 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nrestart_ = %d"), this->restart_)); 00852 this->peer_acceptor_.dump (); 00853 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("delete_concurrency_strategy_ = %d"), 00854 delete_concurrency_strategy_)); 00855 this->concurrency_strategy_->dump (); 00856 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00857 #endif /* ACE_HAS_DUMP */ 00858 } |
|
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 1154 of file Acceptor.cpp. References ACE_TRACE, and ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_close().
01155 { 01156 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::fini"); 01157 return this->handle_close (); 01158 } |
|
Returns the listening acceptor's {ACE_HANDLE}.
Reimplemented from ACE_Event_Handler. Definition at line 1204 of file Acceptor.cpp. References ACE_TRACE.
01205 { 01206 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::get_handle"); 01207 return this->peer_acceptor_.get_handle (); 01208 } |
|
Perform termination activities when {this} is removed from the {reactor}. Reimplemented from ACE_Event_Handler. Definition at line 921 of file Acceptor.cpp. References ACE_ERROR, ACE_Reactor_Mask, ACE_TEXT, 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().
00923 { 00924 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_close"); 00925 00926 // Guard against multiple closes. 00927 if (this->delete_concurrency_strategy_) 00928 { 00929 delete this->concurrency_strategy_; 00930 this->delete_concurrency_strategy_ = 0; 00931 this->concurrency_strategy_ = 0; 00932 } 00933 // Note that if we aren't actually registered with the 00934 // ACE_Reactor then it's ok for this call to fail... 00935 00936 if (this->reactor ()) 00937 this->reactor ()->remove_handler 00938 (this, 00939 ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL); 00940 00941 if (this->peer_acceptor_.close () == -1) 00942 ACE_ERROR ((LM_ERROR, 00943 ACE_TEXT ("close\n"))); 00944 return 0; 00945 } |
|
Accept one connection from a client and activates the SVC_HANDLER. Reimplemented from ACE_Event_Handler. Definition at line 1109 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().
01110 { 01111 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_input"); 01112 int result = 0; 01113 01114 // Cancel any timer that might be pending. 01115 this->cancel (); 01116 01117 // Try to find out if the implementation of the reactor that we are 01118 // using requires us to reset the event association for the newly 01119 // created handle. This is because the newly created handle will 01120 // inherit the properties of the listen handle, including its event 01121 // associations. 01122 int reset_new_handle = this->reactor ()->uses_event_associations (); 01123 01124 // There is a use-case whereby this object will be gone upon return 01125 // from shared_accept - if the Svc_Handler deletes this Oneshot_Acceptor 01126 // during the shared_accept/activation steps. So, do whatever we need 01127 // to do with this object before calling shared_accept. 01128 if (this->reactor ()) 01129 this->reactor ()->remove_handler 01130 (this, 01131 ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL); 01132 01133 if (this->shared_accept (this->svc_handler_, // stream 01134 0, // remote address 01135 0, // timeout 01136 this->restart_, // restart 01137 reset_new_handle // reset new handle 01138 ) == -1) 01139 result = -1; 01140 01141 return result; 01142 } |
|
Called when an acceptor times out...
Reimplemented from ACE_Event_Handler. Definition at line 949 of file Acceptor.cpp. References ACE_TRACE, and ETIME.
00951 { 00952 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_timeout"); 00953 errno = ETIME; 00954 00955 if (this->svc_handler_->handle_timeout (tv, arg) == -1) 00956 this->svc_handler_->handle_close (this->svc_handler_->get_handle (), 00957 ACE_Event_Handler::TIMER_MASK); 00958 00959 // Since we aren't necessarily registered with the Reactor, don't 00960 // bother to check the return value here... 00961 if (this->reactor ()) 00962 this->reactor ()->remove_handler (this, 00963 ACE_Event_Handler::ACCEPT_MASK); 00964 return 0; 00965 } |
|
Default version returns address info in {buf}.
Reimplemented from ACE_Shared_Object. Definition at line 1161 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR_ADDR, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE_OS::sprintf(), ACE_OS::strdup(), ACE_OS::strlen(), and ACE_OS::strsncpy().
01163 { 01164 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::info"); 01165 ACE_TCHAR buf[BUFSIZ]; 01166 ACE_TCHAR addr_str[BUFSIZ]; 01167 ACE_PEER_ACCEPTOR_ADDR addr; 01168 01169 if (this->peer_acceptor_.get_local_addr (addr) == -1) 01170 return -1; 01171 else if (addr.addr_to_string (addr_str, sizeof addr_str) == -1) 01172 return -1; 01173 01174 ACE_OS::sprintf (buf, 01175 ACE_TEXT ("%s\t %s %s"), 01176 ACE_TEXT ("ACE_Oneshot_Acceptor"), 01177 addr_str, 01178 ACE_TEXT ("#oneshot acceptor factory\n")); 01179 01180 if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) 01181 return -1; 01182 else 01183 ACE_OS::strsncpy (*strp, buf, length); 01184 return static_cast<int> (ACE_OS::strlen (buf)); 01185 } |
|
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 1147 of file Acceptor.cpp. References ACE_TCHAR, and ACE_TRACE.
01148 { 01149 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::init"); 01150 return -1; 01151 } |
|
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 862 of file Acceptor.cpp. References ACE_NEW_RETURN, ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, and ACE_Strategy_Acceptor< SVC_HANDLER, >::open().
00865 { 00866 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::open"); 00867 this->reactor (reactor); 00868 00869 // Initialize the concurrency strategy. 00870 00871 if (con_s == 0) 00872 { 00873 ACE_NEW_RETURN (con_s, 00874 ACE_Concurrency_Strategy<SVC_HANDLER>, 00875 -1); 00876 this->delete_concurrency_strategy_ = 1; 00877 } 00878 this->concurrency_strategy_ = con_s; 00879 00880 // Reuse the addr, even if it is already in use...! 00881 return this->peer_acceptor_.open (local_addr, 1); 00882 } |
|
Return the underlying {PEER_ACCEPTOR} object.
Definition at line 1218 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR, and ACE_TRACE.
01219 { 01220 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::operator ACE_PEER_ACCEPTOR &"); 01221 return (ACE_PEER_ACCEPTOR &) this->peer_acceptor_; 01222 } |
|
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 976 of file Acceptor.cpp. References ACE_TRACE.
00979 { 00980 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::register_handler"); 00981 // Can't do this if we don't have a Reactor. 00982 if (this->reactor () == 0) 00983 { 00984 errno = EINVAL; 00985 return -1; 00986 } 00987 else 00988 { 00989 this->svc_handler_ = svc_handler; 00990 this->restart_ = restart; 00991 ACE_Time_Value *tv = (ACE_Time_Value *) synch_options.time_value (); 00992 00993 if (tv != 0 00994 && this->reactor ()->schedule_timer (this, 00995 synch_options.arg (), 00996 *tv) == 0) 00997 return -1; 00998 else 00999 return this->reactor ()->register_handler 01000 (this, 01001 ACE_Event_Handler::ACCEPT_MASK); 01002 } 01003 } |
|
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 1195 of file Acceptor.cpp. References ACE_TRACE, ACE_Event_Handler::reactor(), and ACE_Reactor::resume_handler().
01196 { 01197 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::resume"); 01198 return this->reactor () && this->reactor ()->resume_handler (this); 01199 } |
|
Factors out the code shared between the {accept} and {handle_input} methods. Definition at line 1028 of file Acceptor.cpp. References ACE_PEER_ACCEPTOR_ADDR, ACE_TRACE, ETIME, and EWOULDBLOCK. Referenced by ACE_Oneshot_Acceptor< SVC_HANDLER, >::handle_input().
01033 { 01034 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::shared_accept"); 01035 if (svc_handler == 0) 01036 return -1; 01037 01038 // Accept connection into the Svc_Handler. 01039 else if (this->peer_acceptor_.accept (svc_handler->peer (), // stream 01040 remote_addr, // remote address 01041 timeout, // timeout 01042 restart, // restart 01043 reset_new_handle // reset new handle 01044 ) == -1) 01045 { 01046 // Check whether we just timed out or whether we failed... 01047 if (!(errno == EWOULDBLOCK || errno == ETIME)) 01048 // Close down handler to avoid memory leaks. 01049 svc_handler->close (0); 01050 return -1; 01051 } 01052 // Activate the <svc_handler> using the designated concurrency 01053 // strategy (note that this method becomes responsible for handling 01054 // errors and freeing up the memory if things go awry...) 01055 else 01056 return this->activate_svc_handler (svc_handler); 01057 } |
|
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 1188 of file Acceptor.cpp. References ACE_TRACE, ACE_Event_Handler::reactor(), and ACE_Reactor::suspend_handler().
01189 { 01190 ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::suspend"); 01191 return this->reactor () && this->reactor ()->suspend_handler (this); 01192 } |
|
Declare the dynamic allocation hooks.
Definition at line 586 of file Acceptor.h. |
|
Concurrency strategy for an Acceptor.
Definition at line 665 of file Acceptor.h. |
|
1 if Acceptor created the concurrency strategy and thus should delete it, else 0. Definition at line 669 of file Acceptor.h. |
|
Factory that establishes connections passively.
Definition at line 662 of file Acceptor.h. |
|
Hold the restart flag across asynchrony boundaries.
Definition at line 659 of file Acceptor.h. |
|
Hold the svc_handler_ across asynchrony boundaries.
Definition at line 656 of file Acceptor.h. |