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 (void) const;
62 /// ACT associated with the operation.
63 const void *act (void) const;
65 /// Did the operation succeed?
66 int success (void) const;
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 (void) const;
76 /// Error value if the operation fails.
77 u_long
error (void) const;
79 /// This returns ACE_INVALID_HANDLE on POSIX4 platforms.
80 ACE_HANDLE
event (void) 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 (void) const;
90 u_long
offset_high (void) const;
92 /// Priority of the operation.
93 int priority (void) 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 (void) const;
102 /// Post @c this to the Proactor.
103 int post_completion (ACE_Proactor_Impl
*proactor
);
106 virtual ~ACE_POSIX_Asynch_Result (void);
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 (void) const;
180 /// Return the underlying Proactor implementation.
181 ACE_POSIX_Proactor
* posix_proactor (void) const;
185 ACE_POSIX_Asynch_Operation (ACE_POSIX_Proactor
*posix_proactor
);
188 virtual ~ACE_POSIX_Asynch_Operation (void);
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
226 /// Factory classes will have special permissions.
227 friend class ACE_POSIX_Asynch_Read_Stream
;
229 /// The Proactor constructs the Result class for faking results.
230 friend class ACE_POSIX_Proactor
;
233 /// The number of bytes which were requested at the start of the
234 /// asynchronous read.
235 size_t bytes_to_read (void) const;
237 /// Message block which contains the read data.
238 ACE_Message_Block
&message_block (void) const;
240 /// I/O handle used for reading.
241 ACE_HANDLE
handle (void) const;
244 ACE_POSIX_Asynch_Read_Stream_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
246 ACE_Message_Block
&message_block
,
247 size_t bytes_to_read
,
252 // Constructor is protected since creation is limited to
253 // ACE_Asynch_Read_Stream factory.
255 /// Get the data copied to this class, before calling application
257 virtual void complete (size_t bytes_transferred
,
259 const void *completion_key
,
263 virtual ~ACE_POSIX_Asynch_Read_Stream_Result (void);
266 // Bytes requested when the asynchronous read was initiated.
268 /// Message block for reading the data into.
269 ACE_Message_Block
&message_block_
;
271 // aiocb::aio_filedes
272 // I/O handle used for reading.
276 * @class ACE_POSIX_Asynch_Read_Stream
278 * This class implements <ACE_Asynch_Read_Stream> for all POSIX
279 * based implementation of Proactor.
281 class ACE_Export ACE_POSIX_Asynch_Read_Stream
: public virtual ACE_Asynch_Read_Stream_Impl
,
282 public ACE_POSIX_Asynch_Operation
286 ACE_POSIX_Asynch_Read_Stream (ACE_POSIX_Proactor
*posix_proactor
);
288 /// This starts off an asynchronous read. Upto @a bytes_to_read will
289 /// be read and stored in the @a message_block.
290 int read (ACE_Message_Block
&message_block
,
291 size_t bytes_to_read
,
294 int signal_number
= 0);
297 virtual ~ACE_POSIX_Asynch_Read_Stream (void);
302 * @class ACE_POSIX_Asynch_Write_Stream_Result
304 * @brief This class provides concrete implementation for
305 * <ACE_Asynch_Write_Stream::Result> on POSIX platforms.
307 * This class has all the information necessary for the
308 * @c handler to uniquiely identify the completion of the
309 * asynchronous write.
311 class ACE_Export ACE_POSIX_Asynch_Write_Stream_Result
: public virtual ACE_Asynch_Write_Stream_Result_Impl
,
312 public ACE_POSIX_Asynch_Result
314 /// Factory classes will have special privilages.
315 friend class ACE_POSIX_Asynch_Write_Stream
;
317 /// The Proactor constructs the Result class for faking results.
318 friend class ACE_POSIX_Proactor
;
321 /// The number of bytes which were requested at the start of the
322 /// asynchronous write.
323 size_t bytes_to_write (void) const;
325 /// Message block that contains the data to be written.
326 ACE_Message_Block
&message_block (void) const;
328 /// I/O handle used for writing.
329 ACE_HANDLE
handle (void) const;
332 /// Constructor is protected since creation is limited to
333 /// ACE_Asynch_Write_Stream factory.
334 ACE_POSIX_Asynch_Write_Stream_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
336 ACE_Message_Block
&message_block
,
337 size_t bytes_to_write
,
343 /// ACE_Proactor will call this method when the write completes.
344 virtual void complete (size_t bytes_transferred
,
346 const void *completion_key
,
350 virtual ~ACE_POSIX_Asynch_Write_Stream_Result (void);
354 // The number of bytes which were requested at the start of the
355 // asynchronous write.
357 /// Message block that contains the data to be written.
358 ACE_Message_Block
&message_block_
;
360 // aiocb::aio_filedes
361 // I/O handle used for writing.
365 * @class ACE_POSIX_Asynch_Write_Stream
367 * @brief This class implements <ACE_Asynch_Write_Stream> for
368 * all POSIX implementations of ACE_Proactor.
370 class ACE_Export ACE_POSIX_Asynch_Write_Stream
: public virtual ACE_Asynch_Write_Stream_Impl
,
371 public ACE_POSIX_Asynch_Operation
375 ACE_POSIX_Asynch_Write_Stream (ACE_POSIX_Proactor
*posix_proactor
);
377 /// This starts off an asynchronous write. Upto @a bytes_to_write
378 /// will be written from the @a message_block.
379 int write (ACE_Message_Block
&message_block
,
380 size_t bytes_to_write
,
383 int signal_number
= 0);
386 virtual ~ACE_POSIX_Asynch_Write_Stream (void);
390 * @class ACE_POSIX_Asynch_Read_File_Result
392 * @brief This class provides concrete implementation for
393 * <ACE_Asynch_Read_File::Result> class for POSIX platforms.
395 class ACE_Export ACE_POSIX_Asynch_Read_File_Result
: public virtual ACE_Asynch_Read_File_Result_Impl
,
396 public ACE_POSIX_Asynch_Read_Stream_Result
398 /// Factory classes will have special permissions.
399 friend class ACE_POSIX_Asynch_Read_File
;
401 /// The Proactor constructs the Result class for faking results.
402 friend class ACE_POSIX_Proactor
;
407 /// Constructor is protected since creation is limited to
408 /// ACE_Asynch_Read_File factory.
409 ACE_POSIX_Asynch_Read_File_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
411 ACE_Message_Block
&message_block
,
412 size_t bytes_to_read
,
420 /// ACE_Proactor will call this method when the read completes.
421 virtual void complete (size_t bytes_transferred
,
423 const void *completion_key
,
427 virtual ~ACE_POSIX_Asynch_Read_File_Result (void);
431 * @class ACE_POSIX_Asynch_Read_File
433 * @brief This class is a factory for starting off asynchronous reads
434 * on a file. This class implements <ACE_Asynch_Read_File> for
435 * all POSIX implementations of Proactor.
437 * Once <open> is called, multiple asynchronous <read>s can
438 * started using this class. A <ACE_Asynch_Read_File::Result>
439 * will be passed back to the @c handler when the asynchronous
440 * reads completes through the <ACE_Handler::handle_read_file>
443 * This class differs slightly from <ACE_Asynch_Read_Stream> as it
444 * allows the user to specify an offset for the read.
446 class ACE_Export ACE_POSIX_Asynch_Read_File
: public virtual ACE_Asynch_Read_File_Impl
,
447 public ACE_POSIX_Asynch_Read_Stream
452 ACE_POSIX_Asynch_Read_File (ACE_POSIX_Proactor
*posix_proactor
);
455 * This starts off an asynchronous read. Upto @a bytes_to_read will
456 * be read and stored in the @a message_block. The read will start
457 * at @a offset from the beginning of the file.
459 int read (ACE_Message_Block
&message_block
,
460 size_t bytes_to_read
,
465 int signal_number
= 0);
468 virtual ~ACE_POSIX_Asynch_Read_File (void);
472 * This belongs to ACE_POSIX_Asynch_Read_Stream. We have
473 * defined this here to avoid compiler warnings and forward the
474 * method to <ACE_POSIX_Asynch_Read_Stream::read>.
476 int read (ACE_Message_Block
&message_block
,
477 size_t bytes_to_read
,
480 int signal_number
= 0);
485 * @class ACE_POSIX_Asynch_Write_File_Result
487 * @brief This class provides implementation for
488 * <ACE_Asynch_Write_File_Result> for POSIX platforms.
490 * This class has all the information necessary for the
491 * @c handler to uniquiely identify the completion of the
492 * asynchronous write.
494 * This class differs slightly from
495 * <ACE_Asynch_Write_Stream::Result> as it calls back
496 * <ACE_Handler::handle_write_file> on the @c handler instead of
497 * <ACE_Handler::handle_write_stream>. No additional state is
498 * required by this class as <ACE_Asynch_Result> can store the
501 class ACE_Export ACE_POSIX_Asynch_Write_File_Result
: public virtual ACE_Asynch_Write_File_Result_Impl
,
502 public ACE_POSIX_Asynch_Write_Stream_Result
504 /// Factory classes will have special permissions.
505 friend class ACE_POSIX_Asynch_Write_File
;
507 /// The Proactor constructs the Result class for faking results.
508 friend class ACE_POSIX_Proactor
;
511 /// Constructor is protected since creation is limited to
512 /// ACE_Asynch_Write_File factory.
513 ACE_POSIX_Asynch_Write_File_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
515 ACE_Message_Block
&message_block
,
516 size_t bytes_to_write
,
524 /// ACE_Proactor will call this method when the write completes.
525 virtual void complete (size_t bytes_transferred
,
527 const void *completion_key
,
531 virtual ~ACE_POSIX_Asynch_Write_File_Result (void);
535 * @class ACE_POSIX_Asynch_Write_File
537 * This class provides concrete implementation for
538 * <ACE_Asynch_Write_File> for POSIX platforms where the
539 * completion strategy for Proactor is based on AIOCB (AIO
542 class ACE_Export ACE_POSIX_Asynch_Write_File
: public virtual ACE_Asynch_Write_File_Impl
,
543 public ACE_POSIX_Asynch_Write_Stream
547 ACE_POSIX_Asynch_Write_File (ACE_POSIX_Proactor
*posix_proactor
);
550 * This starts off an asynchronous write. Upto @a bytes_to_write
551 * will be written and stored in the @a message_block. The write will
552 * start at @a offset from the beginning of the file.
554 int write (ACE_Message_Block
&message_block
,
555 size_t bytes_to_write
,
560 int signal_number
= 0);
563 virtual ~ACE_POSIX_Asynch_Write_File (void);
567 * This <write> belongs to ACE_POSIX_Asynch_Write_Stream. We
568 * have put this here to avoid compiler warnings. We forward this
569 * method call to the <ACE_POSIX_Asynch_Write_Stream::write>
572 int write (ACE_Message_Block
&message_block
,
573 size_t bytes_to_write
,
576 int signal_number
= 0);
580 * @class ACE_POSIX_Asynch_Accept_Result
582 * @brief This is that class which will be passed back to the
583 * handler when the asynchronous accept completes.
585 * This class has all the information necessary for the
586 * handler to uniquiely identify the completion of the
587 * asynchronous accept.
589 class ACE_Export ACE_POSIX_Asynch_Accept_Result
: public virtual ACE_Asynch_Accept_Result_Impl
,
590 public ACE_POSIX_Asynch_Result
592 /// Factory classes will have special permissions.
593 friend class ACE_POSIX_Asynch_Accept
;
595 /// The Proactor constructs the Result class for faking results.
596 friend class ACE_POSIX_Proactor
;
599 /// The number of bytes which were requested at the start of the
600 /// asynchronous accept.
601 size_t bytes_to_read (void) const;
603 /// Message block which contains the read data.
604 ACE_Message_Block
&message_block (void) const;
606 /// I/O handle used for accepting new connections.
607 ACE_HANDLE
listen_handle (void) const;
609 /// I/O handle for the new connection.
610 ACE_HANDLE
accept_handle (void) const;
613 /// Constructor is protected since creation is limited to
614 /// ACE_Asynch_Accept factory.
615 ACE_POSIX_Asynch_Accept_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
616 ACE_HANDLE listen_handle
,
617 ACE_HANDLE accept_handle
,
618 ACE_Message_Block
&message_block
,
619 size_t bytes_to_read
,
625 /// ACE_Proactor will call this method when the accept completes.
626 virtual void complete (size_t bytes_transferred
,
628 const void *completion_key
,
632 virtual ~ACE_POSIX_Asynch_Accept_Result (void);
635 // Bytes requested when the asynchronous read was initiated.
636 // Actually, on POSIX implementation, we dont read any intial data.
638 /// Message block for reading the data into.
639 ACE_Message_Block
&message_block_
;
641 /// I/O handle used for accepting new connections.
642 ACE_HANDLE listen_handle_
;
644 // aiocb::aio_filedes
645 // I/O handle for the new connection.
650 * @class ACE_POSIX_Asynch_Accept
652 * @brief For the POSIX implementation this class is common for all Proactors
655 class ACE_Export ACE_POSIX_Asynch_Accept
:
656 public virtual ACE_Asynch_Accept_Impl
,
657 public ACE_POSIX_Asynch_Operation
,
658 public ACE_Event_Handler
663 ACE_POSIX_Asynch_Accept (ACE_POSIX_Proactor
* posix_proactor
);
666 virtual ~ACE_POSIX_Asynch_Accept (void);
669 * This <open> belongs to ACE_POSIX_Asynch_Operation. We forward
670 * this call to that method. We have put this here to avoid the
673 int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
675 const void *completion_key
,
676 ACE_Proactor
*proactor
= 0);
679 * This starts off an asynchronous accept. The asynchronous accept
680 * call also allows any initial data to be returned to the
681 * @c handler. Upto @a bytes_to_read will be read and stored in the
682 * @a message_block. The <accept_handle> will be used for the
683 * <accept> call. If (<accept_handle> == INVALID_HANDLE), a new
684 * handle will be created.
686 * @a message_block must be specified. This is because the address of
687 * the new connection is placed at the end of this buffer.
689 int accept (ACE_Message_Block
&message_block
,
690 size_t bytes_to_read
,
691 ACE_HANDLE accept_handle
,
694 int signal_number
= 0,
695 int addr_family
= AF_INET
);
698 * Cancel all pending pseudo-asynchronus requests
699 * Behavior as usual AIO request
704 * Close performs cancellation of all pending requests
705 * and closure the listen handle
709 /// virtual from ACE_Event_Handler
710 ACE_HANDLE
get_handle (void) const;
712 /// virtual from ACE_Event_Handler
713 void set_handle (ACE_HANDLE handle
);
715 /// virtual from ACE_Event_Handler
716 /// Called when accept event comes up on <listen_handle>
717 int handle_input (ACE_HANDLE handle
);
719 /// virtual from ACE_Event_Handler
720 int handle_close (ACE_HANDLE handle
, ACE_Reactor_Mask close_mask
);
723 /// flg_notify points whether or not we should send notification about
725 /// Parameter flg_notify can be
726 /// 0 - don't send notifications about canceled accepts
727 /// 1 - notify user about canceled accepts
728 /// according POSIX standards we should receive notifications
729 /// on canceled AIO requests
730 int cancel_uncompleted (int flg_notify
);
732 /// true - Accept is registered in ACE_Asynch_Pseudo_Task
733 /// false - Accept is deregisted in ACE_Asynch_Pseudo_Task
736 /// Queue of Result pointers that correspond to all the pending
737 /// accept operations.
738 ACE_Unbounded_Queue
<ACE_POSIX_Asynch_Accept_Result
*> result_queue_
;
740 /// The lock to protect the result queue which is shared. The queue
741 /// is updated by main thread in the register function call and
742 /// through the auxillary thread in the deregister fun. So let us
744 ACE_SYNCH_MUTEX lock_
;
748 * @class ACE_POSIX_Asynch_Connect_Result
750 * @brief This is that class which will be passed back to the
751 * completion handler when the asynchronous connect completes.
753 * This class has all the information necessary for a
754 * completion handler to uniquely identify the completion of the
755 * asynchronous connect.
757 class ACE_Export ACE_POSIX_Asynch_Connect_Result
: public virtual ACE_Asynch_Connect_Result_Impl
,
758 public ACE_POSIX_Asynch_Result
760 /// Factory classes will have special permissions.
761 friend class ACE_POSIX_Asynch_Connect
;
763 /// The Proactor constructs the Result class for faking results.
764 friend class ACE_POSIX_Proactor
;
768 /// I/O handle for the connection.
769 ACE_HANDLE
connect_handle (void) const;
772 /// Constructor is protected since creation is limited to
773 /// ACE_Asynch_Connect factory.
774 ACE_POSIX_Asynch_Connect_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
775 ACE_HANDLE connect_handle
,
781 /// ACE_Proactor will call this method when the accept completes.
782 virtual void complete (size_t bytes_transferred
,
784 const void *completion_key
,
788 virtual ~ACE_POSIX_Asynch_Connect_Result (void);
790 // aiocb::aio_filedes
791 // I/O handle for the new connection.
792 void connect_handle (ACE_HANDLE handle
);
797 * @class ACE_POSIX_Asynch_Connect
799 class ACE_Export ACE_POSIX_Asynch_Connect
:
800 public virtual ACE_Asynch_Connect_Impl
,
801 public ACE_POSIX_Asynch_Operation
,
802 public ACE_Event_Handler
807 ACE_POSIX_Asynch_Connect (ACE_POSIX_Proactor
* posix_proactor
);
810 virtual ~ACE_POSIX_Asynch_Connect (void);
813 * This belongs to ACE_POSIX_Asynch_Operation. We forward
814 * this call to that method. We have put this here to avoid the
817 int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
819 const void *completion_key
,
820 ACE_Proactor
*proactor
= 0);
823 * This starts off an asynchronous connect.
825 * @arg connect_handle will be used for the connect call. If
826 * ACE_INVALID_HANDLE is specified, a new
827 * handle will be created.
829 int connect (ACE_HANDLE connect_handle
,
830 const ACE_Addr
&remote_sap
,
831 const ACE_Addr
&local_sap
,
835 int signal_number
= 0);
838 * Cancel all pending pseudo-asynchronus requests
839 * Behavior as usual AIO request
844 * Close performs cancellation of all pending requests.
848 /// virtual from ACE_Event_Handler
849 ACE_HANDLE
get_handle (void) const;
851 /// virtual from ACE_Event_Handler
852 void set_handle (ACE_HANDLE handle
);
854 /// virtual from ACE_Event_Handler
855 /// The default action on handle_input() and handle_exception is to
856 /// return -1. Since that's what we want to do, just reuse them.
857 /// handle_output(), however, is where successful connects are reported.
858 int handle_output (ACE_HANDLE handle
);
860 /// virtual from ACE_Event_Handler
861 int handle_close (ACE_HANDLE handle
, ACE_Reactor_Mask close_mask
) ;
864 int connect_i (ACE_POSIX_Asynch_Connect_Result
*result
,
865 const ACE_Addr
& remote_sap
,
866 const ACE_Addr
& local_sap
,
869 int post_result (ACE_POSIX_Asynch_Connect_Result
*result
, bool flg_post
);
871 /// Cancel uncompleted connect operations.
873 * @arg flg_notify Indicates whether or not we should send notification
874 * about canceled accepts. If this is false, don't send
875 * notifications about canceled connects. If true, notify
876 * user about canceled connects according POSIX
877 * standards we should receive notifications on canceled
880 int cancel_uncompleted (bool flg_notify
, ACE_Handle_Set
&set
);
883 /// true - Connect is registered in ACE_Asynch_Pseudo_Task
884 /// false - Aceept is deregisted in ACE_Asynch_Pseudo_Task
886 typedef ACE_Map_Manager
<ACE_HANDLE
, ACE_POSIX_Asynch_Connect_Result
*, ACE_SYNCH_NULL_MUTEX
>
889 /// Map of Result pointers that correspond to all the pending connects.
890 MAP_MANAGER result_map_
;
892 /// The lock to protect the result map which is shared. The queue
893 /// is updated by main thread in the register function call and
894 /// through the auxillary thread in the asynch pseudo task.
895 ACE_SYNCH_MUTEX lock_
;
900 * @class ACE_POSIX_Asynch_Transmit_File_Result
902 * @brief This is that class which will be passed back to the
903 * <handler> when the asynchronous transmit file completes.
905 * This class has all the information necessary for the
906 * <handler> to uniquiely identify the completion of the
907 * asynchronous transmit file.
909 class ACE_Export ACE_POSIX_Asynch_Transmit_File_Result
: public virtual ACE_Asynch_Transmit_File_Result_Impl
,
910 public ACE_POSIX_Asynch_Result
912 /// Factory classes will have special permissions.
913 friend class ACE_POSIX_Asynch_Transmit_File
;
915 /// Handlers do all the job.
916 friend class ACE_POSIX_Asynch_Transmit_Handler
;
918 /// The Proactor constructs the Result class for faking results.
919 friend class ACE_POSIX_Proactor
;
922 /// Socket used for transmitting the file.
923 ACE_HANDLE
socket (void) const;
925 /// File from which the data is read.
926 ACE_HANDLE
file (void) const;
928 /// Header and trailer data associated with this transmit file.
929 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer (void) const;
931 /// The number of bytes which were requested at the start of the
932 /// asynchronous transmit file.
933 size_t bytes_to_write (void) const;
935 /// Number of bytes per send requested at the start of the transmit
937 size_t bytes_per_send (void) const;
939 /// Flags which were passed into transmit file.
940 u_long
flags (void) const;
943 ACE_POSIX_Asynch_Transmit_File_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
946 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer
,
947 size_t bytes_to_write
,
950 size_t bytes_per_send
,
956 // Constructor is protected since creation is limited to
957 // ACE_Asynch_Transmit_File factory.
959 /// ACE_Proactor will call this method when the write completes.
960 virtual void complete (size_t bytes_transferred
,
962 const void *completion_key
,
966 virtual ~ACE_POSIX_Asynch_Transmit_File_Result (void);
968 /// Network I/O handle.
971 // aiocb::aio_filedes
974 /// Header and trailer data associated with this transmit file.
975 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer_
;
978 // The number of bytes which were requested at the start of the
979 // asynchronous transmit file.
981 /// Number of bytes per send requested at the start of the transmit
983 size_t bytes_per_send_
;
985 /// Flags which were passed into transmit file.
990 * @class ACE_POSIX_Asynch_Transmit_File
992 * @brief Implementation for transmit_file will make use of
993 * POSIX_Asynch_Transmit_Handler.
995 class ACE_Export ACE_POSIX_Asynch_Transmit_File
: public virtual ACE_Asynch_Transmit_File_Impl
,
996 public ACE_POSIX_Asynch_Operation
1000 ACE_POSIX_Asynch_Transmit_File (ACE_POSIX_Proactor
*posix_proactor
);
1003 * This starts off an asynchronous transmit file. The <file> is a
1004 * handle to an open file. <header_and_trailer> is a pointer to a
1005 * data structure that contains pointers to data to send before and
1006 * after the file data is sent. Set this parameter to 0 if you only
1007 * want to transmit the file data. Upto @a bytes_to_write will be
1008 * written to the <socket>. If you want to send the entire file,
1009 * let @a bytes_to_write = 0. @a bytes_per_send is the size of each
1010 * block of data sent per send operation. Please read the POSIX
1011 * documentation on what the flags should be.
1013 int transmit_file (ACE_HANDLE file
,
1014 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer
,
1015 size_t bytes_to_write
,
1018 size_t bytes_per_send
,
1022 int signal_number
= 0);
1025 virtual ~ACE_POSIX_Asynch_Transmit_File (void);
1030 * @class ACE_POSIX_Asynch_Read_Dgram
1032 * @brief This class is a factory for starting off asynchronous reads
1035 * Once <open> is called, multiple asynchronous <read>s can be
1036 * started using this class. An ACE_Asynch_Read_Dgram::Result
1037 * will be passed back to the <handler> when the asynchronous
1038 * reads completes through the <ACE_Handler::handle_read_stream>
1041 class ACE_Export ACE_POSIX_Asynch_Read_Dgram
: public virtual ACE_Asynch_Read_Dgram_Impl
,
1042 public ACE_POSIX_Asynch_Operation
1046 ACE_POSIX_Asynch_Read_Dgram (ACE_POSIX_Proactor
*posix_proactor
);
1047 virtual ~ACE_POSIX_Asynch_Read_Dgram (void);
1049 /** This method queues an asynchronous read. Up to
1050 * @a message_block->total_size() bytes will be read and stored in the
1051 * @a message_block beginning at its write pointer. The @a message_block
1052 * write pointer will be updated to reflect any added bytes if the read
1053 * operation is successful completed.
1054 * Priority of the operation is specified by @a priority. On POSIX4-Unix,
1055 * this is supported. Works like <nice> in Unix. Negative values are not
1056 * allowed. 0 means priority of the operation same as the process
1057 * priority. 1 means priority of the operation is one less than
1058 * process. @a signal_number argument is a no-op on non-POSIX4 systems.
1060 * @note Unlike the Windows version of this facility, no indication of
1061 * immediate success can be returned, and @a number_of_bytes_read is
1064 * @arg flags Not used.
1065 * @arg protocol_family Not used.
1066 * @retval 0 The IO will complete asynchronously.
1067 * @retval -1 There was an error; see @c errno to get the error code.
1070 virtual ssize_t
recv (ACE_Message_Block
*message_block
,
1071 size_t &number_of_bytes_recvd
,
1073 int protocol_family
,
1079 /// Do-nothing constructor.
1080 ACE_POSIX_Asynch_Read_Dgram (void);
1084 * @class ACE_POSIX__Asynch_Write_Dgram_Result
1086 * @brief This is class provides concrete implementation for
1087 * ACE_Asynch_Write_Dgram::Result class.
1089 class ACE_Export ACE_POSIX_Asynch_Write_Dgram_Result
: public virtual ACE_Asynch_Write_Dgram_Result_Impl
,
1090 public ACE_POSIX_Asynch_Result
1092 /// Factory classes will have special permissions.
1093 friend class ACE_POSIX_Asynch_Write_Dgram
;
1095 /// Proactor class has special permission.
1096 friend class ACE_POSIX_Proactor
;
1099 /// The number of bytes which were requested at the start of the
1100 /// asynchronous write.
1101 size_t bytes_to_write (void) const;
1103 /// Message block which contains the sent data
1104 ACE_Message_Block
*message_block (void) const;
1106 /// The flags using in the write
1107 int flags (void) const;
1109 /// I/O handle used for writing.
1110 ACE_HANDLE
handle (void) const;
1113 /// Constructor is protected since creation is limited to
1114 /// ACE_Asynch_Write_Stream factory.
1115 ACE_POSIX_Asynch_Write_Dgram_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
1117 ACE_Message_Block
*message_block
,
1118 size_t bytes_to_write
,
1125 /// ACE_Proactor will call this method when the write completes.
1126 virtual void complete (size_t bytes_transferred
,
1128 const void *completion_key
,
1132 virtual ~ACE_POSIX_Asynch_Write_Dgram_Result (void);
1134 /// The number of bytes which were requested at the start of the
1135 /// asynchronous write.
1136 size_t bytes_to_write_
;
1138 /// Message block used for the send.
1139 ACE_Message_Block
*message_block_
;
1141 /// The flags using in the write
1144 /// I/O handle used for writing.
1150 * @class ACE_POSIX_Asynch_Write_Dgram
1152 * @brief This class is a factory for starting off asynchronous writes
1153 * on a UDP socket. The UDP socket must be "connected", as there is
1154 * no facility for specifying the destination address on each send
1157 * Once @c open() is called, multiple asynchronous writes can
1158 * started using this class. A ACE_Asynch_Write_Stream::Result
1159 * will be passed back to the associated completion handler when the
1160 * asynchronous write completes through the
1161 * ACE_Handler::handle_write_stream() callback.
1163 class ACE_Export ACE_POSIX_Asynch_Write_Dgram
: public virtual ACE_Asynch_Write_Dgram_Impl
,
1164 public ACE_POSIX_Asynch_Operation
1168 ACE_POSIX_Asynch_Write_Dgram (ACE_POSIX_Proactor
*posix_proactor
);
1171 virtual ~ACE_POSIX_Asynch_Write_Dgram (void);
1173 /** This method queues an asynchronous send. Up to
1174 * @a message_block->total_length bytes will be sent, beginning at the
1175 * read pointer. The @a message_block read pointer will be updated to
1176 * reflect the sent bytes if the send operation is successful completed.
1178 * Priority of the operation is specified by @a priority. On POSIX,
1179 * this is supported. Works like @c nice in Unix. Negative values are not
1180 * allowed. 0 means priority of the operation same as the process
1181 * priority. 1 means priority of the operation is one less than
1183 * @a signal_number is a no-op on non-POSIX4 systems.
1185 * @note Unlike the Windows version of this facility, no indication of
1186 * immediate success can be returned, and @a number_of_bytes_sent is
1189 * @arg flags Not used.
1190 * @arg addr Not used.
1191 * @retval 0 The IO will complete asynchronously.
1192 * @retval -1 There was an error; see @c errno to get the error code.
1194 virtual ssize_t
send (ACE_Message_Block
*message_block
,
1195 size_t &number_of_bytes_sent
,
1197 const ACE_Addr
&addr
,
1203 /// Do-nothing constructor.
1204 ACE_POSIX_Asynch_Write_Dgram (void);
1208 /*****************************************************/
1211 * @class ACE_POSIX_Asynch_Read_Dgram_Result
1213 * @brief This is class provides concrete implementation for
1214 * ACE_Asynch_Read_Dgram::Result class.
1216 class ACE_Export ACE_POSIX_Asynch_Read_Dgram_Result
: public virtual ACE_Asynch_Read_Dgram_Result_Impl
,
1217 public virtual ACE_POSIX_Asynch_Result
1220 /// Factory classes will have special permissions.
1221 friend class ACE_POSIX_Asynch_Read_Dgram
;
1223 /// Proactor class has special permission.
1224 friend class ACE_POSIX_Proactor
;
1227 /// The number of bytes which were requested at the start of the
1228 /// asynchronous read.
1229 size_t bytes_to_read (void) const;
1231 /// Message block which contains the read data
1232 ACE_Message_Block
*message_block (void) const;
1234 /// The address of where the packet came from
1235 int remote_address (ACE_Addr
& addr
) const;
1237 sockaddr
*saddr (void) const;
1239 /// The flags used in the read
1240 int flags (void) const;
1242 /// I/O handle used for reading.
1243 ACE_HANDLE
handle (void) const;
1246 /// Constructor is protected since creation is limited to
1247 /// ACE_Asynch_Read_Dgram factory.
1248 ACE_POSIX_Asynch_Read_Dgram_Result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
1250 ACE_Message_Block
*message_block
,
1251 size_t bytes_to_read
,
1253 int protocol_family
,
1257 int signal_number
= 0);
1259 /// Proactor will call this method when the read completes.
1260 virtual void complete (size_t bytes_transferred
,
1262 const void *completion_key
,
1266 virtual ~ACE_POSIX_Asynch_Read_Dgram_Result (void);
1268 /// Bytes requested when the asynchronous read was initiated.
1269 size_t bytes_to_read_
;
1271 /// Message block for reading the data into.
1272 ACE_Message_Block
*message_block_
;
1274 /// The address of where the packet came from
1275 ACE_Addr
*remote_address_
;
1279 /// The flags used in the read
1282 /// I/O handle used for reading.
1287 ACE_END_VERSIONED_NAMESPACE_DECL
1289 #endif /* ACE_HAS_AIO_CALLS */
1290 #endif /* ACE_POSIX_ASYNCH_IO_H */