1 #ifndef ACE_CONNECTOR_CPP
2 #define ACE_CONNECTOR_CPP
4 #include "ace/Connector.h"
6 #include "ace/OS_NS_stdio.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/os_include/os_fcntl.h" /* Has ACE_NONBLOCK */
10 #if !defined (ACE_LACKS_PRAGMA_ONCE)
12 #endif /* ACE_LACKS_PRAGMA_ONCE */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE_Tc (ACE_NonBlocking_Connect_Handler
)
17 ACE_ALLOC_HOOK_DEFINE_Tco (ACE_Connector
)
18 ACE_ALLOC_HOOK_DEFINE_Tco (ACE_Strategy_Connector
)
20 template <typename SVC_HANDLER
>
21 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::ACE_NonBlocking_Connect_Handler (ACE_Connector_Base
<SVC_HANDLER
> &connector
,
24 : connector_ (connector
),
26 cleanup_svc_handler_ (0),
29 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::ACE_NonBlocking_Connect_Handler");
31 this->reference_counting_policy ().value
32 (ACE_Event_Handler::Reference_Counting_Policy::ENABLED
);
34 if (this->svc_handler_
!= 0 &&
35 this->svc_handler_
->reference_counting_policy ().value () ==
36 ACE_Event_Handler::Reference_Counting_Policy::ENABLED
)
38 // If SVC_HANDLER is reference counted then NBCH holds a reference
39 // in cleanup_svc_handle_ which is both a pointer to SVC_HANDLER
40 // and a flag that triggers remove_reference in NBCH destructor.
41 this->cleanup_svc_handler_
= sh
;
42 this->cleanup_svc_handler_
->add_reference ();
46 template <typename SVC_HANDLER
>
47 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::~ACE_NonBlocking_Connect_Handler ()
49 if (this->cleanup_svc_handler_
)
50 this->cleanup_svc_handler_
->remove_reference ();
53 template <typename SVC_HANDLER
> SVC_HANDLER
*
54 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::svc_handler ()
56 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::svc_handler");
57 return this->svc_handler_
;
60 template <typename SVC_HANDLER
> long
61 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::timer_id ()
63 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
64 return this->timer_id_
;
67 template <typename SVC_HANDLER
> void
68 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::timer_id (long id
)
70 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
74 template <typename SVC_HANDLER
> void
75 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::dump () const
77 #if defined (ACE_HAS_DUMP)
78 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::dump");
80 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
81 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("svc_handler_ = %x"), this->svc_handler_
));
82 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("\ntimer_id_ = %d"), this->timer_id_
));
83 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
84 #endif /* ACE_HAS_DUMP */
87 template <typename SVC_HANDLER
> bool
88 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::close (SVC_HANDLER
*&sh
)
90 // Make sure that we haven't already initialized the Svc_Handler.
91 if (!this->svc_handler_
)
95 // Exclusive access to the Reactor.
96 ACE_GUARD_RETURN (ACE_Lock
,
98 this->reactor ()->lock (),
102 if (!this->svc_handler_
)
105 // Remember the Svc_Handler.
106 sh
= this->svc_handler_
;
107 ACE_HANDLE
const h
= sh
->get_handle ();
108 this->svc_handler_
= 0;
110 // Remove this handle from the set of non-blocking handles
112 this->connector_
.non_blocking_handles ().remove (h
);
115 if (this->reactor ()->cancel_timer (this->timer_id (),
120 // Remove from Reactor.
121 if (-1 == this->reactor ()->remove_handler (
123 ACE_Event_Handler::ALL_EVENTS_MASK
| ACE_Event_Handler::DONT_CALL
))
131 template <typename SVC_HANDLER
> int
132 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::handle_timeout
133 (const ACE_Time_Value
&tv
,
136 // This method is called if a connection times out before completing.
137 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_timeout");
139 SVC_HANDLER
*svc_handler
= 0;
140 int const retval
= this->close (svc_handler
) ? 0 : -1;
142 // Forward to the SVC_HANDLER the <arg> that was passed in as a
143 // magic cookie during ACE_Connector::connect(). This gives the
144 // SVC_HANDLER an opportunity to take corrective action (e.g., wait
145 // a few milliseconds and try to reconnect again.
146 if (svc_handler
!= 0 && svc_handler
->handle_timeout (tv
, arg
) == -1)
147 svc_handler
->handle_close (svc_handler
->get_handle (),
148 ACE_Event_Handler::TIMER_MASK
);
154 template <typename SVC_HANDLER
> int
155 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::handle_input (ACE_HANDLE
)
157 // Called when a failure occurs during asynchronous connection
159 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_input");
161 SVC_HANDLER
*svc_handler
= 0;
162 int const retval
= this->close (svc_handler
) ? 0 : -1;
164 // Close Svc_Handler.
165 if (svc_handler
!= 0)
167 svc_handler
->close (NORMAL_CLOSE_OPERATION
);
173 template <typename SVC_HANDLER
> int
174 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::handle_close (ACE_HANDLE handle
,
177 // epoll on Linux will, at least sometimes, return EPOLLERR when a connect
178 // fails, triggering a total removal from the reactor. This is different from
179 // select()-based systems which select the fd for read on a connect failure.
180 // So just call handle_input() to rejoin common handling for a failed
182 if (m
== ACE_Event_Handler::ALL_EVENTS_MASK
)
183 return this->handle_input (handle
);
187 template <typename SVC_HANDLER
> int
188 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::handle_output (ACE_HANDLE handle
)
190 // Called when a connection is establishment asynchronous.
191 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_output");
193 // Grab the connector ref before smashing ourselves in close().
194 ACE_Connector_Base
<SVC_HANDLER
> &connector
= this->connector_
;
195 SVC_HANDLER
*svc_handler
= 0;
196 int const retval
= this->close (svc_handler
) ? 0 : -1;
198 if (svc_handler
!= 0)
200 connector
.initialize_svc_handler (handle
, svc_handler
);
206 template <typename SVC_HANDLER
> int
207 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::handle_exception (ACE_HANDLE h
)
209 // On Win32, the except mask must also be set for asynchronous
211 ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_exception");
212 return this->handle_output (h
);
215 template <typename SVC_HANDLER
> int
216 ACE_NonBlocking_Connect_Handler
<SVC_HANDLER
>::resume_handler ()
218 return ACE_Event_Handler::ACE_EVENT_HANDLER_NOT_RESUMED
;
221 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> void
222 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::dump () const
224 #if defined (ACE_HAS_DUMP)
225 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::dump");
227 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
228 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("\nflags_ = %d"), this->flags_
));
229 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
230 #endif /* ACE_HAS_DUMP */
233 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
234 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::make_svc_handler (SVC_HANDLER
*&sh
)
236 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::make_svc_handler");
243 // Set the reactor of the newly created <SVC_HANDLER> to the same
244 // reactor that this <Connector> is using.
245 sh
->reactor (this->reactor ());
249 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
250 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::activate_svc_handler (SVC_HANDLER
*svc_handler
)
252 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::activate_svc_handler");
253 // No errors initially
256 // See if we should enable non-blocking I/O on the <svc_handler>'s
258 if (ACE_BIT_ENABLED (this->flags_
, ACE_NONBLOCK
) != 0)
260 if (svc_handler
->peer ().enable (ACE_NONBLOCK
) == -1)
263 // Otherwise, make sure it's disabled by default.
264 else if (svc_handler
->peer ().disable (ACE_NONBLOCK
) == -1)
267 // We are connected now, so try to open things up.
268 if (error
|| svc_handler
->open ((void *) this) == -1)
270 // Make sure to close down the <svc_handler> to avoid descriptor
272 // The connection was already made; so this close is a "normal"
274 svc_handler
->close (NORMAL_CLOSE_OPERATION
);
281 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> PEER_CONNECTOR
&
282 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connector () const
284 return const_cast<PEER_CONNECTOR
&> (this->connector_
);
287 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
288 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_svc_handler
289 (SVC_HANDLER
*&svc_handler
,
290 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
291 ACE_Time_Value
*timeout
,
292 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
297 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::connect_svc_handler");
299 return this->connector_
.connect (svc_handler
->peer (),
308 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
309 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_svc_handler
310 (SVC_HANDLER
*&svc_handler
,
311 SVC_HANDLER
*&sh_copy
,
312 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
313 ACE_Time_Value
*timeout
,
314 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
319 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::connect_svc_handler");
321 sh_copy
= svc_handler
;
322 return this->connector_
.connect (svc_handler
->peer (),
331 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
332 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::open (ACE_Reactor
*r
, int flags
)
334 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::open");
336 this->flags_
= flags
;
340 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
>
341 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::ACE_Connector (ACE_Reactor
*r
, int flags
)
343 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::ACE_Connector");
344 (void) this->open (r
, flags
);
347 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
348 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect
350 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
351 const ACE_Synch_Options
&synch_options
,
352 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
357 // Initiate connection to peer.
358 return this->connect_i (sh
,
368 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
369 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect
371 SVC_HANDLER
*&sh_copy
,
372 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
373 const ACE_Synch_Options
&synch_options
,
374 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
379 // Initiate connection to peer.
380 return this->connect_i (sh
,
390 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
391 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_i
393 SVC_HANDLER
**sh_copy
,
394 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
395 const ACE_Synch_Options
&synch_options
,
396 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
401 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::connect_i");
403 // If the user hasn't supplied us with a <SVC_HANDLER> we'll use the
404 // factory method to create one. Otherwise, things will remain as
406 if (this->make_svc_handler (sh
) == -1)
409 ACE_Time_Value
*timeout
= 0;
410 int const use_reactor
= synch_options
[ACE_Synch_Options::USE_REACTOR
];
413 timeout
= const_cast<ACE_Time_Value
*> (&ACE_Time_Value::zero
);
415 timeout
= const_cast<ACE_Time_Value
*> (synch_options
.time_value ());
419 result
= this->connect_svc_handler (sh
,
427 result
= this->connect_svc_handler (sh
,
436 // Activate immediately if we are connected.
438 return this->activate_svc_handler (sh
);
440 // Delegate to connection strategy.
441 if (use_reactor
&& ACE_OS::last_error () == EWOULDBLOCK
)
443 // If the connection hasn't completed and we are using
444 // non-blocking semantics then register
445 // ACE_NonBlocking_Connect_Handler with the ACE_Reactor so that
446 // it will call us back when the connection is complete or we
447 // timeout, whichever comes first...
449 result
= this->nonblocking_connect (sh
, synch_options
);
451 result
= this->nonblocking_connect (*sh_copy
, synch_options
);
453 // If for some reason the <nonblocking_connect> call failed, then <errno>
454 // will be set to the new error. If the call succeeds, however,
455 // we need to make sure that <errno> remains set to
462 // Save/restore errno.
463 ACE_Errno_Guard
error (errno
);
464 // Make sure to close down the service handler to avoid handle
469 sh
->close (CLOSE_DURING_NEW_CONNECTION
);
472 (*sh_copy
)->close (CLOSE_DURING_NEW_CONNECTION
);
478 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
479 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_n
482 typename
PEER_CONNECTOR::PEER_ADDR remote_addrs
[],
483 ACE_TCHAR
*failed_svc_handlers
,
484 const ACE_Synch_Options
&synch_options
)
488 for (size_t i
= 0; i
< n
; i
++)
490 if (this->connect (sh
[i
], remote_addrs
[i
], synch_options
) == -1
491 && !(synch_options
[ACE_Synch_Options::USE_REACTOR
]
492 && errno
== EWOULDBLOCK
))
495 if (failed_svc_handlers
!= 0)
496 // Mark this entry as having failed.
497 failed_svc_handlers
[i
] = 1;
499 else if (failed_svc_handlers
!= 0)
500 // Mark this entry as having succeeded.
501 failed_svc_handlers
[i
] = 0;
507 // Cancel a <svc_handler> that was started asynchronously.
508 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
509 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::cancel (SVC_HANDLER
*sh
)
511 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::cancel");
513 ACE_Event_Handler
*handler
=
514 this->reactor ()->find_handler (sh
->get_handle ());
519 // find_handler() increments handler's refcount; ensure we decrement it.
520 ACE_Event_Handler_var
safe_handler (handler
);
523 dynamic_cast<NBCH
*> (handler
);
528 SVC_HANDLER
*tmp_sh
= 0;
530 if (nbch
->close (tmp_sh
) == false)
536 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
537 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::nonblocking_connect
539 const ACE_Synch_Options
&synch_options
)
541 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::nonblocking_connect");
543 // Must have a valid Reactor for non-blocking connects to work.
544 if (this->reactor () == 0)
547 // Register the pending SVC_HANDLER so that it can be activated
548 // later on when the connection completes.
550 ACE_HANDLE handle
= sh
->get_handle ();
552 ACE_Time_Value
*tv
= 0;
555 ACE_NEW_RETURN (nbch
,
561 ACE_Event_Handler_var
safe_nbch (nbch
);
563 // Exclusive access to the Reactor.
564 ACE_GUARD_RETURN (ACE_Lock
, ace_mon
, this->reactor ()->lock (), -1);
566 // Register handle with the reactor for connection events.
567 ACE_Reactor_Mask
const mask
= ACE_Event_Handler::CONNECT_MASK
;
568 if (this->reactor ()->register_handler (handle
,
571 goto reactor_registration_failure
;
573 // Add handle to non-blocking handle set.
574 this->non_blocking_handles ().insert (handle
);
576 // If we're starting connection under timer control then we need to
577 // schedule a timeout with the ACE_Reactor.
578 tv
= const_cast<ACE_Time_Value
*> (synch_options
.time_value ());
582 this->reactor ()->schedule_timer (nbch
,
583 synch_options
.arg (),
586 goto timer_registration_failure
;
588 // Remember timer id.
589 nbch
->timer_id (timer_id
);
594 // Undo previous actions using the ol' "goto label and fallthru"
596 timer_registration_failure
:
598 // Remove from Reactor.
599 this->reactor ()->remove_handler (handle
, mask
);
601 // Remove handle from the set of non-blocking handles.
602 this->non_blocking_handles ().remove (handle
);
606 reactor_registration_failure
:
607 // Close the svc_handler
609 sh
->close (CLOSE_DURING_NEW_CONNECTION
);
614 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
>
615 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::~ACE_Connector ()
617 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::~ACE_Connector");
622 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> void
623 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::initialize_svc_handler
625 SVC_HANDLER
*svc_handler
)
627 // Try to find out if the reactor uses event associations for the
628 // handles it waits on. If so we need to reset it.
629 bool const reset_new_handle
=
630 this->reactor ()->uses_event_associations ();
632 if (reset_new_handle
)
633 this->connector_
.reset_new_handle (handle
);
635 // Transfer ownership of the ACE_HANDLE to the SVC_HANDLER.
636 svc_handler
->set_handle (handle
);
638 typename
PEER_CONNECTOR::PEER_ADDR raddr
;
640 // Check to see if we're connected.
641 if (svc_handler
->peer ().get_remote_addr (raddr
) != -1)
642 this->activate_svc_handler (svc_handler
);
643 else // Somethings gone wrong, so close down...
645 #if defined (ACE_WIN32)
646 // Win32 (at least prior to Windows 2000) has a timing problem.
647 // If you check to see if the connection has completed too fast,
648 // it will fail - so wait 35 milliseconds to let it catch up.
649 ACE_Time_Value
tv (0, ACE_NON_BLOCKING_BUG_DELAY
);
651 if (svc_handler
->peer ().get_remote_addr (raddr
) != -1)
652 this->activate_svc_handler (svc_handler
);
653 else // do the svc handler close below...
654 #endif /* ACE_WIN32 */
655 svc_handler
->close (NORMAL_CLOSE_OPERATION
);
659 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> void
660 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::reactor (ACE_Reactor
*reactor
)
662 this->reactor_
= reactor
;
665 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> ACE_Reactor
*
666 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::reactor () const
668 return this->reactor_
;
671 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> ACE_Unbounded_Set
<ACE_HANDLE
> &
672 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::non_blocking_handles ()
674 return this->non_blocking_handles_
;
677 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
678 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::close ()
680 // If there are no non-blocking handle pending, return immediately.
681 if (this->non_blocking_handles ().size () == 0)
684 // Exclusive access to the Reactor.
685 ACE_GUARD_RETURN (ACE_Lock
, ace_mon
, this->reactor ()->lock (), -1);
687 // Go through all the non-blocking handles. It is necessary to
688 // create a new iterator each time because we remove from the handle
689 // set when we cancel the Svc_Handler.
690 ACE_HANDLE
*handle
= 0;
693 ACE_Unbounded_Set_Iterator
<ACE_HANDLE
>
694 iterator (this->non_blocking_handles ());
695 if (!iterator
.next (handle
))
698 ACE_Event_Handler
*handler
=
699 this->reactor ()->find_handler (*handle
);
702 ACELIB_ERROR ((LM_ERROR
,
703 ACE_TEXT ("%t: Connector::close h %d, no handler\n"),
705 // Remove handle from the set of non-blocking handles.
706 this->non_blocking_handles ().remove (*handle
);
710 // find_handler() incremented handler's refcount; ensure it's decremented
711 ACE_Event_Handler_var
safe_handler (handler
);
712 NBCH
*nbch
= dynamic_cast<NBCH
*> (handler
);
715 ACELIB_ERROR ((LM_ERROR
,
716 ACE_TEXT ("%t: Connector::close h %d handler %@ ")
717 ACE_TEXT ("not a legit handler\n"),
720 // Remove handle from the set of non-blocking handles.
721 this->non_blocking_handles ().remove (*handle
);
724 SVC_HANDLER
*svc_handler
= nbch
->svc_handler ();
726 // Cancel the non-blocking connection.
727 this->cancel (svc_handler
);
729 // Close the associated Svc_Handler.
730 svc_handler
->close (NORMAL_CLOSE_OPERATION
);
736 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
737 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::fini ()
739 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::fini");
741 return this->close ();
744 // Hook called by the explicit dynamic linking facility.
746 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
747 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::init (int, ACE_TCHAR
*[])
749 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::init");
753 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
754 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::suspend ()
756 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::suspend");
760 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
761 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::resume ()
763 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::resume");
767 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
768 ACE_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::info (ACE_TCHAR
**strp
, size_t length
) const
770 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::info");
771 ACE_TCHAR buf
[BUFSIZ
];
773 ACE_OS::snprintf (buf
, BUFSIZ
,
774 ACE_TEXT ("%s\t %s"),
775 ACE_TEXT ("ACE_Connector"),
776 ACE_TEXT ("# connector factory\n"));
778 if (*strp
== 0 && (*strp
= ACE_OS::strdup (buf
)) == 0)
781 ACE_OS::strsncpy (*strp
, buf
, length
);
782 return static_cast<int> (ACE_OS::strlen (buf
));
785 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
786 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::open (ACE_Reactor
*r
,
789 ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, PEER_CONNECTOR>::open");
790 return this->open (r
, 0, 0, 0, flags
);
793 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
794 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::open
796 ACE_Creation_Strategy
<SVC_HANDLER
> *cre_s
,
797 ACE_Connect_Strategy
<SVC_HANDLER
, PEER_CONNECTOR
> *conn_s
,
798 ACE_Concurrency_Strategy
<SVC_HANDLER
> *con_s
,
801 ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, PEER_CONNECTOR>::open");
805 // @@ Not implemented yet.
806 // this->flags_ = flags;
807 ACE_UNUSED_ARG (flags
);
809 // Initialize the creation strategy.
811 // First we decide if we need to clean up.
812 if (this->creation_strategy_
!= 0 &&
813 this->delete_creation_strategy_
&&
816 delete this->creation_strategy_
;
817 this->creation_strategy_
= 0;
818 this->delete_creation_strategy_
= false;
822 this->creation_strategy_
= cre_s
;
823 else if (this->creation_strategy_
== 0)
825 ACE_NEW_RETURN (this->creation_strategy_
,
826 CREATION_STRATEGY (0, r
),
828 this->delete_creation_strategy_
= true;
832 // Initialize the accept strategy.
834 if (this->connect_strategy_
!= 0 &&
835 this->delete_connect_strategy_
&&
838 delete this->connect_strategy_
;
839 this->connect_strategy_
= 0;
840 this->delete_connect_strategy_
= false;
844 this->connect_strategy_
= conn_s
;
845 else if (this->connect_strategy_
== 0)
847 ACE_NEW_RETURN (this->connect_strategy_
,
850 this->delete_connect_strategy_
= true;
853 // Initialize the concurrency strategy.
855 if (this->concurrency_strategy_
!= 0 &&
856 this->delete_concurrency_strategy_
&&
859 delete this->concurrency_strategy_
;
860 this->concurrency_strategy_
= 0;
861 this->delete_concurrency_strategy_
= false;
865 this->concurrency_strategy_
= con_s
;
866 else if (this->concurrency_strategy_
== 0)
868 ACE_NEW_RETURN (this->concurrency_strategy_
,
869 CONCURRENCY_STRATEGY
,
871 this->delete_concurrency_strategy_
= true;
877 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
>
878 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::ACE_Strategy_Connector
879 (ACE_Reactor
*reactor
,
880 ACE_Creation_Strategy
<SVC_HANDLER
> *cre_s
,
881 ACE_Connect_Strategy
<SVC_HANDLER
, PEER_CONNECTOR
> *conn_s
,
882 ACE_Concurrency_Strategy
<SVC_HANDLER
> *con_s
,
884 : base_type (reactor
),
885 creation_strategy_ (0),
886 delete_creation_strategy_ (false),
887 connect_strategy_ (0),
888 delete_connect_strategy_ (false),
889 concurrency_strategy_ (0),
890 delete_concurrency_strategy_ (false)
892 ACE_TRACE ("ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::ACE_Strategy_Connector");
894 if (this->open (reactor
, cre_s
, conn_s
, con_s
, flags
) == -1)
895 ACELIB_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Strategy_Connector::ACE_Strategy_Connector")));
898 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
>
899 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::~ACE_Strategy_Connector ()
901 ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, PEER_CONNECTOR>::~ACE_Strategy_Connector");
907 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
908 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::close ()
910 if (this->delete_creation_strategy_
)
911 delete this->creation_strategy_
;
912 this->delete_creation_strategy_
= false;
913 this->creation_strategy_
= 0;
915 if (this->delete_connect_strategy_
)
916 delete this->connect_strategy_
;
917 this->delete_connect_strategy_
= false;
918 this->connect_strategy_
= 0;
920 if (this->delete_concurrency_strategy_
)
921 delete this->concurrency_strategy_
;
922 this->delete_concurrency_strategy_
= false;
923 this->concurrency_strategy_
= 0;
925 return SUPER::close ();
928 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
929 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::make_svc_handler (SVC_HANDLER
*&sh
)
931 return this->creation_strategy_
->make_svc_handler (sh
);
934 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
935 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_svc_handler
937 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
938 ACE_Time_Value
*timeout
,
939 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
944 return this->connect_strategy_
->connect_svc_handler (sh
,
953 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
954 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_svc_handler
956 SVC_HANDLER
*&sh_copy
,
957 const typename
PEER_CONNECTOR::PEER_ADDR
&remote_addr
,
958 ACE_Time_Value
*timeout
,
959 const typename
PEER_CONNECTOR::PEER_ADDR
&local_addr
,
964 return this->connect_strategy_
->connect_svc_handler (sh
,
974 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> int
975 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::activate_svc_handler (SVC_HANDLER
*svc_handler
)
977 return this->concurrency_strategy_
->activate_svc_handler (svc_handler
, this);
980 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> ACE_Creation_Strategy
<SVC_HANDLER
> *
981 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::creation_strategy () const
983 return this->creation_strategy_
;
986 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> ACE_Connect_Strategy
<SVC_HANDLER
, PEER_CONNECTOR
> *
987 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::connect_strategy () const
989 return this->connect_strategy_
;
992 template <typename SVC_HANDLER
, typename PEER_CONNECTOR
> ACE_Concurrency_Strategy
<SVC_HANDLER
> *
993 ACE_Strategy_Connector
<SVC_HANDLER
, PEER_CONNECTOR
>::concurrency_strategy () const
995 return this->concurrency_strategy_
;
998 ACE_END_VERSIONED_NAMESPACE_DECL
1000 #endif /* ACE_CONNECTOR_C */