Document return values
[ACE_TAO.git] / ACE / ace / Asynch_IO.h
blobc528be4188ef931b645b6ad9d96d17acae3cea98
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Asynch_IO.h
7 * This works on Win32 (defined (ACE_WIN32)) platforms and on
8 * POSIX4 platforms with {aio_*} routines (defined (ACE_HAS_AIO_CALLS))
10 * On Win32 platforms, the implementation of
11 * {ACE_Asynch_Transmit_File} and {ACE_Asynch_Accept} are only
12 * supported if ACE_HAS_WINSOCK2 is defined or you are on WinNT 4.0
13 * or higher.
15 * @author Irfan Pyarali <irfan@cs.wustl.edu>
16 * @author Tim Harrison <harrison@cs.wustl.edu>
17 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
18 * @author Roger Tragin <r.tragin@computer.org>
19 * @author Alexander Libman <alibman@ihug.com.au>
21 //=============================================================================
23 #ifndef ACE_ASYNCH_IO_H
24 #define ACE_ASYNCH_IO_H
25 #include /**/ "ace/pre.h"
27 #include /**/ "ace/ACE_export.h"
29 #if !defined (ACE_LACKS_PRAGMA_ONCE)
30 #pragma once
31 #endif /* ACE_LACKS_PRAGMA_ONCE */
33 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
35 #include "ace/Synch_Traits.h"
36 #if defined (ACE_HAS_THREADS)
37 # include "ace/Thread_Mutex.h"
38 #else
39 # include "ace/Null_Mutex.h"
40 #endif /* ACE_HAS_THREADS */
41 #include "ace/Refcounted_Auto_Ptr.h"
43 #include "ace/os_include/os_signal.h"
44 #include "ace/os_include/sys/os_socket.h"
45 #include "ace/os_include/sys/os_types.h"
47 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
49 # if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
50 typedef TRANSMIT_FILE_BUFFERS ACE_TRANSMIT_FILE_BUFFERS;
51 typedef LPTRANSMIT_FILE_BUFFERS ACE_LPTRANSMIT_FILE_BUFFERS;
52 typedef PTRANSMIT_FILE_BUFFERS ACE_PTRANSMIT_FILE_BUFFERS;
54 # define ACE_INFINITE INFINITE
55 # define ACE_STATUS_TIMEOUT STATUS_TIMEOUT
56 # define ACE_WAIT_FAILED WAIT_FAILED
57 # define ACE_WAIT_TIMEOUT WAIT_TIMEOUT
58 # else /* ACE_HAS_WIN32_OVERLAPPED_IO */
59 struct ACE_TRANSMIT_FILE_BUFFERS
61 void *Head;
62 size_t HeadLength;
63 void *Tail;
64 size_t TailLength;
66 typedef ACE_TRANSMIT_FILE_BUFFERS* ACE_PTRANSMIT_FILE_BUFFERS;
67 typedef ACE_TRANSMIT_FILE_BUFFERS* ACE_LPTRANSMIT_FILE_BUFFERS;
69 # if !defined (ACE_INFINITE)
70 # define ACE_INFINITE LONG_MAX
71 # endif /* ACE_INFINITE */
72 # define ACE_STATUS_TIMEOUT LONG_MAX
73 # define ACE_WAIT_FAILED LONG_MAX
74 # define ACE_WAIT_TIMEOUT LONG_MAX
75 # endif /* ACE_HAS_WIN32_OVERLAPPED_IO */
77 // Forward declarations
78 class ACE_Proactor;
79 class ACE_Handler;
80 class ACE_Message_Block;
81 class ACE_INET_Addr;
82 class ACE_Addr;
84 // Forward declarations
85 class ACE_Asynch_Result_Impl;
86 class ACE_Time_Value;
88 /**
89 * @class ACE_Asynch_Result
91 * @brief An interface base class which allows users access to common
92 * information related to an asynchronous operation.
94 * An interface base class from which you can obtain some basic
95 * information like the number of bytes transferred, the ACT
96 * associated with the asynchronous operation, indication of
97 * success or failure, etc. Subclasses may want to store more
98 * information that is particular to the asynchronous operation
99 * it represents.
101 class ACE_Export ACE_Asynch_Result
103 public:
104 /// Number of bytes transferred by the operation.
105 size_t bytes_transferred () const;
107 /// ACT associated with the operation.
108 const void *act () const;
110 /// Did the operation succeed?
111 int success () const;
114 * This is the ACT associated with the handle on which the
115 * Asynch_Operation takes place.
117 * On WIN32, this returns the ACT associated with the handle when it
118 * was registered with the I/O completion port.
120 * @@ This is not implemented for POSIX4 platforms. Returns 0.
122 const void *completion_key () const;
124 /// Error value if the operation fails.
125 unsigned long error () const;
128 * On WIN32, this returns the event associated with the OVERLAPPED
129 * structure.
131 * This returns ACE_INVALID_HANDLE on POSIX4-Unix platforms.
133 ACE_HANDLE event () const;
136 * This really makes sense only when doing file I/O.
138 * On WIN32, these are represented in the OVERLAPPED datastructure.
140 * @@ On POSIX4-Unix, offset_high should be supported using
141 * aiocb64.
143 unsigned long offset () const;
144 unsigned long offset_high () const;
147 * Priority of the operation.
149 * On POSIX4-Unix, this is supported. Priority works like {nice} in
150 * Unix. Negative values are not allowed. 0 means priority of the
151 * operation same as the process priority. 1 means priority of the
152 * operation is one less than process. And so forth.
154 * On Win32, this is a no-op.
156 int priority () const;
159 * POSIX4 real-time signal number to be used for the
160 * operation. {signal_number} ranges from ACE_SIGRTMIN to ACE_SIGRTMAX. By
161 * default, ACE_SIGRTMIN is used to issue {aio_} calls. This is a no-op
162 * on non-POSIX4 systems and returns 0.
164 int signal_number () const;
167 /// Destructor.
168 virtual ~ACE_Asynch_Result ();
170 protected:
171 /// Constructor. This implementation will not be deleted. The
172 /// implementation will be deleted by the Proactor.
173 ACE_Asynch_Result (ACE_Asynch_Result_Impl *implementation);
175 /// Get the implementation class.
176 ACE_Asynch_Result_Impl *implementation () const;
178 /// Implementation class.
179 ACE_Asynch_Result_Impl *implementation_;
182 // Forward declarations
183 class ACE_Asynch_Operation_Impl;
186 * @class ACE_Asynch_Operation
188 * @brief This is an interface base class for all asynch
189 * operations. The resposiblility of this class is to forward
190 * all methods to its delegation/implementation class, e.g.,
191 * ACE_WIN32_Asynch_Operation or ACE_POSIX_Asynch_Operation.
193 * There are some attributes and functionality which is common
194 * to all asychronous operations. The delegation classes of this
195 * class will factor out this code.
197 class ACE_Export ACE_Asynch_Operation
199 public:
201 * Initializes the factory with information which will be used with
202 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
203 * {ACE_Handler::handle} will be called on the {handler} to get the
204 * correct handle.
206 int open (ACE_Handler &handler,
207 ACE_HANDLE handle,
208 const void *completion_key,
209 ACE_Proactor *proactor);
212 * (Attempts to) cancel the asynchronous operation pending against
213 * the {handle} registered with this Operation.
215 * All completion notifications for the I/O operations will occur
216 * normally.
218 * = Return Values:
220 * -1 : Operation failed. (can get only in POSIX).
221 * 0 : All the operations were cancelled.
222 * 1 : All the operations were already finished in this
223 * handle. Unable to cancel them.
224 * 2 : Atleast one of the requested operations cannot be
225 * cancelled.
227 * There is slight difference in the semantics between NT and POSIX
228 * platforms which is given below.
230 * = Win32 :
232 * cancels all pending accepts operations that were issued by the
233 * calling thread. The function does not cancel asynchronous
234 * operations issued by other threads.
235 * All I/O operations that are canceled will complete with the
236 * error ERROR_OPERATION_ABORTED.
238 * = POSIX:
240 * Attempts to cancel one or more asynchronous I/O requests
241 * currently outstanding against the {handle} registered in this
242 * operation.
243 * For requested operations that are successfully canceled, the
244 * associated error status is set to ECANCELED.
246 int cancel ();
249 // = Access methods.
251 /// Return the underlying proactor.
252 ACE_Proactor* proactor () const;
254 /// Destructor.
255 virtual ~ACE_Asynch_Operation () = default;
257 protected:
258 /// Constructor.
259 ACE_Asynch_Operation () = default;
261 /// Return the underlying implementation class.
262 virtual ACE_Asynch_Operation_Impl *implementation () const = 0;
264 /// Get a proactor for/from the user
265 ACE_Proactor *get_proactor (ACE_Proactor *user_proactor,
266 ACE_Handler &handler) const;
269 // Forward declarations
270 class ACE_Asynch_Read_Stream_Result_Impl;
271 class ACE_Asynch_Read_Stream_Impl;
274 * @class ACE_Asynch_Read_Stream
276 * @brief This class is a factory for starting off asynchronous reads
277 * on a stream. This class forwards all methods to its
278 * implementation class.
280 * Once {open} is called, multiple asynchronous {read}s can
281 * started using this class. An ACE_Asynch_Read_Stream::Result
282 * will be passed back to the {handler} when the asynchronous
283 * reads completes through the {ACE_Handler::handle_read_stream}
284 * callback.
286 class ACE_Export ACE_Asynch_Read_Stream : public ACE_Asynch_Operation
288 public:
289 /// A do nothing constructor.
290 ACE_Asynch_Read_Stream ();
292 /// Destructor
293 virtual ~ACE_Asynch_Read_Stream ();
296 * Initializes the factory with information which will be used with
297 * each asynchronous call.
299 * @param handler The ACE_Handler that will be called to handle completions
300 * for operations initiated using this factory.
301 * @param handle The handle that future read operations will use.
302 * If handle == @c ACE_INVALID_HANDLE,
303 * ACE_Handler::handle() will be called on @ handler
304 * to get the correct handle.
306 * @retval 0 for success.
307 * @retval -1 for failure; consult @c errno for further information.
309 int open (ACE_Handler &handler,
310 ACE_HANDLE handle = ACE_INVALID_HANDLE,
311 const void *completion_key = 0,
312 ACE_Proactor *proactor = 0);
315 * Initiate an asynchronous read operation.
317 * @param message_block The ACE_Message_Block to receive the data.
318 * Received bytes will be placed in the block
319 * beginning at its current write pointer.
320 * If data is read, the message block's write
321 * pointer will be advanced by the number of
322 * bytes read.
323 * @param num_bytes_to_read The maximum number of bytes to read.
324 * @param act Asynchronous Completion Token; passed through to
325 * the completion handler in the Result object.
326 * @param priority Priority of the operation. On POSIX4-Unix,
327 * this is supported. Works like @c nice in Unix.
328 * Negative values are not allowed. 0 means
329 * priority of the operation same as the process
330 * priority. 1 means priority of the operation is
331 * one less than process priority, etc.
332 * Ignored on Windows.
333 * @param signal_number The POSIX4 real-time signal number to be used
334 * to signal completion of the operation. Values
335 * range from ACE_SIGRTMIN to ACE_SIGRTMAX.
336 * This argument is ignored on non-POSIX4 systems.
338 int read (ACE_Message_Block &message_block,
339 size_t num_bytes_to_read,
340 const void *act = 0,
341 int priority = 0,
342 int signal_number = ACE_SIGRTMIN);
344 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
346 * Same as above but with scatter support, through chaining of composite
347 * message blocks using the continuation field.
349 int readv (ACE_Message_Block &message_block,
350 size_t num_bytes_to_read,
351 const void *act = 0,
352 int priority = 0,
353 int signal_number = ACE_SIGRTMIN);
354 #endif /* defined (ACE_HAS_WIN32_OVERLAPPED_IO) */
356 /// Return the underlying implementation class.
357 // (this should be protected...)
358 virtual ACE_Asynch_Operation_Impl *implementation () const;
360 protected:
361 /// Implementation class that all methods will be forwarded to.
362 ACE_Asynch_Read_Stream_Impl *implementation_;
364 public:
366 * @class Result
368 * @brief This is the class which will be passed back to the
369 * ACE_Handler::handle_read_stream when the asynchronous read completes.
370 * This class forwards all the methods to the implementation classes.
372 * This class has all the information necessary for the
373 * handler to uniquiely identify the completion of the
374 * asynchronous read.
376 class ACE_Export Result : public ACE_Asynch_Result
378 /// The concrete implementation result classes only construct this
379 /// class.
380 friend class ACE_POSIX_Asynch_Read_Stream_Result;
381 friend class ACE_WIN32_Asynch_Read_Stream_Result;
383 public:
384 /// The number of bytes which were requested at the start of the
385 /// asynchronous read.
386 size_t bytes_to_read () const;
388 /// Message block which contains the read data.
389 ACE_Message_Block &message_block () const;
391 /// I/O handle used for reading.
392 ACE_HANDLE handle () const;
394 /// Get the implementation class.
395 ACE_Asynch_Read_Stream_Result_Impl *implementation () const;
397 protected:
398 /// Constructor.
399 Result (ACE_Asynch_Read_Stream_Result_Impl *implementation);
401 /// Destructor.
402 virtual ~Result ();
404 /// The implementation class.
405 ACE_Asynch_Read_Stream_Result_Impl *implementation_;
407 private:
408 void operator= (const ACE_Asynch_Read_Stream &) = delete;
409 ACE_Asynch_Read_Stream (const ACE_Asynch_Read_Stream &) = delete;
412 // Forward declarations
413 class ACE_Asynch_Write_Stream_Impl;
414 class ACE_Asynch_Write_Stream_Result_Impl;
417 * @class ACE_Asynch_Write_Stream
419 * @brief This class is a factory for initiating asynchronous writes
420 * on a connected TCP/IP stream. This class forwards all methods to its
421 * implementation class.
423 * Once open() is called, multiple asynchronous writes can be
424 * started using this class. An ACE_Asynch_Write_Stream::Result
425 * will be passed to the ACE_Handler::handle_write_stream() method on the
426 * opened ACE_Handler object when the asynchronous write completes.
428 class ACE_Export ACE_Asynch_Write_Stream : public ACE_Asynch_Operation
430 public:
431 /// A do nothing constructor.
432 ACE_Asynch_Write_Stream ();
434 /// Destructor.
435 virtual ~ACE_Asynch_Write_Stream ();
438 * Initializes the factory with information which will be used with
439 * each asynchronous operation.
441 * @param handler ACE_Handler to be notified when operations initiated
442 * via this factory complete. The handle_write_stream()
443 * method will be called on this object.
444 * @param handle The socket handle to initiate write operations on.
445 * If handle is @c ACE_INVALID_HANDLE,
446 * ACE_Handler::handle() will be called on handler to
447 * get the handle value.
448 * @param completion_key A token that is passed to the completion handler.
449 * @param proactor The ACE_Proactor object which will control operation
450 * completion and dispatching the results to handler.
451 * If this is 0, the process's singleton ACE_Proactor
452 * will be used.
454 * @retval 0 for success.
455 * @retval -1 for failure; consult @c errno for further information.
457 int open (ACE_Handler &handler,
458 ACE_HANDLE handle = ACE_INVALID_HANDLE,
459 const void *completion_key = 0,
460 ACE_Proactor *proactor = 0);
463 * Initiates an asynchronous write on a socket. If the operation completes
464 * the ACE_Handler object registered in open() will receive a completion
465 * callback via its handle_write_stream() method.
467 * @param bytes_to_write The number of bytes to write.
468 * @param message_block The ACE_Message_Block containing data to write.
469 * Data is written to the socket beginning at the
470 * block's rd_ptr. Upon successful completion
471 * of the write operation, the message_block rd_ptr
472 * is updated to reflect the data that was written.
473 * @param act Token that is passed through to the completion
474 * handler.
475 * @param priority Priority of the operation. This argument only has
476 * an affect on POSIX4-Unix. Works like @c nice in
477 * Unix; negative values are not allowed. 0 means
478 * priority of the operation same as the process
479 * priority. 1 means priority of the operation is one
480 * less than the process, and so forth.
481 * @param signal_number The POSIX4 real-time signal number to be used
482 * for the operation. signal_number ranges from
483 * ACE_SIGRTMIN to ACE_SIGRTMAX. This argument is
484 * not used on other platforms.
486 * @retval 0 for success, and the handle_write_stream associated
487 * with the opened ACE_Handler will be called. An
488 * instance of ACE_Asynch_Write_Stream::Result will be
489 * passed to the completion handler.
490 * @retval -1 for failure; consult @c errno for further information.
492 int write (ACE_Message_Block &message_block,
493 size_t bytes_to_write,
494 const void *act = 0,
495 int priority = 0,
496 int signal_number = ACE_SIGRTMIN);
498 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
500 * Same as above but with gather support, through chaining of composite
501 * message blocks using the continuation field.
503 int writev (ACE_Message_Block &message_block,
504 size_t bytes_to_write,
505 const void *act = 0,
506 int priority = 0,
507 int signal_number = ACE_SIGRTMIN);
508 #endif /* defined (ACE_HAS_WIN32_OVERLAPPED_IO) */
510 /// Return the underlying implementation class.
511 /// @todo (this should be protected...)
512 virtual ACE_Asynch_Operation_Impl *implementation () const;
514 protected:
515 /// Implementation class that all methods will be forwarded to.
516 ACE_Asynch_Write_Stream_Impl *implementation_;
518 public:
520 * @class Result
522 * @brief This is that class which will be passed back to the
523 * ACE_Handler when the asynchronous write completes. This class
524 * forwards all the methods to the implementation class.
526 * This class has all the information necessary for the
527 * handler to uniquiely identify the completion of the
528 * asynchronous write.
530 class ACE_Export Result : public ACE_Asynch_Result
532 /// The concrete implementation result classes only construct this
533 /// class.
534 friend class ACE_POSIX_Asynch_Write_Stream_Result;
535 friend class ACE_WIN32_Asynch_Write_Stream_Result;
537 public:
538 /// The number of bytes which were requested at the start of the
539 /// asynchronous write.
540 size_t bytes_to_write () const;
542 /// Message block that contains the data to be written.
543 ACE_Message_Block &message_block () const;
545 /// I/O handle used for writing.
546 ACE_HANDLE handle () const;
548 /// Get the implementation class.
549 ACE_Asynch_Write_Stream_Result_Impl *implementation () const;
551 protected:
552 /// Constructor.
553 Result (ACE_Asynch_Write_Stream_Result_Impl *implementation);
555 /// Destructor.
556 virtual ~Result ();
558 /// Implementation class.
559 ACE_Asynch_Write_Stream_Result_Impl *implementation_;
561 private:
562 void operator= (const ACE_Asynch_Write_Stream &) = delete;
563 ACE_Asynch_Write_Stream (const ACE_Asynch_Write_Stream &) = delete;
566 // Forward declarations
567 class ACE_Asynch_Read_File_Impl;
568 class ACE_Asynch_Read_File_Result_Impl;
571 * @class ACE_Asynch_Read_File
573 * @brief This class is a factory for starting off asynchronous reads
574 * on a file. This class forwards all methods to its
575 * implementation class.
577 * Once open() is called, multiple asynchronous reads can
578 * started using this class. An ACE_Asynch_Read_File::Result
579 * will be passed back to the completion handler's
580 * ACE_Handler::handle_read_file() method when each asynchronous
581 * read completes.
582 * This class differs slightly from ACE_Asynch_Read_Stream as it
583 * allows the user to specify an offset for the read.
585 class ACE_Export ACE_Asynch_Read_File : public ACE_Asynch_Read_Stream
587 public:
588 /// A do nothing constructor.
589 ACE_Asynch_Read_File ();
591 /// Destructor.
592 virtual ~ACE_Asynch_Read_File ();
595 * Initializes the factory with information which will be used with
596 * each asynchronous operation.
598 * @param handler ACE_Handler to be notified when operations initiated
599 * via this factory complete. The
600 * ACE_Handler::handle_read_file() method will be
601 * called on this object.
602 * @param handle The file handle to initiate read operations on.
603 * If handle is @c ACE_INVALID_HANDLE,
604 * ACE_Handler::handle() will be called on handler to
605 * get the handle value.
606 * @param completion_key A token that is passed to the completion handler.
607 * @param proactor The ACE_Proactor object which will control operation
608 * completion and dispatching the results to handler.
609 * If this is 0, the process's singleton ACE_Proactor
610 * will be used.
612 * @retval 0 for success.
613 * @retval -1 for failure; consult @c errno for further information.
615 int open (ACE_Handler &handler,
616 ACE_HANDLE handle = ACE_INVALID_HANDLE,
617 const void *completion_key = 0,
618 ACE_Proactor *proactor = 0);
621 * This starts off an asynchronous read. Upto {bytes_to_read} will
622 * be read and stored in the {message_block}. The read will start
623 * at {offset} from the beginning of the file. Priority of the
624 * operation is specified by {priority}. On POSIX4-Unix, this is
625 * supported. Works like {nice} in Unix. Negative values are not
626 * allowed. 0 means priority of the operation same as the process
627 * priority. 1 means priority of the operation is one less than
628 * process. And so forth. On Win32, this argument is a no-op.
629 * {signal_number} is the POSIX4 real-time signal number to be used
630 * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
631 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
633 int read (ACE_Message_Block &message_block,
634 size_t bytes_to_read,
635 unsigned long offset = 0,
636 unsigned long offset_high = 0,
637 const void *act = 0,
638 int priority = 0,
639 int signal_number = ACE_SIGRTMIN);
641 #if defined (ACE_WIN32)
643 * Same as above but with scatter support, through chaining of composite
644 * message blocks using the continuation field.
645 * @note In win32 Each data block payload must be at least the size of a system
646 * memory page and must be aligned on a system memory page size boundary
648 int readv (ACE_Message_Block &message_block,
649 size_t bytes_to_read,
650 unsigned long offset = 0,
651 unsigned long offset_high = 0,
652 const void *act = 0,
653 int priority = 0,
654 int signal_number = ACE_SIGRTMIN);
655 #endif /* defined (ACE_WIN32) */
657 /// Return the underlying implementation class.
658 // (this should be protected...)
659 virtual ACE_Asynch_Operation_Impl *implementation () const;
661 protected:
662 /// Delegation/implementation class that all methods will be
663 /// forwarded to.
664 ACE_Asynch_Read_File_Impl *implementation_;
666 public:
668 * @class Result
670 * @brief This is that class which will be passed back to the
671 * {handler} when the asynchronous read completes. This class
672 * forwards all the methods to the implementation class.
674 * This class has all the information necessary for the
675 * {handler} to uniquiely identify the completion of the
676 * asynchronous read.
677 * This class differs slightly from
678 * ACE_Asynch_Read_Stream::Result as it calls back
679 * {ACE_Handler::handle_read_file} on the {handler} instead of
680 * {ACE_Handler::handle_read_stream}. No additional state is
681 * required by this class as ACE_Asynch_Result can store the
682 * {offset}.
684 class ACE_Export Result : public ACE_Asynch_Read_Stream::Result
686 /// The concrete implementation result classes only construct this
687 /// class.
688 friend class ACE_POSIX_Asynch_Read_File_Result;
689 friend class ACE_WIN32_Asynch_Read_File_Result;
691 public:
692 /// Get the implementation class.
693 ACE_Asynch_Read_File_Result_Impl *implementation () const;
695 protected:
696 /// Constructor. This implementation will not be deleted.
697 Result (ACE_Asynch_Read_File_Result_Impl *implementation);
699 /// Destructor.
700 virtual ~Result ();
702 /// The implementation class.
703 ACE_Asynch_Read_File_Result_Impl *implementation_;
705 private:
706 /// Here just to provide an dummy implementation, since the
707 /// one auto generated by MSVC is flagged as infinitely recursive
708 void operator= (Result &) {}
710 private:
711 void operator= (const ACE_Asynch_Read_File &) = delete;
712 ACE_Asynch_Read_File (const ACE_Asynch_Read_File &) = delete;
715 // Forward declarations
716 class ACE_Asynch_Write_File_Impl;
717 class ACE_Asynch_Write_File_Result_Impl;
720 * @class ACE_Asynch_Write_File
722 * @brief This class is a factory for starting off asynchronous writes
723 * on a file. This class forwards all methods to its
724 * implementation class.
726 * Once {open} is called, multiple asynchronous {write}s can be
727 * started using this class. A ACE_Asynch_Write_File::Result
728 * will be passed back to the {handler} when the asynchronous
729 * writes completes through the {ACE_Handler::handle_write_file}
730 * callback.
731 * This class differs slightly from ACE_Asynch_Write_Stream as
732 * it allows the user to specify an offset for the write.
734 class ACE_Export ACE_Asynch_Write_File : public ACE_Asynch_Write_Stream
736 public:
737 /// A do nothing constructor.
738 ACE_Asynch_Write_File ();
740 /// Destructor.
741 virtual ~ACE_Asynch_Write_File ();
744 * Initializes the factory with information which will be used with
745 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
746 * {ACE_Handler::handle} will be called on the {handler} to get the
747 * correct handle.
749 int open (ACE_Handler &handler,
750 ACE_HANDLE handle = ACE_INVALID_HANDLE,
751 const void *completion_key = 0,
752 ACE_Proactor *proactor = 0);
755 * This starts off an asynchronous write. Upto {bytes_to_write}
756 * will be written from the {message_block}, starting at the
757 * block's {rd_ptr}. The write will go to the file, starting
758 * {offset} bytes from the beginning of the file. Priority of the
759 * operation is specified by {priority}. On POSIX4-Unix, this is
760 * supported. Works like {nice} in Unix. Negative values are not
761 * allowed. 0 means priority of the operation same as the process
762 * priority. 1 means priority of the operation is one less than
763 * process. And so forth. On Win32, this is a no-op.
764 * {signal_number} is the POSIX4 real-time signal number to be used
765 * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
766 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
768 int write (ACE_Message_Block &message_block,
769 size_t bytes_to_write,
770 unsigned long offset = 0,
771 unsigned long offset_high = 0,
772 const void *act = 0,
773 int priority = 0,
774 int signal_number = ACE_SIGRTMIN);
776 #if defined (ACE_WIN32)
778 * Same as above but with gather support, through chaining of composite
779 * message blocks using the continuation field.
780 * @note In win32 Each data block payload must be at least the size of a system
781 * memory page and must be aligned on a system memory page size boundary
783 int writev (ACE_Message_Block &message_block,
784 size_t bytes_to_write,
785 unsigned long offset = 0,
786 unsigned long offset_high = 0,
787 const void *act = 0,
788 int priority = 0,
789 int signal_number = ACE_SIGRTMIN);
790 #endif /* defined (ACE_WIN32) */
792 /// Return the underlying implementation class.
793 // (this should be protected...)
794 virtual ACE_Asynch_Operation_Impl *implementation () const;
796 protected:
797 /// Implementation object.
798 ACE_Asynch_Write_File_Impl *implementation_;
800 public:
802 * @class Result
804 * @brief This is that class which will be passed back to the
805 * {handler} when the asynchronous write completes. This class
806 * forwards all the methods to the implementation class.
808 * This class has all the information necessary for the
809 * {handler} to uniquiely identify the completion of the
810 * asynchronous write.
811 * This class differs slightly from
812 * ACE_Asynch_Write_Stream::Result as it calls back
813 * {ACE_Handler::handle_write_file} on the {handler} instead
814 * of {ACE_Handler::handle_write_stream}. No additional state
815 * is required by this class as ACE_Asynch_Result can store
816 * the {offset}.
818 class ACE_Export Result : public ACE_Asynch_Write_Stream::Result
820 /// The concrete implementation result classes only construct this
821 /// class.
822 friend class ACE_POSIX_Asynch_Write_File_Result;
823 friend class ACE_WIN32_Asynch_Write_File_Result;
825 public:
826 /// Get the implementation class.
827 ACE_Asynch_Write_File_Result_Impl *implementation () const;
829 protected:
830 /// Constructor. This implementation will not be deleted.
831 Result (ACE_Asynch_Write_File_Result_Impl *implementation);
833 /// Destructor.
834 virtual ~Result ();
836 /// The implementation class.
837 ACE_Asynch_Write_File_Result_Impl *implementation_;
839 private:
840 /// Here just to provide an dummy implementation, since the
841 /// one auto generated by MSVC is flagged as infinitely recursive
842 void operator= (Result &) {}
844 private:
845 void operator= (const ACE_Asynch_Write_File &) = delete;
846 ACE_Asynch_Write_File (const ACE_Asynch_Write_File &) = delete;
849 // Forward declarations
850 class ACE_Asynch_Accept_Result_Impl;
851 class ACE_Asynch_Accept_Impl;
854 * @class ACE_Asynch_Accept
856 * @brief This class is a factory for starting off asynchronous accepts
857 * on a listen handle. This class forwards all methods to its
858 * implementation class.
860 * Once {open} is called, multiple asynchronous {accept}s can
861 * started using this class. A ACE_Asynch_Accept::Result will
862 * be passed back to the {handler} when the asynchronous accept
863 * completes through the {ACE_Handler::handle_accept}
864 * callback.
866 class ACE_Export ACE_Asynch_Accept : public ACE_Asynch_Operation
868 public:
869 /// A do nothing constructor.
870 ACE_Asynch_Accept ();
872 /// Destructor.
873 virtual ~ACE_Asynch_Accept ();
876 * Initializes the factory with information which will be used with
877 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
878 * {ACE_Handler::handle} will be called on the {handler} to get the
879 * correct handle.
881 int open (ACE_Handler &handler,
882 ACE_HANDLE handle = ACE_INVALID_HANDLE,
883 const void *completion_key = 0,
884 ACE_Proactor *proactor = 0);
887 * This starts off an asynchronous accept. The asynchronous accept
888 * call also allows any initial data to be returned to the
889 * handler specified to @c open().
890 * @param message_block A message block to receive initial data, as well
891 * as the local and remote addresses when the
892 * connection is made. Since the block receives
893 * the addresses regardless of whether or not
894 * initial data is available or requested, the
895 * message block size must be at least
896 * @a bytes_to_read plus two times the size of
897 * the addresses used (IPv4 or IPv6).
898 * @param bytes_to_read The maximum number of bytes of initial data
899 * to read into @a message_block.
900 * @param accept_handle The handle that the new connection will be
901 * accepted on. If @c INVALID_HANDLE, a new
902 * handle will be created using @a addr_family.
903 * @param act Value to be passed in result when operation
904 * completes.
905 * @param priority Priority of the operation. On POSIX4-Unix, this
906 * is supported. Works like @c nice in Unix.
907 * Negative values are not allowed. 0 means
908 * priority of the operation same as the process
909 * priority. 1 means priority of the operation is
910 * one less than process. And so forth.
911 * On Win32, this argument is ignored.
912 * @param signal_number The POSIX4 real-time signal number to be used
913 * for the operation. Value range is from
914 * @c ACE_SIGRTMIN to @c ACE_SIGRTMAX.
915 * This argument is ignored on non-POSIX4 systems.
916 * @param addr_family The address family to use if @a accept_handle
917 * is @c ACE_INVALID_HANDLE and a new handle must
918 * be opened. Values are @c AF_INET and @c PF_INET6.
920 int accept (ACE_Message_Block &message_block,
921 size_t bytes_to_read,
922 ACE_HANDLE accept_handle = ACE_INVALID_HANDLE,
923 const void *act = 0,
924 int priority = 0,
925 int signal_number = ACE_SIGRTMIN,
926 int addr_family = AF_INET);
928 /// Return the underlying implementation class.
929 // (this should be protected...)
930 virtual ACE_Asynch_Operation_Impl *implementation () const;
932 protected:
933 /// Delegation/implementation class that all methods will be
934 /// forwarded to.
935 ACE_Asynch_Accept_Impl *implementation_;
937 public:
939 * @class Result
941 * @brief This is that class which will be passed back to the
942 * {handler} when the asynchronous accept completes.
944 * This class has all the information necessary for the
945 * {handler} to uniquiely identify the completion of the
946 * asynchronous accept.
948 class ACE_Export Result : public ACE_Asynch_Result
950 /// The concrete implementation result classes only construct this
951 /// class.
952 friend class ACE_POSIX_Asynch_Accept_Result;
953 friend class ACE_WIN32_Asynch_Accept_Result;
955 public:
956 /// The number of bytes which were requested at the start of the
957 /// asynchronous accept.
958 size_t bytes_to_read () const;
960 /// Message block which contains the read data.
961 ACE_Message_Block &message_block () const;
963 /// I/O handle used for accepting new connections.
964 ACE_HANDLE listen_handle () const;
966 /// I/O handle for the new connection.
967 ACE_HANDLE accept_handle () const;
969 /// Get the implementation.
970 ACE_Asynch_Accept_Result_Impl *implementation () const;
972 protected:
973 /// Constructor. Implementation will not be deleted.
974 Result (ACE_Asynch_Accept_Result_Impl *implementation);
976 /// Destructor.
977 virtual ~Result ();
979 /// Implementation class.
980 ACE_Asynch_Accept_Result_Impl *implementation_;
982 private:
983 void operator= (const ACE_Asynch_Accept &) = delete;
984 ACE_Asynch_Accept (const ACE_Asynch_Accept &) = delete;
986 // Forward declarations
987 class ACE_Asynch_Connect_Result_Impl;
988 class ACE_Asynch_Connect_Impl;
991 * @class ACE_Asynch_Connect
993 * @brief This class is a factory for starting off asynchronous connects
994 * This class forwards all methods to its implementation class.
996 * Once @c open is called, multiple asynchronous connect operationss can
997 * started using this class. A ACE_Asynch_Connect::Result will
998 * be passed back to the associated ACE_Handler when the asynchronous connect
999 * completes through the ACE_Handler::handle_connect() callback.
1001 class ACE_Export ACE_Asynch_Connect : public ACE_Asynch_Operation
1003 public:
1004 /// A do nothing constructor.
1005 ACE_Asynch_Connect ();
1007 /// Destructor.
1008 virtual ~ACE_Asynch_Connect ();
1011 * Initializes the factory with information which will be used with
1012 * each asynchronous call.
1014 * @note @arg handle is ignored and should be @c ACE_INVALID_HANDLE.
1016 int open (ACE_Handler &handler,
1017 ACE_HANDLE handle = ACE_INVALID_HANDLE,
1018 const void *completion_key = 0,
1019 ACE_Proactor *proactor = 0);
1022 * This starts off an asynchronous Connect.
1024 int connect (ACE_HANDLE connect_handle,
1025 const ACE_Addr & remote_sap,
1026 const ACE_Addr & local_sap,
1027 int reuse_addr,
1028 const void *act=0,
1029 int priority = 0,
1030 int signal_number = ACE_SIGRTMIN);
1032 /// Return the underlying implementation class.
1033 // (this should be protected...)
1034 virtual ACE_Asynch_Operation_Impl *implementation () const;
1036 protected:
1037 /// Delegation/implementation class that all methods will be
1038 /// forwarded to.
1039 ACE_Asynch_Connect_Impl *implementation_;
1041 public:
1043 * @class Result
1045 * @brief This is that class which will be passed back to the
1046 * handler when the asynchronous connect completes.
1048 * This class has all the information necessary for the
1049 * handler to uniquely identify the completion of the
1050 * asynchronous connect.
1052 class ACE_Export Result : public ACE_Asynch_Result
1054 /// The concrete implementation result classes only construct this
1055 /// class.
1056 friend class ACE_POSIX_Asynch_Connect_Result;
1057 friend class ACE_WIN32_Asynch_Connect_Result;
1059 public:
1060 /// I/O handle for the connection.
1061 ACE_HANDLE connect_handle () const;
1063 /// Get the implementation.
1064 ACE_Asynch_Connect_Result_Impl *implementation () const;
1066 protected:
1067 /// Constructor. Implementation will not be deleted.
1068 Result (ACE_Asynch_Connect_Result_Impl *implementation);
1070 /// Destructor.
1071 virtual ~Result ();
1073 /// Implementation class.
1074 ACE_Asynch_Connect_Result_Impl *implementation_;
1076 private:
1077 void operator= (const ACE_Asynch_Connect &) = delete;
1078 ACE_Asynch_Connect (const ACE_Asynch_Connect &) = delete;
1081 // Forward declarations
1082 class ACE_Asynch_Transmit_File_Result_Impl;
1083 class ACE_Asynch_Transmit_File_Impl;
1086 * @class ACE_Asynch_Transmit_File
1088 * @brief This class is a factory for starting off asynchronous
1089 * transmit files on a stream.
1091 * Once {open} is called, multiple asynchronous {transmit_file}s
1092 * can started using this class. A
1093 * ACE_Asynch_Transmit_File::Result will be passed back to the
1094 * {handler} when the asynchronous transmit file completes
1095 * through the {ACE_Handler::handle_transmit_file} callback.
1096 * The transmit_file function transmits file data over a
1097 * connected network connection. The function uses the operating
1098 * system's cache manager to retrieve the file data. This
1099 * function provides high-performance file data transfer over
1100 * network connections. This function would be of great use in
1101 * a Web Server, Image Server, etc.
1103 class ACE_Export ACE_Asynch_Transmit_File : public ACE_Asynch_Operation
1105 public:
1106 // Forward declarations
1107 class Header_And_Trailer;
1109 /// A do nothing constructor.
1110 ACE_Asynch_Transmit_File ();
1112 /// Destructor.
1113 virtual ~ACE_Asynch_Transmit_File ();
1116 * Initializes the factory with information which will be used with
1117 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
1118 * {ACE_Handler::handle} will be called on the {handler} to get the
1119 * correct handle.
1121 int open (ACE_Handler &handler,
1122 ACE_HANDLE handle = ACE_INVALID_HANDLE,
1123 const void *completion_key = 0,
1124 ACE_Proactor *proactor = 0);
1127 * This starts off an asynchronous transmit file. The {file} is a
1128 * handle to an open file. {header_and_trailer} is a pointer to a
1129 * data structure that contains pointers to data to send before and
1130 * after the file data is sent. Set this parameter to 0 if you only
1131 * want to transmit the file data. Upto {bytes_to_write} will be
1132 * written to the {socket}. If you want to send the entire file,
1133 * let {bytes_to_write} = 0. {bytes_per_send} is the size of each
1134 * block of data sent per send operation. Please read the Win32
1135 * documentation on what the flags should be. Priority of the
1136 * operation is specified by {priority}. On POSIX4-Unix, this is
1137 * supported. Works like {nice} in Unix. Negative values are not
1138 * allowed. 0 means priority of the operation same as the process
1139 * priority. 1 means priority of the operation is one less than
1140 * process. And so forth. On Win32, this is a no-op.
1141 * {signal_number} is the POSIX4 real-time signal number to be used
1142 * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
1143 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
1145 int transmit_file (ACE_HANDLE file,
1146 Header_And_Trailer *header_and_trailer = 0,
1147 size_t bytes_to_write = 0,
1148 unsigned long offset = 0,
1149 unsigned long offset_high = 0,
1150 size_t bytes_per_send = 0,
1151 unsigned long flags = 0,
1152 const void *act = 0,
1153 int priority = 0,
1154 int signal_number = ACE_SIGRTMIN);
1156 /// Return the underlying implementation class.
1157 // (this should be protected...)
1158 virtual ACE_Asynch_Operation_Impl *implementation () const;
1160 protected:
1161 /// The implementation class.
1162 ACE_Asynch_Transmit_File_Impl *implementation_;
1164 public:
1166 * @class Result
1168 * @brief This is that class which will be passed back to the
1169 * {handler} when the asynchronous transmit file completes.
1171 * This class has all the information necessary for the
1172 * {handler} to uniquiely identify the completion of the
1173 * asynchronous transmit file.
1175 class ACE_Export Result : public ACE_Asynch_Result
1177 /// The concrete implementation result classes only construct this
1178 /// class.
1179 friend class ACE_POSIX_Asynch_Transmit_File_Result;
1180 friend class ACE_WIN32_Asynch_Transmit_File_Result;
1182 public:
1183 /// Socket used for transmitting the file.
1184 ACE_HANDLE socket () const;
1186 /// File from which the data is read.
1187 ACE_HANDLE file () const;
1189 /// Header and trailer data associated with this transmit file.
1190 Header_And_Trailer *header_and_trailer () const;
1192 /// The number of bytes which were requested at the start of the
1193 /// asynchronous transmit file.
1194 size_t bytes_to_write () const;
1196 /// Number of bytes per send requested at the start of the transmit
1197 /// file.
1198 size_t bytes_per_send () const;
1200 /// Flags which were passed into transmit file.
1201 unsigned long flags () const;
1203 /// Get the implementation class.
1204 ACE_Asynch_Transmit_File_Result_Impl *implementation () const;
1206 protected:
1207 /// Constructor.
1208 Result (ACE_Asynch_Transmit_File_Result_Impl *implementation);
1210 /// Destructor.
1211 virtual ~Result ();
1213 /// The implementation class.
1214 ACE_Asynch_Transmit_File_Result_Impl *implementation_;
1218 * @class Header_And_Trailer
1220 * @brief The class defines a data structure that contains pointers
1221 * to data to send before and after the file data is sent.
1223 * This class provides a wrapper over TRANSMIT_FILE_BUFFERS
1224 * and provided a consistent use of ACE_Message_Blocks.
1226 class ACE_Export Header_And_Trailer
1228 public:
1229 /// Constructor.
1230 Header_And_Trailer (ACE_Message_Block *header = 0,
1231 size_t header_bytes = 0,
1232 ACE_Message_Block *trailer = 0,
1233 size_t trailer_bytes = 0);
1235 /// Destructor
1236 virtual ~Header_And_Trailer ();
1238 /// This method allows all the member to be set in one fell swoop.
1239 void header_and_trailer (ACE_Message_Block *header = 0,
1240 size_t header_bytes = 0,
1241 ACE_Message_Block *trailer = 0,
1242 size_t trailer_bytes = 0);
1244 /// Get header which goes before the file data.
1245 ACE_Message_Block *header () const;
1247 /// Set header which goes before the file data.
1248 void header (ACE_Message_Block *message_block);
1250 /// Get size of the header data.
1251 size_t header_bytes () const;
1253 /// Set size of the header data.
1254 void header_bytes (size_t bytes);
1256 /// Get trailer which goes after the file data.
1257 ACE_Message_Block *trailer () const;
1259 /// Set trailer which goes after the file data.
1260 void trailer (ACE_Message_Block *message_block);
1262 /// Get size of the trailer data.
1263 size_t trailer_bytes () const;
1265 /// Set size of the trailer data.
1266 void trailer_bytes (size_t bytes);
1268 /// Conversion routine.
1269 ACE_LPTRANSMIT_FILE_BUFFERS transmit_buffers ();
1271 protected:
1272 /// Header data.
1273 ACE_Message_Block *header_;
1275 /// Size of header data.
1276 size_t header_bytes_;
1278 /// Trailer data.
1279 ACE_Message_Block *trailer_;
1281 /// Size of trailer data.
1282 size_t trailer_bytes_;
1284 /// Target data structure.
1285 ACE_TRANSMIT_FILE_BUFFERS transmit_buffers_;
1287 private:
1288 void operator= (const ACE_Asynch_Transmit_File &) = delete;
1289 ACE_Asynch_Transmit_File (const ACE_Asynch_Transmit_File &) = delete;
1293 // Forward declarations
1294 class ACE_Asynch_Read_Dgram_Result_Impl;
1295 class ACE_Asynch_Read_Dgram_Impl;
1296 class ACE_Addr;
1299 * @class ACE_Asynch_Read_Dgram
1301 * @brief This class is a factory for starting off asynchronous reads
1302 * on a UDP socket. This class forwards all methods to its
1303 * implementation class.
1305 * Once {open} is called, multiple asynchronous {read}s can be
1306 * started using this class. An ACE_Asynch_Read_Dgram::Result
1307 * will be passed back to the {handler} when the asynchronous
1308 * reads completes through the {ACE_Handler::handle_read_dgram}
1309 * callback.
1311 class ACE_Export ACE_Asynch_Read_Dgram : public ACE_Asynch_Operation
1313 public:
1314 /// A do nothing constructor.
1315 ACE_Asynch_Read_Dgram ();
1317 /// Destructor
1318 virtual ~ACE_Asynch_Read_Dgram ();
1321 * Initializes the factory with information which will be used with
1322 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
1323 * {ACE_Handler::handle} will be called on the {handler} to get the
1324 * correct handle.
1326 int open (ACE_Handler &handler,
1327 ACE_HANDLE handle = ACE_INVALID_HANDLE,
1328 const void *completion_key = 0,
1329 ACE_Proactor *proactor = 0);
1331 /** This starts off an asynchronous read. Upto
1332 * {message_block->total_size()} will be read and stored in the
1333 * {message_block}. {message_block}'s {wr_ptr} will be updated to reflect
1334 * the added bytes if the read operation is successfully completed.
1335 * Return code of 1 means immediate success and {number_of_bytes_recvd}
1336 * will contain number of bytes read. The {ACE_Handler::handle_read_dgram}
1337 * method will still be called. Return code of 0 means the IO will
1338 * complete proactively. Return code of -1 means there was an error, use
1339 * errno to get the error code.
1341 * Scatter/gather is supported on WIN32 by using the {message_block->cont()}
1342 * method. Up to ACE_IOV_MAX {message_block}'s are supported. Upto
1343 * {message_block->size()} bytes will be read into each {message block} for
1344 * a total of {message_block->total_size()} bytes. All {message_block}'s
1345 * {wr_ptr}'s will be updated to reflect the added bytes for each
1346 * {message_block}
1348 * Priority of the operation is specified by {priority}. On POSIX4-Unix,
1349 * this is supported. Works like {nice} in Unix. Negative values are not
1350 * allowed. 0 means priority of the operation same as the process
1351 * priority. 1 means priority of the operation is one less than
1352 * process. And so forth. On Win32, {priority} is a no-op.
1353 * {signal_number} is the POSIX4 real-time signal number to be used
1354 * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
1355 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
1357 ssize_t recv (ACE_Message_Block *message_block,
1358 size_t &number_of_bytes_recvd,
1359 int flags,
1360 int protocol_family = PF_INET,
1361 const void *act = 0,
1362 int priority = 0,
1363 int signal_number = ACE_SIGRTMIN);
1365 /// Return the underlying implementation class.
1366 // (this should be protected...)
1367 virtual ACE_Asynch_Operation_Impl *implementation () const;
1369 protected:
1370 /// Implementation class that all methods will be forwarded to.
1371 ACE_Asynch_Read_Dgram_Impl *implementation_;
1373 public:
1375 * @class Result
1377 * @brief This is the class which will be passed back to the
1378 * {handler} when the asynchronous read completes. This class
1379 * forwards all the methods to the implementation classes.
1381 * This class has all the information necessary for the
1382 * {handler} to uniquiely identify the completion of the
1383 * asynchronous read.
1385 class ACE_Export Result : public ACE_Asynch_Result
1387 /// The concrete implementation result classes only construct this
1388 /// class.
1389 friend class ACE_POSIX_Asynch_Read_Dgram_Result;
1390 friend class ACE_WIN32_Asynch_Read_Dgram_Result;
1392 public:
1393 /// The number of bytes which were requested at the start of the
1394 /// asynchronous read.
1395 size_t bytes_to_read () const;
1397 /// Message block which contains the read data
1398 ACE_Message_Block *message_block () const;
1400 /// The flags used in the read
1401 int flags () const;
1403 /// The address of where the packet came from
1404 int remote_address (ACE_Addr& addr) const;
1406 /// I/O handle used for reading.
1407 ACE_HANDLE handle () const;
1409 /// Get the implementation class.
1410 ACE_Asynch_Read_Dgram_Result_Impl *implementation () const;
1412 protected:
1413 /// Constructor.
1414 Result (ACE_Asynch_Read_Dgram_Result_Impl *implementation);
1416 /// Destructor.
1417 virtual ~Result ();
1419 /// The implementation class.
1420 ACE_Asynch_Read_Dgram_Result_Impl *implementation_;
1422 private:
1423 void operator= (const ACE_Asynch_Read_Dgram &) = delete;
1424 ACE_Asynch_Read_Dgram (const ACE_Asynch_Read_Dgram &) = delete;
1427 // Forward declarations
1428 class ACE_Asynch_Write_Dgram_Impl;
1429 class ACE_Asynch_Write_Dgram_Result_Impl;
1432 * @class ACE_Asynch_Write_Dgram
1434 * @brief This class is a factory for starting off asynchronous writes
1435 * on a UDP socket. This class forwards all methods to its
1436 * implementation class.
1438 * Once {open} is called, multiple asynchronous {writes}s can
1439 * started using this class. An ACE_Asynch_Write_Dgram::Result
1440 * will be passed back to the {handler} when the asynchronous
1441 * write completes through the
1442 * {ACE_Handler::handle_write_dgram} callback.
1444 class ACE_Export ACE_Asynch_Write_Dgram : public ACE_Asynch_Operation
1446 public:
1447 /// A do nothing constructor.
1448 ACE_Asynch_Write_Dgram ();
1450 /// Destructor.
1451 virtual ~ACE_Asynch_Write_Dgram ();
1454 * Initializes the factory with information which will be used with
1455 * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
1456 * {ACE_Handler::handle} will be called on the {handler} to get the
1457 * correct handle.
1459 int open (ACE_Handler &handler,
1460 ACE_HANDLE handle = ACE_INVALID_HANDLE,
1461 const void *completion_key = 0,
1462 ACE_Proactor *proactor = 0);
1464 /** This starts off an asynchronous send. Upto
1465 * {message_block->total_length()} will be sent. {message_block}'s
1466 * {rd_ptr} will be updated to reflect the sent bytes if the send operation
1467 * is successfully completed.
1468 * Return code of 1 means immediate success and {number_of_bytes_sent}
1469 * is updated to number of bytes sent. The {ACE_Handler::handle_write_dgram}
1470 * method will still be called. Return code of 0 means the IO will
1471 * complete proactively. Return code of -1 means there was an error, use
1472 * errno to get the error code.
1474 * Scatter/gather is supported on WIN32 by using the {message_block->cont()}
1475 * method. Up to ACE_IOV_MAX {message_block}'s are supported. Upto
1476 * {message_block->length()} bytes will be sent from each {message block}
1477 * for a total of {message_block->total_length()} bytes. All
1478 * {message_block}'s {rd_ptr}'s will be updated to reflect the bytes sent
1479 * from each {message_block}.
1481 * Priority of the operation is specified by {priority}. On POSIX4-Unix,
1482 * this is supported. Works like {nice} in Unix. Negative values are not
1483 * allowed. 0 means priority of the operation same as the process
1484 * priority. 1 means priority of the operation is one less than
1485 * process. And so forth. On Win32, this argument is a no-op.
1486 * {signal_number} is the POSIX4 real-time signal number to be used
1487 * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
1488 * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
1490 ssize_t send (ACE_Message_Block *message_block,
1491 size_t &number_of_bytes_sent,
1492 int flags,
1493 const ACE_Addr& remote_addr,
1494 const void *act = 0,
1495 int priority = 0,
1496 int signal_number = ACE_SIGRTMIN);
1498 /// Return the underlying implementation class.
1499 // (this should be protected...)
1500 virtual ACE_Asynch_Operation_Impl *implementation () const;
1502 protected:
1503 /// Implementation class that all methods will be forwarded to.
1504 ACE_Asynch_Write_Dgram_Impl *implementation_;
1506 public:
1508 * @class Result
1510 * @brief This is that class which will be passed back to the
1511 * {handler} when the asynchronous write completes. This class
1512 * forwards all the methods to the implementation class.
1514 * This class has all the information necessary for the
1515 * {handler} to uniquiely identify the completion of the
1516 * asynchronous write.
1518 class ACE_Export Result : public ACE_Asynch_Result
1520 /// The concrete implementation result classes only construct this
1521 /// class.
1522 friend class ACE_POSIX_Asynch_Write_Dgram_Result;
1523 friend class ACE_WIN32_Asynch_Write_Dgram_Result;
1525 public:
1526 /// The number of bytes which were requested at the start of the
1527 /// asynchronous write.
1528 size_t bytes_to_write () const;
1530 /// Message block which contains the sent data
1531 ACE_Message_Block *message_block () const;
1533 /// The flags using in the write
1534 int flags () const;
1536 /// I/O handle used for writing.
1537 ACE_HANDLE handle () const;
1539 /// Get the implementation class.
1540 ACE_Asynch_Write_Dgram_Result_Impl *implementation () const;
1542 protected:
1543 /// Constructor.
1544 Result (ACE_Asynch_Write_Dgram_Result_Impl *implementation);
1546 /// Destructor.
1547 virtual ~Result ();
1549 /// Implementation class.
1550 ACE_Asynch_Write_Dgram_Result_Impl *implementation_;
1552 private:
1553 void operator= (const ACE_Asynch_Write_Dgram &) = delete;
1554 ACE_Asynch_Write_Dgram (const ACE_Asynch_Write_Dgram &) = delete;
1558 * @class ACE_Handler
1560 * @brief This base class defines the interface for receiving the
1561 * results of asynchronous operations.
1563 * Subclasses of this class will fill in appropriate methods.
1565 class ACE_Export ACE_Handler
1567 public:
1568 /// A do nothing constructor.
1569 ACE_Handler ();
1571 /// A do nothing constructor which allows proactor to be set to \<p\>.
1572 ACE_Handler (ACE_Proactor *p);
1574 /// Virtual destruction.
1575 virtual ~ACE_Handler ();
1577 /// This method will be called when an asynchronous read completes on
1578 /// a stream.
1579 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
1581 /// This method will be called when an asynchronous write completes
1582 /// on a UDP socket.
1583 virtual void handle_write_dgram (const ACE_Asynch_Write_Dgram::Result &result);
1585 /// This method will be called when an asynchronous read completes on
1586 /// a UDP socket.
1587 virtual void handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result);
1589 /// This method will be called when an asynchronous write completes
1590 /// on a stream.
1591 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
1593 /// This method will be called when an asynchronous read completes on
1594 /// a file.
1595 virtual void handle_read_file (const ACE_Asynch_Read_File::Result &result);
1597 /// This method will be called when an asynchronous write completes
1598 /// on a file.
1599 virtual void handle_write_file (const ACE_Asynch_Write_File::Result &result);
1601 /// This method will be called when an asynchronous accept completes.
1602 virtual void handle_accept (const ACE_Asynch_Accept::Result &result);
1604 /// This method will be called when an asynchronous connect completes.
1605 virtual void handle_connect (const ACE_Asynch_Connect::Result &result);
1607 /// This method will be called when an asynchronous transmit file
1608 /// completes.
1609 virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result);
1611 /// Called when timer expires. {tv} was the requested time value and
1612 /// {act} is the ACT passed when scheduling the timer.
1613 virtual void handle_time_out (const ACE_Time_Value &tv,
1614 const void *act = 0);
1617 * This is method works with the {run_event_loop} of the
1618 * ACE_Proactor. A special {Wake_Up_Completion} is used to wake up
1619 * all the threads that are blocking for completions.
1621 virtual void handle_wakeup ();
1623 /// Get the proactor associated with this handler.
1624 ACE_Proactor *proactor ();
1626 /// Set the proactor.
1627 void proactor (ACE_Proactor *p);
1630 * Get the I/O handle used by this {handler}. This method will be
1631 * called by the ACE_Asynch_* classes when an ACE_INVALID_HANDLE is
1632 * passed to {open}.
1634 virtual ACE_HANDLE handle () const;
1636 /// Set the ACE_HANDLE value for this Handler.
1637 virtual void handle (ACE_HANDLE);
1640 * @class Proxy
1642 * @brief The Proxy class acts as a proxy for dispatch of completions
1643 * to operations issued for the associated handler. It allows the handler
1644 * to be deleted while operations are outstanding. The proxy must be used
1645 * to get the ACE_Handler pointer for dispatching, and if it's 0, the
1646 * handler is no longer valid and the result should not be dispatched.
1648 class ACE_Export Proxy
1650 public:
1651 Proxy (ACE_Handler *handler) : handler_ (handler) {}
1652 void reset () { this->handler_ = 0; }
1653 ACE_Handler *handler () { return this->handler_; }
1654 private:
1655 ACE_Handler *handler_;
1657 typedef ACE_Refcounted_Auto_Ptr<Proxy, ACE_SYNCH_MUTEX> Proxy_Ptr;
1659 Proxy_Ptr &proxy ();
1661 protected:
1662 /// The proactor associated with this handler.
1663 ACE_Proactor *proactor_;
1665 /// The ACE_HANDLE in use with this handler.
1666 ACE_HANDLE handle_;
1668 /// Refers to proxy for this handler.
1669 ACE_Refcounted_Auto_Ptr<Proxy, ACE_SYNCH_MUTEX> proxy_;
1671 private:
1672 ACE_Handler (const ACE_Handler &) = delete;
1673 ACE_Handler operator= (const ACE_Handler &) = delete;
1676 // Forward declarations
1677 class ACE_INET_Addr;
1679 // Forward declarations
1680 template <class HANDLER>
1681 class ACE_Asynch_Acceptor;
1684 * @class ACE_Service_Handler
1686 * @brief This base class defines the interface for the
1687 * ACE_Asynch_Acceptor to call into when new connection are
1688 * accepted.
1690 * Subclasses of this class will fill in appropriate methods to
1691 * define application specific behavior.
1693 class ACE_Export ACE_Service_Handler : public ACE_Handler
1695 /// The Acceptor is the factory and therefore should have special
1696 /// privileges.
1697 friend class ACE_Asynch_Acceptor<ACE_Service_Handler>;
1699 public:
1700 /// A do nothing constructor.
1701 ACE_Service_Handler ();
1703 /// Virtual destruction.
1704 virtual ~ACE_Service_Handler ();
1707 * {open} is called by ACE_Asynch_Acceptor to initialize a new
1708 * instance of ACE_Service_Handler that has been created after the
1709 * new connection is accepted. The handle for the new connection is
1710 * passed along with the initial data that may have shown up.
1712 virtual void open (ACE_HANDLE new_handle,
1713 ACE_Message_Block &message_block);
1715 // protected:
1716 // This should be corrected after the correct semantics of the
1717 // friend has been figured out.
1719 /// Called by ACE_Asynch_Acceptor to pass the addresses of the new
1720 /// connections.
1721 virtual void addresses (const ACE_INET_Addr &remote_address,
1722 const ACE_INET_Addr &local_address);
1724 /// Called by ACE_Asynch_Acceptor to pass the act.
1725 virtual void act (const void *);
1728 ACE_END_VERSIONED_NAMESPACE_DECL
1730 #endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS*/
1731 #include /**/ "ace/post.h"
1732 #endif /* ACE_ASYNCH_IO_H */