3 //=============================================================================
5 * @file Asynch_IO_Impl.h
7 * This class contains asbtract base classes for all the concrete
8 * implementation classes for the various asynchronous operations
9 * that are used with the Praoctor.
11 * @author Irfan Pyarali (irfan@cs.wustl.edu)
12 * @author Tim Harrison (harrison@cs.wustl.edu)
13 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
14 * @author Roger Tragin <r.tragin@computer.org>
15 * @author Alexander Libman <alibman@ihug.com.au>
17 //=============================================================================
19 #ifndef ACE_ASYNCH_IO_IMPL_H
20 #define ACE_ASYNCH_IO_IMPL_H
21 #include /**/ "ace/pre.h"
23 #include /**/ "ace/config-all.h"
25 #if !defined (ACE_LACKS_PRAGMA_ONCE)
27 #endif /* ACE_LACKS_PRAGMA_ONCE */
29 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
30 // This only works on Win32 platforms and on Unix platforms supporting
33 #include "ace/Asynch_IO.h"
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
37 // Forward declaration.
38 class ACE_Proactor_Impl
;
41 * @class ACE_Asynch_Result_Impl
43 * @brief Abstract base class for the all the classes that provide
44 * concrete implementations for ACE_Asynch_Result.
46 class ACE_Export ACE_Asynch_Result_Impl
49 virtual ~ACE_Asynch_Result_Impl ();
51 /// Number of bytes transferred by the operation.
52 virtual size_t bytes_transferred () const = 0;
54 /// ACT associated with the operation.
55 virtual const void *act () const = 0;
57 /// Did the operation succeed?
58 virtual int success () const = 0;
60 /// This ACT is not the same as the ACT associated with the
61 /// asynchronous operation.
62 virtual const void *completion_key () const = 0;
64 /// Error value if the operation fail.
65 virtual u_long
error () const = 0;
67 /// Event associated with the OVERLAPPED structure.
68 virtual ACE_HANDLE
event () const = 0;
70 /// This really make sense only when doing file I/O.
71 virtual u_long
offset () const = 0;
72 virtual u_long
offset_high () const = 0;
74 /// Priority of the operation.
75 virtual int priority () const = 0;
78 * POSIX4 real-time signal number to be used for the
79 * operation. signal_number ranges from SIGRTMIN to SIGRTMAX. By
80 * default, SIGRTMIN is used to issue <aio_> calls. This is a no-op
81 * on non-POSIX4 systems and returns 0.
83 virtual int signal_number () const = 0;
87 // These two should really be protected. But sometimes it
88 // simplifies code to be able to "fake" a result. Use carefully.
89 /// This is called when the asynchronous operation completes.
90 virtual void complete (size_t bytes_transferred
,
92 const void *completion_key
,
93 u_long error
= 0) = 0;
95 /// Post @c this to the Proactor's completion port.
96 virtual int post_completion (ACE_Proactor_Impl
*proactor
) = 0;
99 /// Do-nothing constructor.
100 ACE_Asynch_Result_Impl ();
104 * @class ACE_Asynch_Operation_Impl
106 * @brief Abstract base class for all the concrete implementation
107 * classes that provide different implementations for the
108 * ACE_Asynch_Operation.
110 class ACE_Export ACE_Asynch_Operation_Impl
113 virtual ~ACE_Asynch_Operation_Impl ();
116 * Initializes the factory with information which will be used with
117 * each asynchronous call. If @a handle == ACE_INVALID_HANDLE,
118 * ACE_Handler::handle() will be called on the proxied handler to get the
121 virtual int open (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
123 const void *completion_key
,
124 ACE_Proactor
*proactor
) = 0;
127 * This cancels all pending accepts operations that were issued by
128 * the calling thread. The function does not cancel asynchronous
129 * operations issued by other threads.
131 virtual int cancel () = 0;
135 /// Return the underlying proactor.
136 virtual ACE_Proactor
* proactor () const = 0;
139 /// Do-nothing constructor.
140 ACE_Asynch_Operation_Impl ();
144 * @class ACE_Asynch_Read_Stream_Impl
146 * @brief Abstract base class for all the concrete implementation
147 * classes that provide different implementations for the
148 * ACE_Asynch_Read_Stream
150 class ACE_Export ACE_Asynch_Read_Stream_Impl
: public virtual ACE_Asynch_Operation_Impl
153 virtual ~ACE_Asynch_Read_Stream_Impl ();
155 /// This starts off an asynchronous read. Upto @a bytes_to_read will
156 /// be read and stored in the @a message_block.
157 virtual int read (ACE_Message_Block
&message_block
,
158 size_t bytes_to_read
,
161 int signal_number
) = 0;
163 #if defined (ACE_WIN32)
165 * Same as above but with scatter support, through chaining of composite
166 * message blocks using the continuation field.
168 virtual int readv (ACE_Message_Block
&message_block
,
169 size_t bytes_to_read
,
172 int signal_number
) = 0;
173 #endif /* defined (ACE_WIN32) */
176 /// Do-nothing constructor.
177 ACE_Asynch_Read_Stream_Impl ();
181 * @class ACE_Asynch_Read_Stream_Result_Impl
183 * @brief Abstract base class for all the concrete implementation
184 * classes that provide different implementations for the
185 * ACE_Asynch_Read_Stream::Result class.
187 class ACE_Export ACE_Asynch_Read_Stream_Result_Impl
: public virtual ACE_Asynch_Result_Impl
190 virtual ~ACE_Asynch_Read_Stream_Result_Impl ();
192 /// The number of bytes which were requested at the start of the
193 /// asynchronous read.
194 virtual size_t bytes_to_read () const = 0;
196 /// Message block which contains the read data.
197 virtual ACE_Message_Block
&message_block () const = 0;
199 /// I/O handle used for reading.
200 virtual ACE_HANDLE
handle () const = 0;
203 /// Do-nothing constructor.
204 ACE_Asynch_Read_Stream_Result_Impl ();
208 * @class ACE_Asynch_Write_Stream_Impl
210 * @brief Abstract base class for all the concrete implementation
211 * classes that provide different implementations for the
212 * ACE_Asynch_Write_Stream class.
214 class ACE_Export ACE_Asynch_Write_Stream_Impl
: public virtual ACE_Asynch_Operation_Impl
217 virtual ~ACE_Asynch_Write_Stream_Impl ();
219 /// This starts off an asynchronous write. Upto @a bytes_to_write
220 /// will be written from the @a message_block.
221 virtual int write (ACE_Message_Block
&message_block
,
222 size_t bytes_to_write
,
225 int signal_number
) = 0;
227 #if defined (ACE_WIN32)
229 * Same as above but with gather support, through chaining of composite
230 * message blocks using the continuation field.
232 virtual int writev (ACE_Message_Block
&message_block
,
233 size_t bytes_to_write
,
236 int signal_number
) = 0;
237 #endif /* defined (ACE_WIN32) */
240 /// Do-nothing constructor.
241 ACE_Asynch_Write_Stream_Impl ();
245 * @class ACE_Asynch_Write_Stream_Result_Impl
247 * @brief Abstract base class for all the concrete implementation
248 * classes that provide different implementations for the
249 * ACE_Asynch_Write_Stream::Result.
251 class ACE_Export ACE_Asynch_Write_Stream_Result_Impl
: public virtual ACE_Asynch_Result_Impl
254 virtual ~ACE_Asynch_Write_Stream_Result_Impl ();
256 /// The number of bytes which were requested at the start of the
257 /// asynchronous write.
258 virtual size_t bytes_to_write () const = 0;
260 /// Message block that contains the data to be written.
261 virtual ACE_Message_Block
&message_block () const = 0;
263 /// I/O handle used for writing.
264 virtual ACE_HANDLE
handle () const = 0;
267 /// Do-nothing constructor.
268 ACE_Asynch_Write_Stream_Result_Impl ();
272 * @class ACE_Asynch_Read_File_Impl
274 * @brief Abstract base class for all the concrete implementation
275 * classes that provide different implementations for the
276 * ACE_Asynch_Read_File::Result.
278 class ACE_Export ACE_Asynch_Read_File_Impl
: public virtual ACE_Asynch_Read_Stream_Impl
281 virtual ~ACE_Asynch_Read_File_Impl ();
284 * This starts off an asynchronous read. Upto @a bytes_to_read will
285 * be read and stored in the @a message_block. The read will start
286 * at @a offset from the beginning of the file.
288 virtual int read (ACE_Message_Block
&message_block
,
289 size_t bytes_to_read
,
294 int signal_number
) = 0;
296 #if defined (ACE_WIN32)
298 * Same as above but with scatter support, through chaining of composite
299 * message blocks using the continuation field.
300 * @note In win32 Each data block payload must be at least the size of a system
301 * memory page and must be aligned on a system memory page size boundary
303 virtual int readv (ACE_Message_Block
&message_block
,
304 size_t bytes_to_read
,
309 int signal_number
) = 0;
310 #endif /* defined (ACE_WIN32) */
312 /// This starts off an asynchronous read. Upto @a bytes_to_read will
313 /// be read and stored in the @a message_block.
314 virtual int read (ACE_Message_Block
&message_block
,
315 size_t bytes_to_read
,
318 int signal_number
) = 0;
320 #if defined (ACE_WIN32)
322 * Same as above but with scatter support, through chaining of composite
323 * message blocks using the continuation field.
325 virtual int readv (ACE_Message_Block
&message_block
,
326 size_t bytes_to_read
,
329 int signal_number
) = 0;
330 #endif /* defined (ACE_WIN32) */
333 /// Do-nothing constructor.
334 ACE_Asynch_Read_File_Impl ();
338 * @class ACE_Asynch_Read_File_Result_Impl
340 * @brief This is the abstract base class for all the concrete
341 * implementation classes for ACE_Asynch_Read_File::Result.
343 class ACE_Export ACE_Asynch_Read_File_Result_Impl
: public virtual ACE_Asynch_Read_Stream_Result_Impl
347 virtual ~ACE_Asynch_Read_File_Result_Impl ();
350 /// Do-nothing constructor.
351 ACE_Asynch_Read_File_Result_Impl ();
355 * @class ACE_Asynch_Write_File_Impl
357 * @brief Abstract base class for all the concrete implementation
358 * classes that provide different implementations for the
359 * ACE_Asynch_Write_File.
361 class ACE_Export ACE_Asynch_Write_File_Impl
: public virtual ACE_Asynch_Write_Stream_Impl
364 virtual ~ACE_Asynch_Write_File_Impl ();
367 * This starts off an asynchronous write. Upto @a bytes_to_write
368 * will be write and stored in the @a message_block. The write will
369 * start at @a offset from the beginning of the file.
371 virtual int write (ACE_Message_Block
&message_block
,
372 size_t bytes_to_write
,
377 int signal_number
) = 0;
379 #if defined (ACE_WIN32)
381 * Same as above but with gather support, through chaining of composite
382 * message blocks using the continuation field.
383 * @note In win32 Each data block payload must be at least the size of a system
384 * memory page and must be aligned on a system memory page size boundary
386 virtual int writev (ACE_Message_Block
&message_block
,
387 size_t bytes_to_write
,
392 int signal_number
) = 0;
393 #endif /* defined (ACE_WIN32) */
395 /// This starts off an asynchronous write. Upto @a bytes_to_write
396 /// will be written from the @a message_block.
397 virtual int write (ACE_Message_Block
&message_block
,
398 size_t bytes_to_write
,
401 int signal_number
) = 0;
403 #if defined (ACE_WIN32)
405 * Same as above but with gather support, through chaining of composite
406 * message blocks using the continuation field.
408 virtual int writev (ACE_Message_Block
&message_block
,
409 size_t bytes_to_write
,
412 int signal_number
) = 0;
413 #endif /* defined (ACE_WIN32) */
416 /// Do-nothing constructor.
417 ACE_Asynch_Write_File_Impl ();
421 * @class ACE_Asynch_Write_File_Result_Impl
423 * @brief This is the abstract base class for all the concrete
424 * implementation classes that provide different implementations
425 * for the ACE_Asynch_Write_File::Result.
427 class ACE_Export ACE_Asynch_Write_File_Result_Impl
: public virtual ACE_Asynch_Write_Stream_Result_Impl
430 virtual ~ACE_Asynch_Write_File_Result_Impl ();
433 /// Do-nothing constructor.
434 ACE_Asynch_Write_File_Result_Impl ();
438 * @class ACE_Asynch_Accept_Impl
440 * @brief Abstract base class for all the concrete implementation
441 * classes that provide different implementations for the
444 class ACE_Export ACE_Asynch_Accept_Impl
: public virtual ACE_Asynch_Operation_Impl
447 virtual ~ACE_Asynch_Accept_Impl ();
450 * This starts off an asynchronous accept. The asynchronous accept
451 * call also allows any initial data to be returned to the
452 * <handler>. Upto @a bytes_to_read will be read and stored in the
453 * @a message_block. The @a accept_handle will be used for the
454 * <accept> call. If (@a accept_handle == INVALID_HANDLE), a new
455 * handle will be created.
457 * @a message_block must be specified. This is because the address of
458 * the new connection is placed at the end of this buffer.
460 virtual int accept (ACE_Message_Block
&message_block
,
461 size_t bytes_to_read
,
462 ACE_HANDLE accept_handle
,
466 int addr_family
) = 0;
469 /// Do-nothing constructor.
470 ACE_Asynch_Accept_Impl ();
474 * @class ACE_Asynch_Accept_Result_Impl
476 * @brief Abstract base class for all the concrete implementation
477 * classes that provide different implementations for the
480 class ACE_Export ACE_Asynch_Accept_Result_Impl
: public virtual ACE_Asynch_Result_Impl
483 virtual ~ACE_Asynch_Accept_Result_Impl ();
485 /// The number of bytes which were requested at the start of the
486 /// asynchronous accept.
487 virtual size_t bytes_to_read () const = 0;
489 /// Message block which contains the read data.
490 virtual ACE_Message_Block
&message_block () const = 0;
492 /// I/O handle used for accepting new connections.
493 virtual ACE_HANDLE
listen_handle () const = 0;
495 /// I/O handle for the new connection.
496 virtual ACE_HANDLE
accept_handle () const = 0;
499 /// Do-nothing constructor.
500 ACE_Asynch_Accept_Result_Impl ();
505 * @class ACE_Asynch_Connect_Impl
507 * @brief Abstract base class for all the concrete implementation
508 * classes that provide different implementations for the
509 * ACE_Asynch_Connect.
511 class ACE_Export ACE_Asynch_Connect_Impl
: public virtual ACE_Asynch_Operation_Impl
514 virtual ~ACE_Asynch_Connect_Impl ();
517 * This starts off an asynchronous connect
519 virtual int connect (ACE_HANDLE connect_handle
,
520 const ACE_Addr
& remote_sap
,
521 const ACE_Addr
& local_sap
,
525 int signal_number
) = 0;
528 /// Do-nothing constructor.
529 ACE_Asynch_Connect_Impl ();
533 * @class ACE_Asynch_Connect_Result_Impl
535 * @brief Abstract base class for all the concrete implementation
536 * classes that provide different implementations for the
537 * ACE_Asynch_Connect.
539 class ACE_Export ACE_Asynch_Connect_Result_Impl
: public virtual ACE_Asynch_Result_Impl
542 virtual ~ACE_Asynch_Connect_Result_Impl ();
544 /// I/O handle for the connection.
545 virtual ACE_HANDLE
connect_handle () const = 0;
548 /// Do-nothing constructor.
549 ACE_Asynch_Connect_Result_Impl ();
554 * @class ACE_Asynch_Transmit_File_Impl
556 * @brief Abstract base class for all the concrete implementation
557 * classes that provide different implementations for the
558 * ACE_Asynch_Transmit_File.
560 class ACE_Asynch_Transmit_File_Impl
: public virtual ACE_Asynch_Operation_Impl
563 virtual ~ACE_Asynch_Transmit_File_Impl ();
565 /// This starts off an asynchronous transmit file.
566 virtual int transmit_file (ACE_HANDLE file
,
567 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer
,
568 size_t bytes_to_write
,
571 size_t bytes_per_send
,
575 int signal_number
) = 0;
578 /// Do-nothing constructor.
579 ACE_Asynch_Transmit_File_Impl ();
583 * @class ACE_Asynch_Transmit_File_Result_Impl
585 * @brief Abstract base class for all the concrete implementation
586 * classes that provide different implementations for the
587 * ACE_Asynch_Transmit_File::Result.
589 class ACE_Export ACE_Asynch_Transmit_File_Result_Impl
: public virtual ACE_Asynch_Result_Impl
592 virtual ~ACE_Asynch_Transmit_File_Result_Impl ();
594 /// Socket used for transmitting the file.
595 virtual ACE_HANDLE
socket () const = 0;
597 /// File from which the data is read.
598 virtual ACE_HANDLE
file () const = 0;
600 /// Header and trailer data associated with this transmit file.
601 virtual ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer () const = 0;
603 /// The number of bytes which were requested at the start of the
604 /// asynchronous transmit file.
605 virtual size_t bytes_to_write () const = 0;
607 /// Number of bytes per send requested at the start of the transmit
609 virtual size_t bytes_per_send () const = 0;
611 /// Flags which were passed into transmit file.
612 virtual u_long
flags () const = 0;
615 /// Do-nothing constructor.
616 ACE_Asynch_Transmit_File_Result_Impl ();
621 * @class ACE_Asynch_Read_Dgram_Impl
623 * @brief Abstract base class for all the concrete implementation
624 * classes that provide different implementations for the
625 * ACE_Asynch_Read_Dgram
627 class ACE_Export ACE_Asynch_Read_Dgram_Impl
: public virtual ACE_Asynch_Operation_Impl
630 virtual ~ACE_Asynch_Read_Dgram_Impl ();
632 /** This starts off an asynchronous read. Upto
633 * <message_block->total_size()> will be read and stored in the
634 * @a message_block. @a message_block's <wr_ptr> will be updated to reflect
635 * the added bytes if the read operation is successful completed.
636 * Return code of 1 means immediate success and <number_of_bytes_recvd>
637 * will contain number of bytes read. The <ACE_Handler::handle_read_dgram>
638 * method will still be called. Return code of 0 means the IO will
639 * complete proactively. Return code of -1 means there was an error, use
640 * errno to get the error code.
642 * Scatter/gather is supported on WIN32 by using the <message_block->cont()>
643 * method. Up to ACE_IOV_MAX @a message_block's are supported. Upto
644 * <message_block->size()> bytes will be read into each <message block> for
645 * a total of <message_block->total_size()> bytes. All @a message_block's
646 * <wr_ptr>'s will be updated to reflect the added bytes for each
649 * Priority of the operation is specified by @a priority. On POSIX4-Unix,
650 * this is supported. Works like <nice> in Unix. Negative values are not
651 * allowed. 0 means priority of the operation same as the process
652 * priority. 1 means priority of the operation is one less than
653 * process. And so forth. On Win32, @a priority is a no-op.
654 * @a signal_number is the POSIX4 real-time signal number to be used
655 * for the operation. @a signal_number ranges from ACE_SIGRTMIN to
656 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
658 virtual ssize_t
recv (ACE_Message_Block
*message_block
,
659 size_t &number_of_bytes_recvd
,
664 int signal_number
) = 0;
667 /// Do-nothing constructor.
668 ACE_Asynch_Read_Dgram_Impl ();
672 * @class ACE_Asynch_Read_Dgram_Result_Impl
674 * @brief Abstract base class for all the concrete implementation
675 * classes that provide different implementations for the
676 * ACE_Asynch_Read_Dgram::Result class.
678 class ACE_Export ACE_Asynch_Read_Dgram_Result_Impl
: public virtual ACE_Asynch_Result_Impl
681 virtual ~ACE_Asynch_Read_Dgram_Result_Impl ();
683 /// Message block which contains the read data
684 virtual ACE_Message_Block
*message_block () const = 0;
686 /// The number of bytes which were requested at the start of the
687 /// asynchronous read.
688 virtual size_t bytes_to_read () const = 0;
690 /// The address of where the packet came from
691 virtual int remote_address (ACE_Addr
& addr
) const = 0;
693 /// The flags used in the read
694 virtual int flags () const = 0;
696 /// I/O handle used for reading.
697 virtual ACE_HANDLE
handle () const = 0;
700 /// Do-nothing constructor.
701 ACE_Asynch_Read_Dgram_Result_Impl ();
705 * @class ACE_Asynch_Write_Dgram_Impl
707 * @brief Abstract base class for all the concrete implementation
708 * classes that provide different implementations for the
709 * ACE_Asynch_Write_Dgram class.
711 class ACE_Export ACE_Asynch_Write_Dgram_Impl
: public virtual ACE_Asynch_Operation_Impl
714 virtual ~ACE_Asynch_Write_Dgram_Impl ();
716 /** This starts off an asynchronous send. Upto
717 * <message_block->total_length()> will be sent. @a message_block's
718 * <rd_ptr> will be updated to reflect the sent bytes if the send operation
719 * is successful completed.
720 * Return code of 1 means immediate success and <number_of_bytes_sent>
721 * is updated to number of bytes sent. The <ACE_Handler::handle_write_dgram>
722 * method will still be called. Return code of 0 means the IO will
723 * complete proactively. Return code of -1 means there was an error, use
724 * errno to get the error code.
726 * Scatter/gather is supported on WIN32 by using the <message_block->cont()>
727 * method. Up to ACE_IOV_MAX @a message_block's are supported. Upto
728 * <message_block->length()> bytes will be sent from each <message block>
729 * for a total of <message_block->total_length()> bytes. All
730 * @a message_block's <rd_ptr>'s will be updated to reflect the bytes sent
731 * from each @a message_block.
733 * Priority of the operation is specified by @a priority. On POSIX4-Unix,
734 * this is supported. Works like <nice> in Unix. Negative values are not
735 * allowed. 0 means priority of the operation same as the process
736 * priority. 1 means priority of the operation is one less than
737 * process. And so forth. On Win32, this argument is a no-op.
738 * @a signal_number is the POSIX4 real-time signal number to be used
739 * for the operation. @a signal_number ranges from ACE_SIGRTMIN to
740 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
742 virtual ssize_t
send (ACE_Message_Block
*message_block
,
743 size_t &number_of_bytes_sent
,
745 const ACE_Addr
&addr
,
748 int signal_number
) = 0;
751 /// Do-nothing constructor.
752 ACE_Asynch_Write_Dgram_Impl ();
756 * @class ACE_Asynch_Write_Dgram_Result_Impl
758 * @brief Abstract base class for all the concrete implementation
759 * classes that provide different implementations for the
760 * ACE_Asynch_Write_Dgram::Result class.
762 class ACE_Export ACE_Asynch_Write_Dgram_Result_Impl
: public virtual ACE_Asynch_Result_Impl
765 virtual ~ACE_Asynch_Write_Dgram_Result_Impl ();
767 /// The number of bytes which were requested at the start of the
768 /// asynchronous write.
769 virtual size_t bytes_to_write () const = 0;
771 /// Message block which contains the sent data
772 virtual ACE_Message_Block
*message_block () const = 0;
774 /// The flags using in the write
775 virtual int flags () const = 0;
777 /// I/O handle used for writing.
778 virtual ACE_HANDLE
handle () const = 0;
781 /// Do-nothing constructor.
782 ACE_Asynch_Write_Dgram_Result_Impl ();
785 ACE_END_VERSIONED_NAMESPACE_DECL
787 #if defined (__ACE_INLINE__)
788 #include "ace/Asynch_IO_Impl.inl"
789 #endif /* __ACE_INLINE__ */
791 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
792 #include /**/ "ace/post.h"
793 #endif /* ACE_ASYNCH_IO_IMPL_H */