Fixed typos
[ACE_TAO.git] / ACE / ace / Acceptor.h
blobda7834cc9e80d61d3685a6490e4d8df5db8e3548
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Acceptor.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_ACCEPTOR_H
12 #define ACE_ACCEPTOR_H
14 #include /**/ "ace/pre.h"
16 #include "ace/Service_Object.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Strategies_T.h"
23 #include "ace/Synch_Options.h"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 /**
28 * @class ACE_Acceptor
30 * @brief Abstract factory for creating a service handler
31 * (SVC_HANDLER), accepting into the SVC_HANDLER, and
32 * activating the SVC_HANDLER.
34 * Implements the basic strategy for passively establishing
35 * connections with clients. An ACE_Acceptor inherits from
36 * ACE_Service_Object, which in turn inherits from ACE_Event_Handler.
37 * This enables the ACE_Reactor to dispatch the ACE_Acceptor's
38 * handle_input method when connection events occur. The handle_input
39 * method performs the ACE_Acceptor's default creation, connection
40 * establishment, and service activation strategies. These strategies
41 * can be overridden by subclasses individually or as a group.
43 * An ACE_Acceptor is parameterized by concrete types that conform to
44 * the interfaces of SVC_HANDLER and PEER_ACCEPTOR described below.
46 * @tparam SVC_HANDLER The name of the concrete type that performs the
47 * application-specific service. The SVC_HANDLER typically
48 * inherits from ACE_Svc_Handler. @see Svc_Handler.h.
50 * @tparam PEER_ACCEPTOR The name of the class that implements the
51 * PEER_ACCEPTOR endpoint (e.g., ACE_SOCK_Acceptor) to
52 * passively establish connections. A PEER_ACCEPTOR
53 * implementation must provide a PEER_STREAM and PEER_ADDR
54 * trait to identify the type of stream (e.g.,
55 * ACE_SOCK_Stream) and type of address (e.g., ACE_INET_Addr)
56 * used by the endpoint.
58 template <typename SVC_HANDLER, typename PEER_ACCEPTOR>
59 class ACE_Acceptor : public ACE_Service_Object
61 public:
62 // Useful STL-style traits.
63 typedef typename PEER_ACCEPTOR::PEER_ADDR addr_type;
64 typedef PEER_ACCEPTOR acceptor_type;
65 typedef SVC_HANDLER handler_type;
66 typedef typename SVC_HANDLER::stream_type stream_type;
68 /// "Do-nothing" constructor.
69 ACE_Acceptor (ACE_Reactor * = 0,
70 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT);
72 /**
73 * Open the contained @c PEER_ACCEPTOR object to begin listening, and
74 * register with the specified reactor for accept events. An
75 * acceptor can only listen to one port at a time, so make sure to
76 * @c close() the acceptor before calling @c open() again.
78 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a
79 * safeguard against the race condition that can otherwise occur
80 * between the time when the passive-mode socket handle is "ready"
81 * and when the actual @c accept() call is made. During this
82 * interval, the client can shutdown the connection, in which case,
83 * the @c accept() call can hang.
85 * @param local_addr The address to listen at.
86 * @param reactor Pointer to the ACE_Reactor instance to register
87 * this object with. The default is the singleton.
88 * @param flags Flags to control what mode an accepted socket
89 * will be put into after it is accepted. The only
90 * legal value for this argument is @c ACE_NONBLOCK,
91 * which enables non-blocking mode on the accepted
92 * peer stream object in @c SVC_HANDLER. The default
93 * is 0.
94 * @param use_select Affects behavior when called back by the reactor
95 * when a connection can be accepted. If non-zero,
96 * this object will accept all pending connections,
97 * instead of just the one that triggered the reactor
98 * callback. Uses ACE_OS::select() internally to
99 * detect any remaining acceptable connections.
100 * The default is 1.
101 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with
102 * @p local_addr. Generally used to request that the
103 * OS allow reuse of the listen port. The default is 1.
105 ACE_Acceptor (const typename PEER_ACCEPTOR::PEER_ADDR &local_addr,
106 ACE_Reactor *reactor = ACE_Reactor::instance (),
107 int flags = 0,
108 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
109 int reuse_addr = 1);
112 * Open the contained @c PEER_ACCEPTOR object to begin listening, and
113 * register with the specified reactor for accept events. An
114 * acceptor can only listen to one port at a time, so make sure to
115 * @c close() the acceptor before calling @c open() again.
117 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a
118 * safeguard against the race condition that can otherwise occur
119 * between the time when the passive-mode socket handle is "ready"
120 * and when the actual @c accept() call is made. During this
121 * interval, the client can shutdown the connection, in which case,
122 * the @c accept() call can hang.
124 * @param local_addr The address to listen at.
125 * @param reactor Pointer to the ACE_Reactor instance to register
126 * this object with. The default is the singleton.
127 * @param flags Flags to control what mode an accepted socket
128 * will be put into after it is accepted. The only
129 * legal value for this argument is @c ACE_NONBLOCK,
130 * which enables non-blocking mode on the accepted
131 * peer stream object in @c SVC_HANDLER. The default
132 * is 0.
133 * @param use_select Affects behavior when called back by the reactor
134 * when a connection can be accepted. If non-zero,
135 * this object will accept all pending connections,
136 * instead of just the one that triggered the reactor
137 * callback. Uses ACE_OS::select() internally to
138 * detect any remaining acceptable connections.
139 * The default is 1.
140 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with
141 * @p local_addr. Generally used to request that the
142 * OS allow reuse of the listen port. The default is 1.
144 * @retval 0 Success
145 * @retval -1 Failure, @c errno contains an error code.
147 virtual int open (const typename PEER_ACCEPTOR::PEER_ADDR &local_addr,
148 ACE_Reactor *reactor = ACE_Reactor::instance (),
149 int flags = 0,
150 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
151 int reuse_addr = 1);
153 /// Close down the Acceptor's resources.
154 virtual ~ACE_Acceptor (void);
156 /// Return the underlying PEER_ACCEPTOR object.
157 virtual operator PEER_ACCEPTOR &() const;
159 /// Return the underlying PEER_ACCEPTOR object.
160 virtual PEER_ACCEPTOR &acceptor (void) const;
162 /// Returns the listening acceptor's {ACE_HANDLE}.
163 virtual ACE_HANDLE get_handle (void) const;
165 /// Close down the Acceptor
166 virtual int close (void);
168 /// In the event that an accept fails, this method will be called and
169 /// the return value will be returned from handle_input().
170 virtual int handle_accept_error (void);
172 /// Dump the state of an object.
173 void dump (void) const;
175 /// Declare the dynamic allocation hooks.
176 ACE_ALLOC_HOOK_DECLARE;
178 protected:
179 // = The following three methods define the Acceptor's strategies
180 // for creating, accepting, and activating SVC_HANDLER's,
181 // respectively.
184 * Bridge method for creating a SVC_HANDLER. The default is to
185 * create a new {SVC_HANDLER} if {sh} == 0, else {sh} is unchanged.
186 * However, subclasses can override this policy to perform
187 * SVC_HANDLER creation in any way that they like (such as creating
188 * subclass instances of SVC_HANDLER, using a singleton, dynamically
189 * linking the handler, etc.). Returns -1 on failure, else 0.
191 virtual int make_svc_handler (SVC_HANDLER *&sh);
194 * Bridge method for accepting the new connection into the
195 * @a svc_handler. The default behavior delegates to the
196 * PEER_ACCEPTOR::accept.
198 virtual int accept_svc_handler (SVC_HANDLER *svc_handler);
201 * Bridge method for activating a @a svc_handler with the appropriate
202 * concurrency strategy. The default behavior of this method is to
203 * activate the SVC_HANDLER by calling its open() method (which
204 * allows the SVC_HANDLER to define its own concurrency strategy).
205 * However, subclasses can override this strategy to do more
206 * sophisticated concurrency activations (such as making the
207 * SVC_HANDLER as an "active object" via multi-threading or
208 * multi-processing).
210 virtual int activate_svc_handler (SVC_HANDLER *svc_handler);
212 // = Demultiplexing hooks.
213 /// Perform termination activities when {this} is removed from the
214 /// {reactor}.
215 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
216 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
218 /// Accepts all pending connections from clients, and creates and
219 /// activates SVC_HANDLERs.
220 virtual int handle_input (ACE_HANDLE);
222 // = Dynamic linking hooks.
223 /// Default version does no work and returns -1. Must be overloaded
224 /// by application developer to do anything meaningful.
225 virtual int init (int argc, ACE_TCHAR *argv[]);
227 /// Calls {handle_close}.
228 virtual int fini (void);
230 /// Default version returns address info in {buf}.
231 virtual int info (ACE_TCHAR **buf, size_t) const;
233 public:
234 // = Service management hooks.
235 /// This method calls {Reactor::suspend}.
236 virtual int suspend (void);
238 /// This method calls {Reactor::resume}.
239 virtual int resume (void);
241 protected:
242 /// Concrete factory for accepting connections from clients...
243 PEER_ACCEPTOR peer_acceptor_;
245 /// Needed to reopen the socket if {accept} fails.
246 typename PEER_ACCEPTOR::PEER_ADDR peer_acceptor_addr_;
249 * Flags that indicate how {SVC_HANDLER}'s should be initialized
250 * prior to being activated. Right now, the only flag that is
251 * processed is {ACE_NONBLOCK}, which enabled non-blocking I/O on
252 * the {SVC_HANDLER} when it is opened.
254 int flags_;
256 /// Flag that indicates whether it shall use {select} in the
257 /// {accept}-loop.
258 int use_select_;
260 /// Needed to reopen the socket if {accept} fails.
261 int reuse_addr_;
265 * @class ACE_Strategy_Acceptor
267 * @brief Abstract factory for creating a service handler
268 * (SVC_HANDLER), accepting into the SVC_HANDLER, and activating
269 * the SVC_HANDLER.
271 * Implements a flexible and extensible set of strategies for
272 * passively establishing connections with clients. There are
273 * three main strategies: (1) creating a SVC_HANDLER, (2)
274 * passively accepting a new connection from a client into the
275 * SVC_HANDLER, and (3) activating the SVC_HANDLER with a
276 * particular concurrency mechanism.
278 template <typename SVC_HANDLER, typename PEER_ACCEPTOR>
279 class ACE_Strategy_Acceptor
280 : public ACE_Acceptor <SVC_HANDLER, PEER_ACCEPTOR>
282 public:
283 // Useful STL-style traits.
284 typedef ACE_Creation_Strategy<SVC_HANDLER>
285 creation_strategy_type;
286 typedef ACE_Accept_Strategy<SVC_HANDLER, PEER_ACCEPTOR>
287 accept_strategy_type;
288 typedef ACE_Concurrency_Strategy<SVC_HANDLER>
289 concurrency_strategy_type;
290 typedef ACE_Scheduling_Strategy<SVC_HANDLER> scheduling_strategy_type;
291 typedef ACE_Acceptor <SVC_HANDLER, PEER_ACCEPTOR>
292 base_type;
294 // = Define some useful (old style) traits.
295 typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;
296 typedef ACE_Accept_Strategy<SVC_HANDLER, PEER_ACCEPTOR> ACCEPT_STRATEGY;
297 typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;
298 typedef ACE_Scheduling_Strategy<SVC_HANDLER> SCHEDULING_STRATEGY;
300 /// Default constructor.
301 ACE_Strategy_Acceptor (const ACE_TCHAR service_name[] = 0,
302 const ACE_TCHAR service_description[] = 0,
303 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
304 int reuse_addr = 1);
307 * Initialize the appropriate strategies for creation, passive
308 * connection acceptance, and concurrency, and then register {this}
309 * with the Reactor and listen for connection requests at the
310 * designated {local_addr}.
312 ACE_Strategy_Acceptor (const typename PEER_ACCEPTOR::PEER_ADDR &local_addr,
313 ACE_Reactor * = ACE_Reactor::instance (),
314 ACE_Creation_Strategy<SVC_HANDLER> * = 0,
315 ACE_Accept_Strategy<SVC_HANDLER, PEER_ACCEPTOR> * = 0,
316 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
317 ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
318 const ACE_TCHAR service_name[] = 0,
319 const ACE_TCHAR service_description[] = 0,
320 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
321 int reuse_addr = 1);
324 * Open the contained @c PEER_ACCEPTOR object to begin listening, and
325 * register with the specified reactor for accept events.
327 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a
328 * safeguard against the race condition that can otherwise occur
329 * between the time when the passive-mode socket handle is "ready"
330 * and when the actual @c accept call is made. During this
331 * interval, the client can shutdown the connection, in which case,
332 * the {accept} call can hang.
334 * @param local_addr The address to listen at.
335 * @param reactor Pointer to the ACE_Reactor instance to register
336 * this object with. The default is the singleton.
337 * @param flags Flags to control what mode an accepted socket
338 * will be put into after it is accepted. The only
339 * legal value for this argument is @c ACE_NONBLOCK,
340 * which enables non-blocking mode on the accepted
341 * peer stream object in @c SVC_HANDLER. The default
342 * is 0.
343 * @param use_select Affects behavior when called back by the reactor
344 * when a connection can be accepted. If non-zero,
345 * this object will accept all pending connections,
346 * instead of just the one that triggered the reactor
347 * callback. Uses ACE_OS::select() internally to
348 * detect any remaining acceptable connections.
349 * The default is 1.
350 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with
351 * @p local_addr. Generally used to request that the
352 * OS allow reuse of the listen port. The default is 1.
354 * @retval 0 Success
355 * @retval -1 Failure, @c errno contains an error code.
357 virtual int open (const typename PEER_ACCEPTOR::PEER_ADDR &local_addr,
358 ACE_Reactor *reactor,
359 int flags = 0,
360 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
361 int reuse_addr = 1);
364 * Initialize the appropriate strategies for creation, passive
365 * connection acceptance, and concurrency, and then register {this}
366 * with the Reactor and listen for connection requests at the
367 * designated {local_addr}.
369 virtual int open (const typename PEER_ACCEPTOR::PEER_ADDR &,
370 ACE_Reactor * = ACE_Reactor::instance (),
371 ACE_Creation_Strategy<SVC_HANDLER> * = 0,
372 ACE_Accept_Strategy<SVC_HANDLER, PEER_ACCEPTOR> * =0,
373 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
374 ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
375 const ACE_TCHAR *service_name = 0,
376 const ACE_TCHAR *service_description = 0,
377 int use_select = ACE_DEFAULT_ACCEPTOR_USE_SELECT,
378 int reuse_addr = 1);
380 /// Close down the Strategy_Acceptor's resources.
381 virtual ~ACE_Strategy_Acceptor (void);
383 /// Return the underlying PEER_ACCEPTOR object.
384 virtual operator PEER_ACCEPTOR &() const;
386 /// Return the underlying PEER_ACCEPTOR object.
387 virtual PEER_ACCEPTOR &acceptor (void) const;
389 /// Returns the listening acceptor's {ACE_HANDLE}.
390 virtual ACE_HANDLE get_handle (void) const;
392 /// Dump the state of an object.
393 void dump (void) const;
395 /// Declare the dynamic allocation hooks.
396 ACE_ALLOC_HOOK_DECLARE;
398 // = Service management hooks.
400 /// This method delegates to the {Scheduling_Strategy}'s {suspend}
401 /// method.
402 virtual int suspend (void);
404 /// This method delegates to the {Scheduling_Strategy}'s {resume}
405 /// method.
406 virtual int resume (void);
408 protected:
410 /// Calls {handle_close} when dynamically unlinked.
411 virtual int fini (void);
413 /// Default version returns address info in {buf}.
414 virtual int info (ACE_TCHAR **buf, size_t) const;
416 // = The following three methods define the {Acceptor}'s strategies
417 // for creating, accepting, and activating {SVC_HANDLER}'s,
418 // respectively.
421 * Bridge method for creating a {SVC_HANDLER}. The strategy for
422 * creating a {SVC_HANDLER} are configured into the Acceptor via
423 * it's {creation_strategy_}. The default is to create a new
424 * {SVC_HANDLER} if {sh} == 0, else {sh} is unchanged. However,
425 * subclasses can override this policy to perform {SVC_HANDLER}
426 * creation in any way that they like (such as creating subclass
427 * instances of {SVC_HANDLER}, using a singleton, dynamically
428 * linking the handler, etc.). Returns -1 on failure, else 0.
430 virtual int make_svc_handler (SVC_HANDLER *&);
433 * Bridge method for accepting the new connection into the
434 * {SVC_HANDLER}. The default behavior delegates to the
435 * {PEER_ACCEPTOR::accept} in the {Acceptor_Strategy}.
437 virtual int accept_svc_handler (SVC_HANDLER *svc_handler);
440 * Bridge method for activating a {SVC_HANDLER} with the appropriate
441 * concurrency strategy. The default behavior of this method is to
442 * activate the {SVC_HANDLER} by calling its {open} method (which
443 * allows the {SVC_HANDLER} to define its own concurrency strategy).
444 * However, subclasses can override this strategy to do more
445 * sophisticated concurrency activations (such as creating the
446 * {SVC_HANDLER} as an "active object" via multi-threading or
447 * multi-processing).
449 virtual int activate_svc_handler (SVC_HANDLER *svc_handler);
451 // = Demultiplexing hooks.
452 /// Perform termination activities when {this} is removed from the
453 /// {Reactor}.
454 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
455 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
457 /// Handle SIGINT.
458 virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
460 // = These data members are "logically private" but are put in the
461 // protected part in case subclasses want to access them.
463 // = Strategy objects.
465 /// Creation strategy for an Acceptor.
466 CREATION_STRATEGY *creation_strategy_;
468 /// true if {Acceptor} created the creation strategy and thus should
469 /// delete it, else false.
470 bool delete_creation_strategy_;
472 /// Accept strategy for an {Acceptor}.
473 ACCEPT_STRATEGY *accept_strategy_;
475 /// true if {Acceptor} created the accept strategy and thus should delete
476 /// it, else false.
477 bool delete_accept_strategy_;
479 /// Concurrency strategy for an {Acceptor}.
480 CONCURRENCY_STRATEGY *concurrency_strategy_;
482 /// true if {Acceptor} created the concurrency strategy and thus should
483 /// delete it, else false.
484 bool delete_concurrency_strategy_;
486 /// Scheduling strategy for an {Acceptor}.
487 SCHEDULING_STRATEGY *scheduling_strategy_;
489 /// true if {Acceptor} created the scheduling strategy and thus should
490 /// delete it, else false.
491 bool delete_scheduling_strategy_;
493 // = Service information objects.
495 /// Name of the service.
496 ACE_TCHAR *service_name_;
498 /// Description of the service.
499 ACE_TCHAR *service_description_;
501 /// Address that the {Strategy_Acceptor} uses to listen for
502 /// connections.
503 typename PEER_ACCEPTOR::PEER_ADDR service_addr_;
507 * @class ACE_Oneshot_Acceptor
509 * @brief Generic factory for passively connecting clients and creating
510 * exactly one service handler of the type SVC_HANDLER specified in the
511 * template.
513 * This class works similarly to the regular ACE_Acceptor, but
514 * with the following differences:
515 * -# ACE_Oneshot_Acceptor doesn't automatically register itself with the
516 * ACE_Reactor; the caller is expected to call the accept() method
517 * directly. Since a later call to accept() may require a reactor,
518 * the constructor and open() methods both accept an ACE_Reactor pointer
519 * which is saved in case it's needed in accept().
520 * -# ACE_Oneshot_Acceptor doesn't need an ACE_Creation_Strategy (because
521 * the user supplies the SVC_HANDLER) or an ACE_Accept_Strategy (because
522 * this class only accepts one connection and then removes all traces of
523 * itself from the ACE_Reactor if it was registered for asynchronous
524 * accepts).
526 * The usage model for ACE_Oneshot_Acceptor is:
527 * - Instantiate an object and establish its local address to listen at.
528 * This can be accomplished using either the address-accepting constructor
529 * (but there's no error indication) or the default constructor followed
530 * by a call to open().
531 * - Call the accept() method. This will attempt to accept a connection
532 * immediately. If there is no immediately available connection to accept,
533 * behavior is governed by the ACE_Synch_Options argument passed to open().
535 template <typename SVC_HANDLER, typename PEER_ACCEPTOR>
536 class ACE_Oneshot_Acceptor : public ACE_Service_Object
538 public:
539 // Useful STL-style traits.
540 typedef typename PEER_ACCEPTOR::PEER_ADDR addr_type;
541 typedef PEER_ACCEPTOR acceptor_type;
542 typedef SVC_HANDLER handler_type;
543 typedef typename SVC_HANDLER::stream_type stream_type;
545 /// Constructor.
546 ACE_Oneshot_Acceptor (void);
549 * Initialize the appropriate strategies for concurrency and then
550 * open the acceptor at the designated @a local_addr. Note
551 * that unlike ACE_Acceptor and ACE_Strategy_Acceptor, this
552 * method does NOT register this acceptor with the @a reactor at
553 * this point -- the @a reactor parameter is saved in case it's
554 * needed later.
556 ACE_Oneshot_Acceptor (const typename PEER_ACCEPTOR::PEER_ADDR &local_addr,
557 ACE_Reactor *reactor = ACE_Reactor::instance (),
558 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0);
561 * Initialize the appropriate strategies for concurrency and then
562 * open the acceptor at the designated @a local_addr. Note
563 * that unlike ACE_Acceptor and ACE_Strategy_Acceptor, this
564 * method does NOT register this acceptor with the @a reactor at
565 * this point -- the @a reactor parameter is saved in case it's
566 * needed later.
568 int open (const typename PEER_ACCEPTOR::PEER_ADDR &,
569 ACE_Reactor *reactor = ACE_Reactor::instance (),
570 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0);
572 /// Close down the {Oneshot_Acceptor}.
573 virtual ~ACE_Oneshot_Acceptor (void);
575 // = Explicit factory operation.
576 /// Create a {SVC_HANDLER}, accept the connection into the
577 /// {SVC_HANDLER}, and activate the {SVC_HANDLER}.
578 virtual int accept (SVC_HANDLER * = 0,
579 typename PEER_ACCEPTOR::PEER_ADDR *remote_addr = 0,
580 const ACE_Synch_Options &synch_options = ACE_Synch_Options::defaults,
581 bool restart = true,
582 bool reset_new_handle = false);
584 /// Cancel a oneshot acceptor that was started asynchronously.
585 virtual int cancel (void);
587 /// Return the underlying {PEER_ACCEPTOR} object.
588 virtual operator PEER_ACCEPTOR &() const;
590 /// Return the underlying {PEER_ACCEPTOR} object.
591 virtual PEER_ACCEPTOR &acceptor (void) const;
593 /// Close down the {Oneshot_Acceptor}.
594 virtual int close (void);
596 /// Dump the state of an object.
597 void dump (void) const;
599 /// Declare the dynamic allocation hooks.
600 ACE_ALLOC_HOOK_DECLARE;
602 protected:
604 * Bridge method for activating a {svc_handler} with the appropriate
605 * concurrency strategy. Default behavior is to activate the
606 * {SVC_HANDLER} as a "passive object." However, subclasses can
607 * override this strategy to do more sophisticated concurrency
608 * activations (such as creating the {SVC_HANDLER} as an "active
609 * object" via multi-threading or multi-processing).
611 virtual int activate_svc_handler (SVC_HANDLER *svc_handler);
613 /// Factors out the code shared between the {accept} and
614 /// {handle_input} methods.
615 int shared_accept (SVC_HANDLER *svc_handler,
616 typename PEER_ACCEPTOR::PEER_ADDR *remote_addr,
617 ACE_Time_Value *timeout,
618 bool restart,
619 bool reset_new_handle);
621 // = Demultiplexing hooks.
622 /// Returns the listening acceptor's {ACE_HANDLE}.
623 virtual ACE_HANDLE get_handle (void) const;
625 /// Perform termination activities when {this} is removed from the
626 /// {reactor}.
627 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
628 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
630 /// Accept one connection from a client and activates the
631 /// SVC_HANDLER.
632 virtual int handle_input (ACE_HANDLE);
634 /// Called when an acceptor times out...
635 virtual int handle_timeout (const ACE_Time_Value &tv,
636 const void *arg);
638 // = Dynamic linking hooks.
639 /// Default version does no work and returns -1. Must be overloaded
640 /// by application developer to do anything meaningful.
641 virtual int init (int argc, ACE_TCHAR *argv[]);
643 /// Default version does no work and returns -1. Must be overloaded
644 /// by application developer to do anything meaningful.
645 virtual int fini (void);
647 /// Default version returns address info in {buf}.
648 virtual int info (ACE_TCHAR **, size_t) const;
650 // = Service management hooks.
651 /// Default version does no work and returns -1. Must be overloaded
652 /// by application developer to do anything meaningful.
653 virtual int suspend (void);
655 /// Default version does no work and returns -1. Must be overloaded
656 /// by application developer to do anything meaningful.
657 virtual int resume (void);
659 private:
661 * Insert ourselves into the {ACE_Reactor} so that we can continue
662 * accepting this connection asynchronously. This method should NOT
663 * be called by developers directly.
665 int register_handler (SVC_HANDLER *svc_handler,
666 const ACE_Synch_Options &options,
667 bool restart);
669 /// Hold the svc_handler_ across asynchrony boundaries.
670 SVC_HANDLER *svc_handler_;
672 /// Hold the restart flag across asynchrony boundaries.
673 bool restart_;
675 /// Factory that establishes connections passively.
676 PEER_ACCEPTOR peer_acceptor_;
678 /// Concurrency strategy for an Acceptor.
679 ACE_Concurrency_Strategy<SVC_HANDLER> *concurrency_strategy_;
681 /// true if Acceptor created the concurrency strategy and thus should
682 /// delete it, else false.
683 bool delete_concurrency_strategy_;
686 ACE_END_VERSIONED_NAMESPACE_DECL
688 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
689 #include "ace/Acceptor.cpp"
690 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
692 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
693 #pragma implementation ("Acceptor.cpp")
694 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
696 #include /**/ "ace/post.h"
698 #endif /* ACE_ACCEPTOR_H */