3 //=============================================================================
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)
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)
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
;
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
55 class ACE_Export ACE_POSIX_Asynch_Result
: public virtual ACE_Asynch_Result_Impl
,
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?
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;
83 * This really make sense only when doing file I/O.
85 * @@ On POSIX4-Unix, offset_high should be supported using
89 u_long
offset () const;
90 u_long
offset_high () const;
92 /// Priority of the operation.
93 int priority () const;
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
);
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
);
115 /// Constructor. <Event> is not used on POSIX.
116 ACE_POSIX_Asynch_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
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
135 /// Bytes transferred by this operation.
136 size_t bytes_transferred_
;
138 /// Success indicator.
141 /// ACT associated with handle.
142 const void *completion_key_
;
144 /// Error if operation failed.
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
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
167 int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
169 const void *completion_key
,
170 ACE_Proactor
*proactor
= 0);
172 /// Check the documentation for ACE_Asynch_Operation::cancel.
177 /// Return the underlying proactor.
178 ACE_Proactor
* proactor () const;
180 /// Return the underlying Proactor implementation.
181 ACE_POSIX_Proactor
* posix_proactor () const;
185 ACE_POSIX_Asynch_Operation (ACE_POSIX_Proactor
*posix_proactor
);
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
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.
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
;
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;
243 ACE_POSIX_Asynch_Read_Stream_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
245 ACE_Message_Block
&message_block
,
246 size_t bytes_to_read
,
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
256 virtual void complete (size_t bytes_transferred
,
258 const void *completion_key
,
262 virtual ~ACE_POSIX_Asynch_Read_Stream_Result ();
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
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
,
293 int signal_number
= 0);
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
;
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;
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
,
335 ACE_Message_Block
&message_block
,
336 size_t bytes_to_write
,
342 /// ACE_Proactor will call this method when the write completes.
343 virtual void complete (size_t bytes_transferred
,
345 const void *completion_key
,
349 virtual ~ACE_POSIX_Asynch_Write_Stream_Result ();
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
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
,
382 int signal_number
= 0);
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
;
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
,
408 ACE_Message_Block
&message_block
,
409 size_t bytes_to_read
,
417 /// ACE_Proactor will call this method when the read completes.
418 virtual void complete (size_t bytes_transferred
,
420 const void *completion_key
,
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>
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
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
,
461 int signal_number
= 0);
464 virtual ~ACE_POSIX_Asynch_Read_File ();
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
,
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
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
;
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
,
511 ACE_Message_Block
&message_block
,
512 size_t bytes_to_write
,
520 /// ACE_Proactor will call this method when the write completes.
521 virtual void complete (size_t bytes_transferred
,
523 const void *completion_key
,
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
538 class ACE_Export ACE_POSIX_Asynch_Write_File
: public virtual ACE_Asynch_Write_File_Impl
,
539 public ACE_POSIX_Asynch_Write_Stream
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
,
556 int signal_number
= 0);
559 virtual ~ACE_POSIX_Asynch_Write_File ();
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>
568 int write (ACE_Message_Block
&message_block
,
569 size_t bytes_to_write
,
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
;
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;
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
,
621 /// ACE_Proactor will call this method when the accept completes.
622 virtual void complete (size_t bytes_transferred
,
624 const void *completion_key
,
628 virtual ~ACE_POSIX_Asynch_Accept_Result ();
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
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
658 ACE_POSIX_Asynch_Accept (ACE_POSIX_Proactor
* posix_proactor
);
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
668 int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
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
,
689 int signal_number
= 0,
690 int addr_family
= AF_INET
);
693 * Cancel all pending pseudo-asynchronus requests
694 * Behavior as usual AIO request
699 * Close performs cancellation of all pending requests
700 * and closure the listen handle
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
);
718 /// flg_notify points whether or not we should send notification about
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
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
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
;
762 /// I/O handle for the connection.
763 ACE_HANDLE
connect_handle () const;
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
,
775 /// ACE_Proactor will call this method when the accept completes.
776 virtual void complete (size_t bytes_transferred
,
778 const void *completion_key
,
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
800 ACE_POSIX_Asynch_Connect (ACE_POSIX_Proactor
* posix_proactor
);
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
810 int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
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
,
828 int signal_number
= 0);
831 * Cancel all pending pseudo-asynchronus requests
832 * Behavior as usual AIO request
837 * Close performs cancellation of all pending requests.
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
) ;
857 int connect_i (ACE_POSIX_Asynch_Connect_Result
*result
,
858 const ACE_Addr
& remote_sap
,
859 const ACE_Addr
& local_sap
,
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
873 int cancel_uncompleted (bool flg_notify
, ACE_Handle_Set
&set
);
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
>
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
;
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
930 size_t bytes_per_send () const;
932 /// Flags which were passed into transmit file.
933 u_long
flags () const;
936 ACE_POSIX_Asynch_Transmit_File_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
939 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer
,
940 size_t bytes_to_write
,
943 size_t bytes_per_send
,
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
,
955 const void *completion_key
,
959 virtual ~ACE_POSIX_Asynch_Transmit_File_Result ();
961 /// Network I/O handle.
964 // aiocb::aio_filedes
967 /// Header and trailer data associated with this transmit file.
968 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer_
;
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
976 size_t bytes_per_send_
;
978 /// Flags which were passed into transmit file.
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
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
,
1011 size_t bytes_per_send
,
1015 int signal_number
= 0);
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
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>
1034 class ACE_Export ACE_POSIX_Asynch_Read_Dgram
: public virtual ACE_Asynch_Read_Dgram_Impl
,
1035 public ACE_POSIX_Asynch_Operation
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
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
,
1066 int protocol_family
,
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
;
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
1102 /// I/O handle used for writing.
1103 ACE_HANDLE
handle () const;
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
,
1110 ACE_Message_Block
*message_block
,
1111 size_t bytes_to_write
,
1118 /// ACE_Proactor will call this method when the write completes.
1119 virtual void complete (size_t bytes_transferred
,
1121 const void *completion_key
,
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
1137 /// I/O handle used for writing.
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
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
1160 ACE_POSIX_Asynch_Write_Dgram (ACE_POSIX_Proactor
*posix_proactor
);
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
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
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
,
1189 const ACE_Addr
&addr
,
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
;
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
1233 /// I/O handle used for reading.
1234 ACE_HANDLE
handle () const;
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
,
1241 ACE_Message_Block
*message_block
,
1242 size_t bytes_to_read
,
1244 int protocol_family
,
1248 int signal_number
= 0);
1250 /// Proactor will call this method when the read completes.
1251 virtual void complete (size_t bytes_transferred
,
1253 const void *completion_key
,
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_
;
1270 /// The flags used in the read
1273 /// I/O handle used for reading.
1277 ACE_END_VERSIONED_NAMESPACE_DECL
1279 #endif /* ACE_HAS_AIO_CALLS */
1280 #endif /* ACE_POSIX_ASYNCH_IO_H */