Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / POSIX_Asynch_IO.h
blob13a5e8e47ca90f56008b3facad6e510c4fe3a5ac
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file POSIX_Asynch_IO.h
7 * The implementation classes for POSIX implementation of Asynch
8 * Operations are defined here in this file.
10 * @author Irfan Pyarali <irfan@cs.wustl.edu>
11 * @author Tim Harrison <harrison@cs.wustl.edu>
12 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
13 * @author Roger Tragin <r.tragin@computer.org>
14 * @author Alexander Libman <alibman@baltimore.com>
16 //=============================================================================
18 #ifndef ACE_POSIX_ASYNCH_IO_H
19 #define ACE_POSIX_ASYNCH_IO_H
21 #include /**/ "ace/config-all.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #if defined (ACE_HAS_AIO_CALLS)
29 #include "ace/os_include/os_aio.h"
31 #include "ace/Asynch_IO_Impl.h"
32 #include "ace/Unbounded_Queue.h"
33 #include "ace/Map_Manager.h"
34 #include "ace/Event_Handler.h"
35 #if defined(INTEGRITY)
36 #include "ace/ACE.h"
37 #endif
39 #include "ace/Null_Mutex.h"
41 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
43 // Forward declarations
44 class ACE_POSIX_Proactor;
45 class ACE_Proactor_Impl;
46 class ACE_Handle_Set;
48 /**
49 * @class ACE_POSIX_Asynch_Result
51 * This class provides concrete implementation for ACE_Asynch_Result
52 * for POSIX4 platforms. This class extends @c aiocb and makes it more
53 * useful.
55 class ACE_Export ACE_POSIX_Asynch_Result : public virtual ACE_Asynch_Result_Impl,
56 public aiocb
58 public:
59 /// Number of bytes transferred by the operation.
60 size_t bytes_transferred () const;
62 /// ACT associated with the operation.
63 const void *act () const;
65 /// Did the operation succeed?
66 int success () const;
68 /**
69 * This is the ACT associated with the handle on which the
70 * Asynch_Operation takes place.
72 * @note This is not implemented for POSIX4 platforms.
74 const void *completion_key () const;
76 /// Error value if the operation fails.
77 u_long error () const;
79 /// This returns ACE_INVALID_HANDLE on POSIX4 platforms.
80 ACE_HANDLE event () const;
82 /**
83 * This really make sense only when doing file I/O.
85 * @@ On POSIX4-Unix, offset_high should be supported using
86 * aiocb64.
89 u_long offset () const;
90 u_long offset_high () const;
92 /// Priority of the operation.
93 int priority () const;
95 /**
96 * POSIX4 realtime signal number to be used for the
97 * operation. <signal_number> ranges from SIGRTMIN to SIGRTMAX. By
98 * default, SIGRTMIN is used to issue <aio_> calls.
100 int signal_number () const;
102 /// Post @c this to the Proactor.
103 int post_completion (ACE_Proactor_Impl *proactor);
105 /// Destructor.
106 virtual ~ACE_POSIX_Asynch_Result ();
108 /// Simulate error value to use in the post_completion ()
109 void set_error (u_long errcode);
111 /// Simulate value to use in the post_completion ()
112 void set_bytes_transferred (size_t nbytes);
114 protected:
115 /// Constructor. <Event> is not used on POSIX.
116 ACE_POSIX_Asynch_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
117 const void* act,
118 ACE_HANDLE event,
119 u_long offset,
120 u_long offset_high,
121 int priority,
122 int signal_number);
124 /// Handler that will be called back.
125 ACE_Handler::Proxy_Ptr handler_proxy_;
128 * ACT for this operation.
129 * We could use <aiocb::aio_sigevent.sigev_value.sival_ptr> for
130 * this. But it doesnot provide the constness, so this may be
131 * better.
133 const void *act_;
135 /// Bytes transferred by this operation.
136 size_t bytes_transferred_;
138 /// Success indicator.
139 int success_;
141 /// ACT associated with handle.
142 const void *completion_key_;
144 /// Error if operation failed.
145 u_long error_;
149 * @class ACE_POSIX_Asynch_Operation
151 * @brief This class implements ACE_Asynch_Operation for all
152 * implementations of Proactor (AIOCB, SIG, SUN)
153 * Specific future implementations can derive from this class.
155 class ACE_Export ACE_POSIX_Asynch_Operation : public virtual ACE_Asynch_Operation_Impl
157 public:
159 * Initializes the factory with information which will be used with
160 * each asynchronous call. If (@a handle == ACE_INVALID_HANDLE),
161 * @c ACE_Handler::handle will be called on the handler to get the
162 * correct handle. No need for the Proactor since the sub classes
163 * will know the correct implementation Proactor class, since this
164 * Operation class itself was created by the correct implementation
165 * Proactor class.
167 int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
168 ACE_HANDLE handle,
169 const void *completion_key,
170 ACE_Proactor *proactor = 0);
172 /// Check the documentation for ACE_Asynch_Operation::cancel.
173 int cancel ();
175 // = Access methods.
177 /// Return the underlying proactor.
178 ACE_Proactor* proactor () const;
180 /// Return the underlying Proactor implementation.
181 ACE_POSIX_Proactor * posix_proactor () const;
183 protected:
184 /// Constructor.
185 ACE_POSIX_Asynch_Operation (ACE_POSIX_Proactor *posix_proactor);
187 /// Destructor.
188 virtual ~ACE_POSIX_Asynch_Operation ();
190 // This call is for the POSIX implementation. This method is used by
191 // ACE_Asynch_Operation to store some information with the
192 // Proactor after an <aio_> call is issued, so that the Proactor can
193 // retreve this information to do <aio_return> and <aio_error>.
194 // Passing a '0' ptr returns the status, indicating whether there
195 // are slots available or no. Passing a valid ptr stores the ptr
196 // with the Proactor.
199 * It is easy to get this specific implementation proactor here,
200 * since it is the one that creates the correct POSIX_Asynch_*
201 * objects. We can use this to get to the implementation proactor
202 * directly.
204 ACE_POSIX_Proactor *posix_proactor_;
206 /// Proactor that this Asynch IO will be registered with.
207 ACE_Proactor *proactor_;
209 /// Handler that will receive the callback.
210 ACE_Handler::Proxy_Ptr handler_proxy_;
212 /// I/O handle used for reading.
213 ACE_HANDLE handle_;
217 * @class ACE_POSIX_Asynch_Read_Stream_Result
219 * @brief This class provides concrete implementation for
220 * <ACE_Asynch_Read_Stream::Result> class for POSIX platforms.
222 class ACE_Export ACE_POSIX_Asynch_Read_Stream_Result : public virtual ACE_Asynch_Read_Stream_Result_Impl,
223 public ACE_POSIX_Asynch_Result
225 /// Factory classes will have special permissions.
226 friend class ACE_POSIX_Asynch_Read_Stream;
228 /// The Proactor constructs the Result class for faking results.
229 friend class ACE_POSIX_Proactor;
231 public:
232 /// The number of bytes which were requested at the start of the
233 /// asynchronous read.
234 size_t bytes_to_read () const;
236 /// Message block which contains the read data.
237 ACE_Message_Block &message_block () const;
239 /// I/O handle used for reading.
240 ACE_HANDLE handle () const;
242 protected:
243 ACE_POSIX_Asynch_Read_Stream_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
244 ACE_HANDLE handle,
245 ACE_Message_Block &message_block,
246 size_t bytes_to_read,
247 const void* act,
248 ACE_HANDLE event,
249 int priority,
250 int signal_number);
251 // Constructor is protected since creation is limited to
252 // ACE_Asynch_Read_Stream factory.
254 /// Get the data copied to this class, before calling application
255 /// handler.
256 virtual void complete (size_t bytes_transferred,
257 int success,
258 const void *completion_key,
259 u_long error);
261 /// Destructor.
262 virtual ~ACE_POSIX_Asynch_Read_Stream_Result ();
264 // aiocb::aio_nbytes
265 // Bytes requested when the asynchronous read was initiated.
267 /// Message block for reading the data into.
268 ACE_Message_Block &message_block_;
270 // aiocb::aio_filedes
271 // I/O handle used for reading.
275 * @class ACE_POSIX_Asynch_Read_Stream
277 * This class implements <ACE_Asynch_Read_Stream> for all POSIX
278 * based implementation of Proactor.
280 class ACE_Export ACE_POSIX_Asynch_Read_Stream : public virtual ACE_Asynch_Read_Stream_Impl,
281 public ACE_POSIX_Asynch_Operation
283 public:
284 /// Constructor.
285 ACE_POSIX_Asynch_Read_Stream (ACE_POSIX_Proactor *posix_proactor);
287 /// This starts off an asynchronous read. Upto @a bytes_to_read will
288 /// be read and stored in the @a message_block.
289 int read (ACE_Message_Block &message_block,
290 size_t bytes_to_read,
291 const void *act,
292 int priority,
293 int signal_number = 0);
295 /// Destructor.
296 virtual ~ACE_POSIX_Asynch_Read_Stream ();
301 * @class ACE_POSIX_Asynch_Write_Stream_Result
303 * @brief This class provides concrete implementation for
304 * <ACE_Asynch_Write_Stream::Result> on POSIX platforms.
306 * This class has all the information necessary for the
307 * @c handler to uniquiely identify the completion of the
308 * asynchronous write.
310 class ACE_Export ACE_POSIX_Asynch_Write_Stream_Result : public virtual ACE_Asynch_Write_Stream_Result_Impl,
311 public ACE_POSIX_Asynch_Result
313 /// Factory classes will have special privilages.
314 friend class ACE_POSIX_Asynch_Write_Stream;
316 /// The Proactor constructs the Result class for faking results.
317 friend class ACE_POSIX_Proactor;
319 public:
320 /// The number of bytes which were requested at the start of the
321 /// asynchronous write.
322 size_t bytes_to_write () const;
324 /// Message block that contains the data to be written.
325 ACE_Message_Block &message_block () const;
327 /// I/O handle used for writing.
328 ACE_HANDLE handle () const;
330 protected:
331 /// Constructor is protected since creation is limited to
332 /// ACE_Asynch_Write_Stream factory.
333 ACE_POSIX_Asynch_Write_Stream_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
334 ACE_HANDLE handle,
335 ACE_Message_Block &message_block,
336 size_t bytes_to_write,
337 const void* act,
338 ACE_HANDLE event,
339 int priority,
340 int signal_number);
342 /// ACE_Proactor will call this method when the write completes.
343 virtual void complete (size_t bytes_transferred,
344 int success,
345 const void *completion_key,
346 u_long error);
348 /// Destructor.
349 virtual ~ACE_POSIX_Asynch_Write_Stream_Result ();
351 protected:
352 // aiocb::aio_nbytes
353 // The number of bytes which were requested at the start of the
354 // asynchronous write.
356 /// Message block that contains the data to be written.
357 ACE_Message_Block &message_block_;
359 // aiocb::aio_filedes
360 // I/O handle used for writing.
364 * @class ACE_POSIX_Asynch_Write_Stream
366 * @brief This class implements <ACE_Asynch_Write_Stream> for
367 * all POSIX implementations of ACE_Proactor.
369 class ACE_Export ACE_POSIX_Asynch_Write_Stream : public virtual ACE_Asynch_Write_Stream_Impl,
370 public ACE_POSIX_Asynch_Operation
372 public:
373 /// Constructor.
374 ACE_POSIX_Asynch_Write_Stream (ACE_POSIX_Proactor *posix_proactor);
376 /// This starts off an asynchronous write. Upto @a bytes_to_write
377 /// will be written from the @a message_block.
378 int write (ACE_Message_Block &message_block,
379 size_t bytes_to_write,
380 const void *act,
381 int priority,
382 int signal_number = 0);
384 /// Destructor.
385 virtual ~ACE_POSIX_Asynch_Write_Stream ();
389 * @class ACE_POSIX_Asynch_Read_File_Result
391 * @brief This class provides concrete implementation for
392 * <ACE_Asynch_Read_File::Result> class for POSIX platforms.
394 class ACE_Export ACE_POSIX_Asynch_Read_File_Result : public virtual ACE_Asynch_Read_File_Result_Impl,
395 public ACE_POSIX_Asynch_Read_Stream_Result
397 /// Factory classes will have special permissions.
398 friend class ACE_POSIX_Asynch_Read_File;
400 /// The Proactor constructs the Result class for faking results.
401 friend class ACE_POSIX_Proactor;
403 protected:
404 /// Constructor is protected since creation is limited to
405 /// ACE_Asynch_Read_File factory.
406 ACE_POSIX_Asynch_Read_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
407 ACE_HANDLE handle,
408 ACE_Message_Block &message_block,
409 size_t bytes_to_read,
410 const void* act,
411 u_long offset,
412 u_long offset_high,
413 ACE_HANDLE event,
414 int priority,
415 int signal_number);
417 /// ACE_Proactor will call this method when the read completes.
418 virtual void complete (size_t bytes_transferred,
419 int success,
420 const void *completion_key,
421 u_long error);
423 /// Destructor.
424 virtual ~ACE_POSIX_Asynch_Read_File_Result ();
428 * @class ACE_POSIX_Asynch_Read_File
430 * @brief This class is a factory for starting off asynchronous reads
431 * on a file. This class implements <ACE_Asynch_Read_File> for
432 * all POSIX implementations of Proactor.
434 * Once <open> is called, multiple asynchronous <read>s can
435 * started using this class. A <ACE_Asynch_Read_File::Result>
436 * will be passed back to the @c handler when the asynchronous
437 * reads completes through the <ACE_Handler::handle_read_file>
438 * callback.
440 * This class differs slightly from <ACE_Asynch_Read_Stream> as it
441 * allows the user to specify an offset for the read.
443 class ACE_Export ACE_POSIX_Asynch_Read_File : public virtual ACE_Asynch_Read_File_Impl,
444 public ACE_POSIX_Asynch_Read_Stream
446 public:
447 /// Constructor.
448 ACE_POSIX_Asynch_Read_File (ACE_POSIX_Proactor *posix_proactor);
451 * This starts off an asynchronous read. Upto @a bytes_to_read will
452 * be read and stored in the @a message_block. The read will start
453 * at @a offset from the beginning of the file.
455 int read (ACE_Message_Block &message_block,
456 size_t bytes_to_read,
457 u_long offset,
458 u_long offset_high,
459 const void *act,
460 int priority,
461 int signal_number = 0);
463 /// Destructor.
464 virtual ~ACE_POSIX_Asynch_Read_File ();
466 private:
468 * This belongs to ACE_POSIX_Asynch_Read_Stream. We have
469 * defined this here to avoid compiler warnings and forward the
470 * method to <ACE_POSIX_Asynch_Read_Stream::read>.
472 int read (ACE_Message_Block &message_block,
473 size_t bytes_to_read,
474 const void *act,
475 int priority,
476 int signal_number = 0);
481 * @class ACE_POSIX_Asynch_Write_File_Result
483 * @brief This class provides implementation for
484 * <ACE_Asynch_Write_File_Result> for POSIX platforms.
486 * This class has all the information necessary for the
487 * @c handler to uniquiely identify the completion of the
488 * asynchronous write.
490 * This class differs slightly from
491 * <ACE_Asynch_Write_Stream::Result> as it calls back
492 * <ACE_Handler::handle_write_file> on the @c handler instead of
493 * <ACE_Handler::handle_write_stream>. No additional state is
494 * required by this class as <ACE_Asynch_Result> can store the
495 * @a offset.
497 class ACE_Export ACE_POSIX_Asynch_Write_File_Result : public virtual ACE_Asynch_Write_File_Result_Impl,
498 public ACE_POSIX_Asynch_Write_Stream_Result
500 /// Factory classes will have special permissions.
501 friend class ACE_POSIX_Asynch_Write_File;
503 /// The Proactor constructs the Result class for faking results.
504 friend class ACE_POSIX_Proactor;
506 protected:
507 /// Constructor is protected since creation is limited to
508 /// ACE_Asynch_Write_File factory.
509 ACE_POSIX_Asynch_Write_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
510 ACE_HANDLE handle,
511 ACE_Message_Block &message_block,
512 size_t bytes_to_write,
513 const void* act,
514 u_long offset,
515 u_long offset_high,
516 ACE_HANDLE event,
517 int priority,
518 int signal_number);
520 /// ACE_Proactor will call this method when the write completes.
521 virtual void complete (size_t bytes_transferred,
522 int success,
523 const void *completion_key,
524 u_long error);
526 /// Destructor.
527 virtual ~ACE_POSIX_Asynch_Write_File_Result ();
531 * @class ACE_POSIX_Asynch_Write_File
533 * This class provides concrete implementation for
534 * <ACE_Asynch_Write_File> for POSIX platforms where the
535 * completion strategy for Proactor is based on AIOCB (AIO
536 * Control Blocks).
538 class ACE_Export ACE_POSIX_Asynch_Write_File : public virtual ACE_Asynch_Write_File_Impl,
539 public ACE_POSIX_Asynch_Write_Stream
541 public:
542 /// Constructor.
543 ACE_POSIX_Asynch_Write_File (ACE_POSIX_Proactor *posix_proactor);
546 * This starts off an asynchronous write. Upto @a bytes_to_write
547 * will be written and stored in the @a message_block. The write will
548 * start at @a offset from the beginning of the file.
550 int write (ACE_Message_Block &message_block,
551 size_t bytes_to_write,
552 u_long offset,
553 u_long offset_high,
554 const void *act,
555 int priority,
556 int signal_number = 0);
558 /// Destructor.
559 virtual ~ACE_POSIX_Asynch_Write_File ();
561 private:
563 * This <write> belongs to ACE_POSIX_Asynch_Write_Stream. We
564 * have put this here to avoid compiler warnings. We forward this
565 * method call to the <ACE_POSIX_Asynch_Write_Stream::write>
566 * one.
568 int write (ACE_Message_Block &message_block,
569 size_t bytes_to_write,
570 const void *act,
571 int priority,
572 int signal_number = 0);
576 * @class ACE_POSIX_Asynch_Accept_Result
578 * @brief This is that class which will be passed back to the
579 * handler when the asynchronous accept completes.
581 * This class has all the information necessary for the
582 * handler to uniquiely identify the completion of the
583 * asynchronous accept.
585 class ACE_Export ACE_POSIX_Asynch_Accept_Result : public virtual ACE_Asynch_Accept_Result_Impl,
586 public ACE_POSIX_Asynch_Result
588 /// Factory classes will have special permissions.
589 friend class ACE_POSIX_Asynch_Accept;
591 /// The Proactor constructs the Result class for faking results.
592 friend class ACE_POSIX_Proactor;
594 public:
595 /// The number of bytes which were requested at the start of the
596 /// asynchronous accept.
597 size_t bytes_to_read () const;
599 /// Message block which contains the read data.
600 ACE_Message_Block &message_block () const;
602 /// I/O handle used for accepting new connections.
603 ACE_HANDLE listen_handle () const;
605 /// I/O handle for the new connection.
606 ACE_HANDLE accept_handle () const;
608 protected:
609 /// Constructor is protected since creation is limited to
610 /// ACE_Asynch_Accept factory.
611 ACE_POSIX_Asynch_Accept_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
612 ACE_HANDLE listen_handle,
613 ACE_HANDLE accept_handle,
614 ACE_Message_Block &message_block,
615 size_t bytes_to_read,
616 const void* act,
617 ACE_HANDLE event,
618 int priority,
619 int signal_number);
621 /// ACE_Proactor will call this method when the accept completes.
622 virtual void complete (size_t bytes_transferred,
623 int success,
624 const void *completion_key,
625 u_long error);
627 /// Destructor.
628 virtual ~ACE_POSIX_Asynch_Accept_Result ();
630 // aiocb::aio_nbytes
631 // Bytes requested when the asynchronous read was initiated.
632 // Actually, on POSIX implementation, we dont read any intial data.
634 /// Message block for reading the data into.
635 ACE_Message_Block &message_block_;
637 /// I/O handle used for accepting new connections.
638 ACE_HANDLE listen_handle_;
640 // aiocb::aio_filedes
641 // I/O handle for the new connection.
646 * @class ACE_POSIX_Asynch_Accept
648 * @brief For the POSIX implementation this class is common for all Proactors
649 * (AIOCB/SIG/SUN)
651 class ACE_Export ACE_POSIX_Asynch_Accept :
652 public virtual ACE_Asynch_Accept_Impl,
653 public ACE_POSIX_Asynch_Operation,
654 public ACE_Event_Handler
656 public:
657 /// Constructor.
658 ACE_POSIX_Asynch_Accept (ACE_POSIX_Proactor * posix_proactor);
660 /// Destructor.
661 virtual ~ACE_POSIX_Asynch_Accept ();
664 * This <open> belongs to ACE_POSIX_Asynch_Operation. We forward
665 * this call to that method. We have put this here to avoid the
666 * compiler warnings.
668 int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
669 ACE_HANDLE handle,
670 const void *completion_key,
671 ACE_Proactor *proactor = 0);
674 * This starts off an asynchronous accept. The asynchronous accept
675 * call also allows any initial data to be returned to the
676 * @c handler. Upto @a bytes_to_read will be read and stored in the
677 * @a message_block. The <accept_handle> will be used for the
678 * <accept> call. If (<accept_handle> == INVALID_HANDLE), a new
679 * handle will be created.
681 * @a message_block must be specified. This is because the address of
682 * the new connection is placed at the end of this buffer.
684 int accept (ACE_Message_Block &message_block,
685 size_t bytes_to_read,
686 ACE_HANDLE accept_handle,
687 const void *act,
688 int priority,
689 int signal_number = 0,
690 int addr_family = AF_INET);
693 * Cancel all pending pseudo-asynchronus requests
694 * Behavior as usual AIO request
696 int cancel ();
699 * Close performs cancellation of all pending requests
700 * and closure the listen handle
702 int close ();
704 /// virtual from ACE_Event_Handler
705 ACE_HANDLE get_handle () const;
707 /// virtual from ACE_Event_Handler
708 void set_handle (ACE_HANDLE handle);
710 /// virtual from ACE_Event_Handler
711 /// Called when accept event comes up on <listen_handle>
712 int handle_input (ACE_HANDLE handle);
714 /// virtual from ACE_Event_Handler
715 int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask);
717 private:
718 /// flg_notify points whether or not we should send notification about
719 /// canceled accepts
720 /// Parameter flg_notify can be
721 /// 0 - don't send notifications about canceled accepts
722 /// 1 - notify user about canceled accepts
723 /// according POSIX standards we should receive notifications
724 /// on canceled AIO requests
725 int cancel_uncompleted (int flg_notify);
727 /// true - Accept is registered in ACE_Asynch_Pseudo_Task
728 /// false - Accept is deregisted in ACE_Asynch_Pseudo_Task
729 bool flg_open_ ;
731 /// Queue of Result pointers that correspond to all the pending
732 /// accept operations.
733 ACE_Unbounded_Queue<ACE_POSIX_Asynch_Accept_Result*> result_queue_;
735 /// The lock to protect the result queue which is shared. The queue
736 /// is updated by main thread in the register function call and
737 /// through the auxillary thread in the deregister fun. So let us
738 /// mutex it.
739 ACE_SYNCH_MUTEX lock_;
743 * @class ACE_POSIX_Asynch_Connect_Result
745 * @brief This is that class which will be passed back to the
746 * completion handler when the asynchronous connect completes.
748 * This class has all the information necessary for a
749 * completion handler to uniquely identify the completion of the
750 * asynchronous connect.
752 class ACE_Export ACE_POSIX_Asynch_Connect_Result : public virtual ACE_Asynch_Connect_Result_Impl,
753 public ACE_POSIX_Asynch_Result
755 /// Factory classes will have special permissions.
756 friend class ACE_POSIX_Asynch_Connect;
758 /// The Proactor constructs the Result class for faking results.
759 friend class ACE_POSIX_Proactor;
761 public:
762 /// I/O handle for the connection.
763 ACE_HANDLE connect_handle () const;
765 protected:
766 /// Constructor is protected since creation is limited to
767 /// ACE_Asynch_Connect factory.
768 ACE_POSIX_Asynch_Connect_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
769 ACE_HANDLE connect_handle,
770 const void* act,
771 ACE_HANDLE event,
772 int priority,
773 int signal_number);
775 /// ACE_Proactor will call this method when the accept completes.
776 virtual void complete (size_t bytes_transferred,
777 int success,
778 const void *completion_key,
779 u_long error);
781 /// Destructor.
782 virtual ~ACE_POSIX_Asynch_Connect_Result ();
784 // aiocb::aio_filedes
785 // I/O handle for the new connection.
786 void connect_handle (ACE_HANDLE handle);
791 * @class ACE_POSIX_Asynch_Connect
793 class ACE_Export ACE_POSIX_Asynch_Connect :
794 public virtual ACE_Asynch_Connect_Impl,
795 public ACE_POSIX_Asynch_Operation,
796 public ACE_Event_Handler
798 public:
799 /// Constructor.
800 ACE_POSIX_Asynch_Connect (ACE_POSIX_Proactor * posix_proactor);
802 /// Destructor.
803 virtual ~ACE_POSIX_Asynch_Connect ();
806 * This belongs to ACE_POSIX_Asynch_Operation. We forward
807 * this call to that method. We have put this here to avoid the
808 * compiler warnings.
810 int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
811 ACE_HANDLE handle,
812 const void *completion_key,
813 ACE_Proactor *proactor = 0);
816 * This starts off an asynchronous connect.
818 * @arg connect_handle will be used for the connect call. If
819 * ACE_INVALID_HANDLE is specified, a new
820 * handle will be created.
822 int connect (ACE_HANDLE connect_handle,
823 const ACE_Addr &remote_sap,
824 const ACE_Addr &local_sap,
825 int reuse_addr,
826 const void *act,
827 int priority,
828 int signal_number = 0);
831 * Cancel all pending pseudo-asynchronus requests
832 * Behavior as usual AIO request
834 int cancel ();
837 * Close performs cancellation of all pending requests.
839 int close ();
841 /// virtual from ACE_Event_Handler
842 ACE_HANDLE get_handle () const;
844 /// virtual from ACE_Event_Handler
845 void set_handle (ACE_HANDLE handle);
847 /// virtual from ACE_Event_Handler
848 /// The default action on handle_input() and handle_exception is to
849 /// return -1. Since that's what we want to do, just reuse them.
850 /// handle_output(), however, is where successful connects are reported.
851 int handle_output (ACE_HANDLE handle);
853 /// virtual from ACE_Event_Handler
854 int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask) ;
856 private:
857 int connect_i (ACE_POSIX_Asynch_Connect_Result *result,
858 const ACE_Addr & remote_sap,
859 const ACE_Addr & local_sap,
860 int reuse_addr);
862 int post_result (ACE_POSIX_Asynch_Connect_Result *result, bool flg_post);
864 /// Cancel uncompleted connect operations.
866 * @arg flg_notify Indicates whether or not we should send notification
867 * about canceled accepts. If this is false, don't send
868 * notifications about canceled connects. If true, notify
869 * user about canceled connects according POSIX
870 * standards we should receive notifications on canceled
871 * AIO requests.
873 int cancel_uncompleted (bool flg_notify, ACE_Handle_Set &set);
875 bool flg_open_ ;
876 /// true - Connect is registered in ACE_Asynch_Pseudo_Task
877 /// false - Aceept is deregisted in ACE_Asynch_Pseudo_Task
879 typedef ACE_Map_Manager<ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX>
880 MAP_MANAGER;
882 /// Map of Result pointers that correspond to all the pending connects.
883 MAP_MANAGER result_map_;
885 /// The lock to protect the result map which is shared. The queue
886 /// is updated by main thread in the register function call and
887 /// through the auxillary thread in the asynch pseudo task.
888 ACE_SYNCH_MUTEX lock_;
893 * @class ACE_POSIX_Asynch_Transmit_File_Result
895 * @brief This is that class which will be passed back to the
896 * <handler> when the asynchronous transmit file completes.
898 * This class has all the information necessary for the
899 * <handler> to uniquiely identify the completion of the
900 * asynchronous transmit file.
902 class ACE_Export ACE_POSIX_Asynch_Transmit_File_Result : public virtual ACE_Asynch_Transmit_File_Result_Impl,
903 public ACE_POSIX_Asynch_Result
905 /// Factory classes will have special permissions.
906 friend class ACE_POSIX_Asynch_Transmit_File;
908 /// Handlers do all the job.
909 friend class ACE_POSIX_Asynch_Transmit_Handler;
911 /// The Proactor constructs the Result class for faking results.
912 friend class ACE_POSIX_Proactor;
914 public:
915 /// Socket used for transmitting the file.
916 ACE_HANDLE socket () const;
918 /// File from which the data is read.
919 ACE_HANDLE file () const;
921 /// Header and trailer data associated with this transmit file.
922 ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer () const;
924 /// The number of bytes which were requested at the start of the
925 /// asynchronous transmit file.
926 size_t bytes_to_write () const;
928 /// Number of bytes per send requested at the start of the transmit
929 /// file.
930 size_t bytes_per_send () const;
932 /// Flags which were passed into transmit file.
933 u_long flags () const;
935 protected:
936 ACE_POSIX_Asynch_Transmit_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
937 ACE_HANDLE socket,
938 ACE_HANDLE file,
939 ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
940 size_t bytes_to_write,
941 u_long offset,
942 u_long offset_high,
943 size_t bytes_per_send,
944 u_long flags,
945 const void *act,
946 ACE_HANDLE event,
947 int priority,
948 int signal_number);
949 // Constructor is protected since creation is limited to
950 // ACE_Asynch_Transmit_File factory.
952 /// ACE_Proactor will call this method when the write completes.
953 virtual void complete (size_t bytes_transferred,
954 int success,
955 const void *completion_key,
956 u_long error);
958 /// Destructor.
959 virtual ~ACE_POSIX_Asynch_Transmit_File_Result ();
961 /// Network I/O handle.
962 ACE_HANDLE socket_;
964 // aiocb::aio_filedes
965 // File I/O handle.
967 /// Header and trailer data associated with this transmit file.
968 ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer_;
970 // aiocb::aio_nbytes
971 // The number of bytes which were requested at the start of the
972 // asynchronous transmit file.
974 /// Number of bytes per send requested at the start of the transmit
975 /// file.
976 size_t bytes_per_send_;
978 /// Flags which were passed into transmit file.
979 u_long flags_;
983 * @class ACE_POSIX_Asynch_Transmit_File
985 * @brief Implementation for transmit_file will make use of
986 * POSIX_Asynch_Transmit_Handler.
988 class ACE_Export ACE_POSIX_Asynch_Transmit_File : public virtual ACE_Asynch_Transmit_File_Impl,
989 public ACE_POSIX_Asynch_Operation
991 public:
992 /// Constructor.
993 ACE_POSIX_Asynch_Transmit_File (ACE_POSIX_Proactor *posix_proactor);
996 * This starts off an asynchronous transmit file. The <file> is a
997 * handle to an open file. <header_and_trailer> is a pointer to a
998 * data structure that contains pointers to data to send before and
999 * after the file data is sent. Set this parameter to 0 if you only
1000 * want to transmit the file data. Upto @a bytes_to_write will be
1001 * written to the <socket>. If you want to send the entire file,
1002 * let @a bytes_to_write = 0. @a bytes_per_send is the size of each
1003 * block of data sent per send operation. Please read the POSIX
1004 * documentation on what the flags should be.
1006 int transmit_file (ACE_HANDLE file,
1007 ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
1008 size_t bytes_to_write,
1009 u_long offset,
1010 u_long offset_high,
1011 size_t bytes_per_send,
1012 u_long flags,
1013 const void *act,
1014 int priority,
1015 int signal_number = 0);
1017 /// Destructor.
1018 virtual ~ACE_POSIX_Asynch_Transmit_File ();
1023 * @class ACE_POSIX_Asynch_Read_Dgram
1025 * @brief This class is a factory for starting off asynchronous reads
1026 * on a UDP socket.
1028 * Once <open> is called, multiple asynchronous <read>s can be
1029 * started using this class. An ACE_Asynch_Read_Dgram::Result
1030 * will be passed back to the <handler> when the asynchronous
1031 * reads completes through the <ACE_Handler::handle_read_stream>
1032 * callback.
1034 class ACE_Export ACE_POSIX_Asynch_Read_Dgram : public virtual ACE_Asynch_Read_Dgram_Impl,
1035 public ACE_POSIX_Asynch_Operation
1037 public:
1038 /// Constructor.
1039 ACE_POSIX_Asynch_Read_Dgram (ACE_POSIX_Proactor *posix_proactor);
1040 virtual ~ACE_POSIX_Asynch_Read_Dgram ();
1042 /** This method queues an asynchronous read. Up to
1043 * @a message_block->total_size() bytes will be read and stored in the
1044 * @a message_block beginning at its write pointer. The @a message_block
1045 * write pointer will be updated to reflect any added bytes if the read
1046 * operation is successful completed.
1047 * Priority of the operation is specified by @a priority. On POSIX4-Unix,
1048 * this is supported. Works like <nice> in Unix. Negative values are not
1049 * allowed. 0 means priority of the operation same as the process
1050 * priority. 1 means priority of the operation is one less than
1051 * process. @a signal_number argument is a no-op on non-POSIX4 systems.
1053 * @note Unlike the Windows version of this facility, no indication of
1054 * immediate success can be returned, and @a number_of_bytes_read is
1055 * never used.
1057 * @arg flags Not used.
1058 * @arg protocol_family Not used.
1059 * @retval 0 The IO will complete asynchronously.
1060 * @retval -1 There was an error; see @c errno to get the error code.
1063 virtual ssize_t recv (ACE_Message_Block *message_block,
1064 size_t &number_of_bytes_recvd,
1065 int flags,
1066 int protocol_family,
1067 const void *act,
1068 int priority,
1069 int signal_number);
1071 protected:
1072 /// Do-nothing constructor.
1073 ACE_POSIX_Asynch_Read_Dgram ();
1077 * @class ACE_POSIX__Asynch_Write_Dgram_Result
1079 * @brief This is class provides concrete implementation for
1080 * ACE_Asynch_Write_Dgram::Result class.
1082 class ACE_Export ACE_POSIX_Asynch_Write_Dgram_Result : public virtual ACE_Asynch_Write_Dgram_Result_Impl,
1083 public ACE_POSIX_Asynch_Result
1085 /// Factory classes will have special permissions.
1086 friend class ACE_POSIX_Asynch_Write_Dgram;
1088 /// Proactor class has special permission.
1089 friend class ACE_POSIX_Proactor;
1091 public:
1092 /// The number of bytes which were requested at the start of the
1093 /// asynchronous write.
1094 size_t bytes_to_write () const;
1096 /// Message block which contains the sent data
1097 ACE_Message_Block *message_block () const;
1099 /// The flags using in the write
1100 int flags () const;
1102 /// I/O handle used for writing.
1103 ACE_HANDLE handle () const;
1105 protected:
1106 /// Constructor is protected since creation is limited to
1107 /// ACE_Asynch_Write_Stream factory.
1108 ACE_POSIX_Asynch_Write_Dgram_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
1109 ACE_HANDLE handle,
1110 ACE_Message_Block *message_block,
1111 size_t bytes_to_write,
1112 int flags,
1113 const void* act,
1114 ACE_HANDLE event,
1115 int priority,
1116 int signal_number);
1118 /// ACE_Proactor will call this method when the write completes.
1119 virtual void complete (size_t bytes_transferred,
1120 int success,
1121 const void *completion_key,
1122 u_long error);
1124 /// Destructor.
1125 virtual ~ACE_POSIX_Asynch_Write_Dgram_Result ();
1127 /// The number of bytes which were requested at the start of the
1128 /// asynchronous write.
1129 size_t bytes_to_write_;
1131 /// Message block used for the send.
1132 ACE_Message_Block *message_block_;
1134 /// The flags using in the write
1135 int flags_;
1137 /// I/O handle used for writing.
1138 ACE_HANDLE handle_;
1142 * @class ACE_POSIX_Asynch_Write_Dgram
1144 * @brief This class is a factory for starting off asynchronous writes
1145 * on a UDP socket. The UDP socket must be "connected", as there is
1146 * no facility for specifying the destination address on each send
1147 * operation.
1149 * Once @c open() is called, multiple asynchronous writes can
1150 * started using this class. A ACE_Asynch_Write_Stream::Result
1151 * will be passed back to the associated completion handler when the
1152 * asynchronous write completes through the
1153 * ACE_Handler::handle_write_stream() callback.
1155 class ACE_Export ACE_POSIX_Asynch_Write_Dgram : public virtual ACE_Asynch_Write_Dgram_Impl,
1156 public ACE_POSIX_Asynch_Operation
1158 public:
1159 /// Constructor.
1160 ACE_POSIX_Asynch_Write_Dgram (ACE_POSIX_Proactor *posix_proactor);
1162 /// Destructor
1163 virtual ~ACE_POSIX_Asynch_Write_Dgram ();
1165 /** This method queues an asynchronous send. Up to
1166 * @a message_block->total_length bytes will be sent, beginning at the
1167 * read pointer. The @a message_block read pointer will be updated to
1168 * reflect the sent bytes if the send operation is successful completed.
1170 * Priority of the operation is specified by @a priority. On POSIX,
1171 * this is supported. Works like @c nice in Unix. Negative values are not
1172 * allowed. 0 means priority of the operation same as the process
1173 * priority. 1 means priority of the operation is one less than
1174 * process, etc.
1175 * @a signal_number is a no-op on non-POSIX4 systems.
1177 * @note Unlike the Windows version of this facility, no indication of
1178 * immediate success can be returned, and @a number_of_bytes_sent is
1179 * never used.
1181 * @arg flags Not used.
1182 * @arg addr Not used.
1183 * @retval 0 The IO will complete asynchronously.
1184 * @retval -1 There was an error; see @c errno to get the error code.
1186 virtual ssize_t send (ACE_Message_Block *message_block,
1187 size_t &number_of_bytes_sent,
1188 int flags,
1189 const ACE_Addr &addr,
1190 const void *act,
1191 int priority,
1192 int signal_number);
1194 protected:
1195 /// Do-nothing constructor.
1196 ACE_POSIX_Asynch_Write_Dgram ();
1200 /*****************************************************/
1203 * @class ACE_POSIX_Asynch_Read_Dgram_Result
1205 * @brief This is class provides concrete implementation for
1206 * ACE_Asynch_Read_Dgram::Result class.
1208 class ACE_Export ACE_POSIX_Asynch_Read_Dgram_Result : public virtual ACE_Asynch_Read_Dgram_Result_Impl,
1209 public virtual ACE_POSIX_Asynch_Result
1211 /// Factory classes will have special permissions.
1212 friend class ACE_POSIX_Asynch_Read_Dgram;
1214 /// Proactor class has special permission.
1215 friend class ACE_POSIX_Proactor;
1217 public:
1218 /// The number of bytes which were requested at the start of the
1219 /// asynchronous read.
1220 size_t bytes_to_read () const;
1222 /// Message block which contains the read data
1223 ACE_Message_Block *message_block () const;
1225 /// The address of where the packet came from
1226 int remote_address (ACE_Addr& addr) const;
1228 sockaddr *saddr () const;
1230 /// The flags used in the read
1231 int flags () const;
1233 /// I/O handle used for reading.
1234 ACE_HANDLE handle () const;
1236 protected:
1237 /// Constructor is protected since creation is limited to
1238 /// ACE_Asynch_Read_Dgram factory.
1239 ACE_POSIX_Asynch_Read_Dgram_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
1240 ACE_HANDLE handle,
1241 ACE_Message_Block *message_block,
1242 size_t bytes_to_read,
1243 int flags,
1244 int protocol_family,
1245 const void* act,
1246 ACE_HANDLE event,
1247 int priority,
1248 int signal_number = 0);
1250 /// Proactor will call this method when the read completes.
1251 virtual void complete (size_t bytes_transferred,
1252 int success,
1253 const void *completion_key,
1254 u_long error);
1256 /// Destructor.
1257 virtual ~ACE_POSIX_Asynch_Read_Dgram_Result ();
1259 /// Bytes requested when the asynchronous read was initiated.
1260 size_t bytes_to_read_;
1262 /// Message block for reading the data into.
1263 ACE_Message_Block *message_block_;
1265 /// The address of where the packet came from
1266 ACE_Addr *remote_address_;
1268 int addr_len_;
1270 /// The flags used in the read
1271 int flags_;
1273 /// I/O handle used for reading.
1274 ACE_HANDLE handle_;
1277 ACE_END_VERSIONED_NAMESPACE_DECL
1279 #endif /* ACE_HAS_AIO_CALLS */
1280 #endif /* ACE_POSIX_ASYNCH_IO_H */