template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::register_handler (SVC_HANDLER *svc_handler, const ACE_Synch_Options &synch_options, int restart) { ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::register_handler"); // Can't do this if we don't have a Reactor. if (this->reactor () == 0) { errno = EINVAL; return -1; } else { this->svc_handler_ = svc_handler; this->restart_ = restart; ACE_Time_Value *tv = (ACE_Time_Value *) synch_options.time_value (); if (tv != 0 && this->reactor ()->schedule_timer (this, synch_options.arg (), *tv) == 0) return -1; else return this->reactor ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK); } }
template <typename SVC_HANDLER, typename PEER_CONNECTOR> int ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::nonblocking_connect (SVC_HANDLER *sh, const ACE_Synch_Options &synch_options) { ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::nonblocking_connect"); // Must have a valid Reactor for non-blocking connects to work. if (this->reactor () == 0) return -1; // Register the pending SVC_HANDLER so that it can be activated // later on when the connection completes. ACE_HANDLE handle = sh->get_handle (); long timer_id = -1; ACE_Time_Value *tv = 0; NBCH *nbch = 0; ACE_NEW_RETURN (nbch, NBCH (*this, sh, -1), -1); ACE_Event_Handler_var safe_nbch (nbch); // Exclusive access to the Reactor. ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->reactor ()->lock (), -1); // Register handle with the reactor for connection events. ACE_Reactor_Mask mask = ACE_Event_Handler::CONNECT_MASK; if (this->reactor ()->register_handler (handle, nbch, mask) == -1) goto reactor_registration_failure; // Add handle to non-blocking handle set. this->non_blocking_handles ().insert (handle); // If we're starting connection under timer control then we need to // schedule a timeout with the ACE_Reactor. tv = const_cast<ACE_Time_Value *> (synch_options.time_value ()); if (tv != 0) { timer_id = this->reactor ()->schedule_timer (nbch, synch_options.arg (), *tv); if (timer_id == -1) goto timer_registration_failure; // Remember timer id. nbch->timer_id (timer_id); } return 0; // Undo previous actions using the ol' "goto label and fallthru" // trick... timer_registration_failure: // Remove from Reactor. this->reactor ()->remove_handler (handle, mask); // Remove handle from the set of non-blocking handles. this->non_blocking_handles ().remove (handle); /* FALLTHRU */ reactor_registration_failure: // Close the svc_handler sh->close (CLOSE_DURING_NEW_CONNECTION); return -1; }