Asynch_IO.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Asynch_IO.h
00006  *
00007  *  Asynch_IO.h,v 4.76 2006/02/10 09:21:43 jwillemsen Exp
00008  *
00009  *  This works on Win32 (#if defined (ACE_WIN32) && !defined
00010  *  (ACE_HAS_WINCE)) platforms and on POSIX4 platforms with {aio_*}
00011  *  routines (#if defined (ACE_HAS_AIO_CALLS))
00012  *
00013  *  On Win32 platforms, the implementation of
00014  *  {ACE_Asynch_Transmit_File} and {ACE_Asynch_Accept} are only
00015  *  supported if ACE_HAS_WINSOCK2 is defined or you are on WinNT 4.0
00016  *  or higher.
00017  *
00018  *  @author Irfan Pyarali <irfan@cs.wustl.edu>
00019  *  @author Tim Harrison <harrison@cs.wustl.edu>
00020  *  @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
00021  *  @author Roger Tragin <r.tragin@computer.org>
00022  *  @author Alexander Libman <alibman@ihug.com.au>
00023  */
00024 //=============================================================================
00025 
00026 #ifndef ACE_ASYNCH_IO_H
00027 #define ACE_ASYNCH_IO_H
00028 #include /**/ "ace/pre.h"
00029 
00030 #include "ace/ACE_export.h"
00031 
00032 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00033 #pragma once
00034 #endif /* ACE_LACKS_PRAGMA_ONCE */
00035 
00036 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS))
00037 
00038 #include "ace/Synch_Traits.h"
00039 #if defined (ACE_HAS_THREADS)
00040 #  include "ace/Thread_Mutex.h"
00041 #else
00042 #  include "ace/Null_Mutex.h"
00043 #endif /* ACE_HAS_THREADS */
00044 #include "ace/Refcounted_Auto_Ptr.h"
00045 
00046 #include "ace/os_include/os_signal.h"
00047 #include "ace/os_include/sys/os_socket.h"
00048 #include "ace/os_include/sys/os_types.h"
00049 
00050 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00051 
00052 # if defined (ACE_WIN32) && ! defined (ACE_HAS_WINCE) \
00053                          && ! defined (ACE_HAS_PHARLAP)
00054 typedef TRANSMIT_FILE_BUFFERS ACE_TRANSMIT_FILE_BUFFERS;
00055 typedef LPTRANSMIT_FILE_BUFFERS ACE_LPTRANSMIT_FILE_BUFFERS;
00056 typedef PTRANSMIT_FILE_BUFFERS ACE_PTRANSMIT_FILE_BUFFERS;
00057 
00058 #   define ACE_INFINITE INFINITE
00059 #   define ACE_STATUS_TIMEOUT STATUS_TIMEOUT
00060 #   define ACE_WAIT_FAILED WAIT_FAILED
00061 #   define ACE_WAIT_TIMEOUT WAIT_TIMEOUT
00062 # else /* ACE_WIN32 */
00063 struct ACE_TRANSMIT_FILE_BUFFERS
00064 {
00065   void *Head;
00066   size_t HeadLength;
00067   void *Tail;
00068   size_t TailLength;
00069 };
00070 typedef ACE_TRANSMIT_FILE_BUFFERS* ACE_PTRANSMIT_FILE_BUFFERS;
00071 typedef ACE_TRANSMIT_FILE_BUFFERS* ACE_LPTRANSMIT_FILE_BUFFERS;
00072 
00073 #   if !defined (ACE_INFINITE)
00074 #     define ACE_INFINITE LONG_MAX
00075 #   endif /* ACE_INFINITE */
00076 #   define ACE_STATUS_TIMEOUT LONG_MAX
00077 #   define ACE_WAIT_FAILED LONG_MAX
00078 #   define ACE_WAIT_TIMEOUT LONG_MAX
00079 # endif /* ACE_WIN32 */
00080 
00081 // Forward declarations
00082 class ACE_Proactor;
00083 class ACE_Handler;
00084 class ACE_Message_Block;
00085 class ACE_INET_Addr;
00086 class ACE_Addr;
00087 
00088 // Forward declarations
00089 class ACE_Asynch_Result_Impl;
00090 class ACE_Time_Value;
00091 
00092 /**
00093  * @class ACE_Asynch_Result
00094  *
00095  * @brief An interface base class which allows users access to common
00096  * information related to an asynchronous operation.
00097  *
00098  * An interface base class from which you can obtain some basic
00099  * information like the number of bytes transferred, the ACT
00100  * associated with the asynchronous operation, indication of
00101  * success or failure, etc. Subclasses may want to store more
00102  * information that is particular to the asynchronous operation
00103  * it represents.
00104  */
00105 class ACE_Export ACE_Asynch_Result
00106 {
00107 
00108 public:
00109   /// Number of bytes transferred by the operation.
00110   size_t bytes_transferred (void) const;
00111 
00112   /// ACT associated with the operation.
00113   const void *act (void) const;
00114 
00115   /// Did the operation succeed?
00116   int success (void) const;
00117 
00118   /**
00119    * This is the ACT associated with the handle on which the
00120    * Asynch_Operation takes place.
00121    *
00122    * On WIN32, this returns the ACT associated with the handle when it
00123    * was registered with the I/O completion port.
00124    *
00125    * @@ This is not implemented for POSIX4 platforms. Returns 0.
00126    */
00127   const void *completion_key (void) const;
00128 
00129   /// Error value if the operation fails.
00130   unsigned long error (void) const;
00131 
00132   /**
00133    * On WIN32, this returns the event associated with the OVERLAPPED
00134    * structure.
00135    *
00136    * This returns ACE_INVALID_HANDLE on POSIX4-Unix platforms.
00137    */
00138   ACE_HANDLE event (void) const;
00139 
00140   /**
00141    * This really makes sense only when doing file I/O.
00142    *
00143    * On WIN32, these are represented in the OVERLAPPED datastructure.
00144    *
00145    * @@ On POSIX4-Unix, offset_high should be supported using
00146    *    aiocb64.
00147    */
00148   unsigned long offset (void) const;
00149   unsigned long offset_high (void) const;
00150 
00151   /**
00152    * Priority of the operation.
00153    *
00154    * On POSIX4-Unix, this is supported. Priority works like {nice} in
00155    * Unix. Negative values are not allowed. 0 means priority of the
00156    * operation same as the process priority. 1 means priority of the
00157    * operation is one less than process. And so forth.
00158    *
00159    * On Win32, this is a no-op.
00160    */
00161   int priority (void) const;
00162 
00163   /**
00164    * POSIX4 real-time signal number to be used for the
00165    * operation. {signal_number} ranges from ACE_SIGRTMIN to ACE_SIGRTMAX. By
00166    * default, ACE_SIGRTMIN is used to issue {aio_} calls. This is a no-op
00167    * on non-POSIX4 systems and returns 0.
00168    */
00169   int signal_number (void) const;
00170 
00171 
00172   /// Destructor.
00173   virtual ~ACE_Asynch_Result (void);
00174 
00175 protected:
00176   /// Constructor. This implementation will not be deleted.  The
00177   /// implementation will be deleted by the Proactor.
00178   ACE_Asynch_Result (ACE_Asynch_Result_Impl *implementation);
00179 
00180   /// Get the implementation class.
00181   ACE_Asynch_Result_Impl *implementation (void) const;
00182 
00183   /// Implementation class.
00184   ACE_Asynch_Result_Impl *implementation_;
00185 };
00186 
00187 // Forward declarations
00188 class ACE_Asynch_Operation_Impl;
00189 
00190 /**
00191  * @class ACE_Asynch_Operation
00192  *
00193  * @brief This is an interface base class for all asynch
00194  * operations. The resposiblility of this class is to forward
00195  * all methods to its delegation/implementation class, e.g.,
00196  * ACE_WIN32_Asynch_Operation or ACE_POSIX_Asynch_Operation.
00197  *
00198  * There are some attributes and functionality which is common
00199  * to all asychronous operations. The delegation classes of this
00200  * class will factor out this code.
00201  */
00202 class ACE_Export ACE_Asynch_Operation
00203 {
00204 
00205 public:
00206   /**
00207    * Initializes the factory with information which will be used with
00208    * each asynchronous call.  If ({handle} == ACE_INVALID_HANDLE),
00209    * {ACE_Handler::handle} will be called on the {handler} to get the
00210    * correct handle.
00211    */
00212   int open (ACE_Handler &handler,
00213             ACE_HANDLE handle,
00214             const void *completion_key,
00215             ACE_Proactor *proactor);
00216 
00217   /**
00218    * (Attempts to) cancel the asynchronous operation pending against
00219    * the {handle} registered with this Operation.
00220    *
00221    * All completion notifications for the I/O operations will occur
00222    * normally.
00223    *
00224    * = Return Values:
00225    *
00226    * -1 : Operation failed. (can get only in POSIX).
00227    *  0 : All the operations were cancelled.
00228    *  1 : All the operations were already finished in this
00229    *      handle. Unable to cancel them.
00230    *  2 : Atleast one of the requested operations cannot be
00231    *      cancelled.
00232    *
00233    * There is slight difference in the semantics between NT and POSIX
00234    * platforms which is given below.
00235    *
00236    * = Win32 :
00237    *
00238    *   cancels all pending accepts operations that were issued by the
00239    *   calling thread.  The function does not cancel asynchronous
00240    *   operations issued by other threads.
00241    *   All I/O operations that are canceled will complete with the
00242    *   error ERROR_OPERATION_ABORTED.
00243    *
00244    * = POSIX:
00245    *
00246    *   Attempts to cancel one or more asynchronous I/O requests
00247    *   currently outstanding against the {handle} registered in this
00248    *   operation.
00249    *   For requested operations that are successfully canceled, the
00250    *   associated  error  status is set to ECANCELED.
00251    */
00252   int cancel (void);
00253 
00254 
00255   // = Access methods.
00256 
00257   /// Return the underlying proactor.
00258   ACE_Proactor* proactor (void) const;
00259 
00260   /// Destructor.
00261   virtual ~ACE_Asynch_Operation (void);
00262 
00263 protected:
00264   /// Constructor.
00265   ACE_Asynch_Operation (void);
00266 
00267   /// Return the underlying implementation class.
00268   virtual ACE_Asynch_Operation_Impl *implementation (void) const = 0;
00269 
00270   /// Get a proactor for/from the user
00271   ACE_Proactor *get_proactor (ACE_Proactor *user_proactor,
00272                               ACE_Handler &handler) const;
00273 };
00274 
00275 // Forward declarations
00276 class ACE_Asynch_Read_Stream_Result_Impl;
00277 class ACE_Asynch_Read_Stream_Impl;
00278 
00279 /**
00280  * @class ACE_Asynch_Read_Stream
00281  *
00282  * @brief This class is a factory for starting off asynchronous reads
00283  * on a stream. This class forwards all methods to its
00284  * implementation class.
00285  *
00286  * Once {open} is called, multiple asynchronous {read}s can
00287  * started using this class.  An ACE_Asynch_Read_Stream::Result
00288  * will be passed back to the {handler} when the asynchronous
00289  * reads completes through the {ACE_Handler::handle_read_stream}
00290  * callback.
00291  */
00292 class ACE_Export ACE_Asynch_Read_Stream : public ACE_Asynch_Operation
00293 {
00294 
00295 public:
00296   /// A do nothing constructor.
00297   ACE_Asynch_Read_Stream (void);
00298 
00299   /// Destructor
00300   virtual ~ACE_Asynch_Read_Stream (void);
00301 
00302   /**
00303    * Initializes the factory with information which will be used with
00304    * each asynchronous call.
00305    *
00306    * @arg handler The ACE_Handler that will be called to handle completions
00307    *              for operations initiated using this factory.
00308    * @arg handle  The handle that future read operations will use.
00309    *              If handle == @c ACE_INVALID_HANDLE,
00310    *              ACE_Handler::handle() will be called on @ handler
00311    *              to get the correct handle.
00312    *
00313    * @retval 0    for success.
00314    * @retval -1   for failure; consult @c errno for further information.
00315    */
00316   int open (ACE_Handler &handler,
00317             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00318             const void *completion_key = 0,
00319             ACE_Proactor *proactor = 0);
00320 
00321   /**
00322    * This starts off an asynchronous read.  Upto {bytes_to_read} will
00323    * be read and stored in the {message_block}. {message_block}'s
00324    * {wr_ptr} will be updated to reflect the added bytes if the read
00325    * operation is successful completed. Priority of the
00326    * operation is specified by {priority}. On POSIX4-Unix, this is
00327    * supported. Works like {nice} in Unix. Negative values are not
00328    * allowed. 0 means priority of the operation same as the process
00329    * priority. 1 means priority of the operation is one less than
00330    * process. And so forth. On Win32, {priority} is a no-op.
00331    * {signal_number} is the POSIX4 real-time signal number to be used
00332    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
00333    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
00334    */
00335   int read (ACE_Message_Block &message_block,
00336             size_t num_bytes_to_read,
00337             const void *act = 0,
00338             int priority = 0,
00339             int signal_number = ACE_SIGRTMIN);
00340 
00341 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))
00342   /**
00343   * Same as above but with scatter support, through chaining of composite
00344   * message blocks using the continuation field.
00345   */
00346   int readv (ACE_Message_Block &message_block,
00347              size_t num_bytes_to_read,
00348              const void *act = 0,
00349              int priority = 0,
00350              int signal_number = ACE_SIGRTMIN);
00351 #endif /* (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) */
00352 
00353   /// Return the underlying implementation class.
00354   //  (this should be protected...)
00355   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00356 
00357 protected:
00358   /// Implementation class that all methods will be forwarded to.
00359   ACE_Asynch_Read_Stream_Impl *implementation_;
00360 
00361 public:
00362 /**
00363  * @class Result
00364  *
00365  * @brief This is the class which will be passed back to the
00366  * {handler} when the asynchronous read completes. This class
00367  * forwards all the methods to the implementation classes.
00368  *
00369  * This class has all the information necessary for the
00370  * {handler} to uniquiely identify the completion of the
00371  * asynchronous read.
00372  */
00373   class ACE_Export Result : public ACE_Asynch_Result
00374   {
00375 
00376     /// The concrete implementation result classes only construct this
00377     /// class.
00378     friend class ACE_POSIX_Asynch_Read_Stream_Result;
00379     friend class ACE_WIN32_Asynch_Read_Stream_Result;
00380 
00381   public:
00382     /// The number of bytes which were requested at the start of the
00383     /// asynchronous read.
00384     size_t bytes_to_read (void) const;
00385 
00386     /// Message block which contains the read data.
00387     ACE_Message_Block &message_block (void) const;
00388 
00389     /// I/O handle used for reading.
00390     ACE_HANDLE handle (void) const;
00391 
00392     /// Get the implementation class.
00393     ACE_Asynch_Read_Stream_Result_Impl *implementation (void) const;
00394 
00395   protected:
00396     /// Constructor.
00397     Result (ACE_Asynch_Read_Stream_Result_Impl *implementation);
00398 
00399     /// Destructor.
00400     virtual ~Result (void);
00401 
00402     /// The implementation class.
00403     ACE_Asynch_Read_Stream_Result_Impl *implementation_;
00404   };
00405 };
00406 
00407 // Forward declarations
00408 class ACE_Asynch_Write_Stream_Impl;
00409 class ACE_Asynch_Write_Stream_Result_Impl;
00410 
00411 /**
00412  * @class ACE_Asynch_Write_Stream
00413  *
00414  * @brief This class is a factory for starting off asynchronous writes
00415  * on a stream. This class forwards all methods to its
00416  * implementation class.
00417  *
00418  * Once {open} is called, multiple asynchronous {writes}s can
00419  * started using this class.  An ACE_Asynch_Write_Stream::Result
00420  * will be passed back to the {handler} when the asynchronous
00421  * write completes through the
00422  * {ACE_Handler::handle_write_stream} callback.
00423  */
00424 class ACE_Export ACE_Asynch_Write_Stream : public ACE_Asynch_Operation
00425 {
00426 
00427 public:
00428   /// A do nothing constructor.
00429   ACE_Asynch_Write_Stream (void);
00430 
00431   /// Destructor.
00432   virtual ~ACE_Asynch_Write_Stream (void);
00433 
00434   /**
00435    * Initializes the factory with information which will be used with
00436    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
00437    * {ACE_Handler::handle} will be called on the {handler} to get the
00438    * correct handle.
00439    */
00440   int open (ACE_Handler &handler,
00441             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00442             const void *completion_key = 0,
00443             ACE_Proactor *proactor = 0);
00444 
00445   /**
00446    * This starts off an asynchronous write.  Upto {bytes_to_write}
00447    * will be written from the {message_block}. Upon successful completion
00448    * of the write operation, {message_block}'s {rd_ptr} is updated to
00449    * reflect the data that was written. Priority of the
00450    * operation is specified by {priority}. On POSIX4-Unix, this is
00451    * supported. Works like {nice} in Unix. Negative values are not
00452    * allowed. 0 means priority of the operation same as the process
00453    * priority. 1 means priority of the operation is one less than
00454    * process. And so forth. On Win32, this argument is a no-op.
00455    * {signal_number} is the POSIX4 real-time signal number to be used
00456    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
00457    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
00458    */
00459   int write (ACE_Message_Block &message_block,
00460              size_t bytes_to_write,
00461              const void *act = 0,
00462              int priority = 0,
00463              int signal_number = ACE_SIGRTMIN);
00464 
00465 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))
00466   /**
00467   * Same as above but with gather support, through chaining of composite
00468   * message blocks using the continuation field.
00469   */
00470   int writev (ACE_Message_Block &message_block,
00471               size_t bytes_to_write,
00472               const void *act = 0,
00473               int priority = 0,
00474               int signal_number = ACE_SIGRTMIN);
00475 #endif /* (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) */
00476 
00477   /// Return the underlying implementation class.
00478   /// @todo (this should be protected...)
00479   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00480 
00481 protected:
00482   /// Implementation class that all methods will be forwarded to.
00483   ACE_Asynch_Write_Stream_Impl *implementation_;
00484 
00485 public:
00486 /**
00487  * @class Result
00488  *
00489  * @brief This is that class which will be passed back to the
00490  * {handler} when the asynchronous write completes. This class
00491  * forwards all the methods to the implementation class.
00492  *
00493  * This class has all the information necessary for the
00494  * {handler} to uniquiely identify the completion of the
00495  * asynchronous write.
00496  */
00497   class ACE_Export Result : public ACE_Asynch_Result
00498   {
00499 
00500     /// The concrete implementation result classes only construct this
00501     /// class.
00502     friend class ACE_POSIX_Asynch_Write_Stream_Result;
00503     friend class ACE_WIN32_Asynch_Write_Stream_Result;
00504 
00505   public:
00506     /// The number of bytes which were requested at the start of the
00507     /// asynchronous write.
00508     size_t bytes_to_write (void) const;
00509 
00510     /// Message block that contains the data to be written.
00511     ACE_Message_Block &message_block (void) const;
00512 
00513     /// I/O handle used for writing.
00514     ACE_HANDLE handle (void) const;
00515 
00516     /// Get the implementation class.
00517     ACE_Asynch_Write_Stream_Result_Impl *implementation (void) const;
00518 
00519   protected:
00520     /// Constructor.
00521     Result (ACE_Asynch_Write_Stream_Result_Impl *implementation);
00522 
00523     /// Destructor.
00524     virtual ~Result (void);
00525 
00526     /// Implementation class.
00527     ACE_Asynch_Write_Stream_Result_Impl *implementation_;
00528   };
00529 };
00530 
00531 // Forward declarations
00532 class ACE_Asynch_Read_File_Impl;
00533 class ACE_Asynch_Read_File_Result_Impl;
00534 
00535 /**
00536  * @class ACE_Asynch_Read_File
00537  *
00538  * @brief This class is a factory for starting off asynchronous reads
00539  * on a file. This class forwards all methods to its
00540  * implementation class.
00541  *
00542  * Once {open} is called, multiple asynchronous {read}s can
00543  * started using this class. An ACE_Asynch_Read_File::Result
00544  * will be passed back to the {handler} when the asynchronous
00545  * reads completes through the {ACE_Handler::handle_read_file}
00546  * callback.
00547  * This class differs slightly from ACE_Asynch_Read_Stream as it
00548  * allows the user to specify an offset for the read.
00549  */
00550 class ACE_Export ACE_Asynch_Read_File : public ACE_Asynch_Read_Stream
00551 {
00552 
00553 public:
00554   /// A do nothing constructor.
00555   ACE_Asynch_Read_File (void);
00556 
00557   /// Destructor.
00558   virtual ~ACE_Asynch_Read_File (void);
00559 
00560   /**
00561    * Initializes the factory with information which will be used with
00562    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
00563    * {ACE_Handler::handle} will be called on the {handler} to get the
00564    * correct handle.
00565    */
00566   int open (ACE_Handler &handler,
00567             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00568             const void *completion_key = 0,
00569             ACE_Proactor *proactor = 0);
00570 
00571   /**
00572    * This starts off an asynchronous read.  Upto {bytes_to_read} will
00573    * be read and stored in the {message_block}.  The read will start
00574    * at {offset} from the beginning of the file. Priority of the
00575    * operation is specified by {priority}. On POSIX4-Unix, this is
00576    * supported. Works like {nice} in Unix. Negative values are not
00577    * allowed. 0 means priority of the operation same as the process
00578    * priority. 1 means priority of the operation is one less than
00579    * process. And so forth. On Win32, this argument is a no-op.
00580    * {signal_number} is the POSIX4 real-time signal number to be used
00581    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
00582    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
00583    */
00584   int read (ACE_Message_Block &message_block,
00585             size_t bytes_to_read,
00586             unsigned long offset = 0,
00587             unsigned long offset_high = 0,
00588             const void *act = 0,
00589             int priority = 0,
00590             int signal_number = ACE_SIGRTMIN);
00591 
00592 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE))
00593   /**
00594   * Same as above but with scatter support, through chaining of composite
00595   * message blocks using the continuation field.
00596   * @note In win32 Each data block payload must be at least the size of a system
00597   * memory page and must be aligned on a system memory page size boundary
00598   */
00599   int readv (ACE_Message_Block &message_block,
00600              size_t bytes_to_read,
00601              unsigned long offset = 0,
00602              unsigned long offset_high = 0,
00603              const void *act = 0,
00604              int priority = 0,
00605              int signal_number = ACE_SIGRTMIN);
00606 #endif /* (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) */
00607 
00608   /// Return the underlying implementation class.
00609   //  (this should be protected...)
00610   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00611 
00612 protected:
00613   /// Delegation/implementation class that all methods will be
00614   /// forwarded to.
00615   ACE_Asynch_Read_File_Impl *implementation_;
00616 
00617 public:
00618 /**
00619  * @class Result
00620  *
00621  * @brief This is that class which will be passed back to the
00622  * {handler} when the asynchronous read completes. This class
00623  * forwards all the methods to the implementation class.
00624  *
00625  * This class has all the information necessary for the
00626  * {handler} to uniquiely identify the completion of the
00627  * asynchronous read.
00628  * This class differs slightly from
00629  * ACE_Asynch_Read_Stream::Result as it calls back
00630  * {ACE_Handler::handle_read_file} on the {handler} instead of
00631  * {ACE_Handler::handle_read_stream}.  No additional state is
00632  * required by this class as ACE_Asynch_Result can store the
00633  * {offset}.
00634  */
00635   class ACE_Export Result : public ACE_Asynch_Read_Stream::Result
00636   {
00637 
00638     /// The concrete implementation result classes only construct this
00639     /// class.
00640     friend class ACE_POSIX_Asynch_Read_File_Result;
00641     friend class ACE_WIN32_Asynch_Read_File_Result;
00642 
00643   public:
00644     /// Get the implementation class.
00645     ACE_Asynch_Read_File_Result_Impl *implementation (void) const;
00646 
00647   protected:
00648     /// Constructor. This implementation will not be deleted.
00649     Result (ACE_Asynch_Read_File_Result_Impl *implementation);
00650 
00651     /// Destructor.
00652     virtual ~Result (void);
00653 
00654     /// The implementation class.
00655     ACE_Asynch_Read_File_Result_Impl *implementation_;
00656 
00657   private:
00658     /// Here just to provide an dummpy implementation, since the
00659     /// one auto generated by MSVC is flagged as infinitely recursive
00660     void operator= (Result &) {}
00661   };
00662 };
00663 
00664 // Forward declarations
00665 class ACE_Asynch_Write_File_Impl;
00666 class ACE_Asynch_Write_File_Result_Impl;
00667 
00668 /**
00669  * @class ACE_Asynch_Write_File
00670  *
00671  * @brief This class is a factory for starting off asynchronous writes
00672  * on a file. This class forwards all methods to its
00673  * implementation class.
00674  *
00675  * Once {open} is called, multiple asynchronous {write}s can be
00676  * started using this class.  A ACE_Asynch_Write_File::Result
00677  * will be passed back to the {handler} when the asynchronous
00678  * writes completes through the {ACE_Handler::handle_write_file}
00679  * callback.
00680  * This class differs slightly from ACE_Asynch_Write_Stream as
00681  * it allows the user to specify an offset for the write.
00682  */
00683 class ACE_Export ACE_Asynch_Write_File : public ACE_Asynch_Write_Stream
00684 {
00685 
00686 public:
00687   /// A do nothing constructor.
00688   ACE_Asynch_Write_File (void);
00689 
00690   /// Destructor.
00691   virtual ~ACE_Asynch_Write_File (void);
00692 
00693   /**
00694    * Initializes the factory with information which will be used with
00695    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
00696    * {ACE_Handler::handle} will be called on the {handler} to get the
00697    * correct handle.
00698    */
00699   int open (ACE_Handler &handler,
00700             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00701             const void *completion_key = 0,
00702             ACE_Proactor *proactor = 0);
00703 
00704   /**
00705    * This starts off an asynchronous write.  Upto {bytes_to_write}
00706    * will be written from the {message_block}, starting at the
00707    * block's {rd_ptr}.  The write will go to the file, starting
00708    * {offset} bytes from the beginning of the file. Priority of the
00709    * operation is specified by {priority}. On POSIX4-Unix, this is
00710    * supported. Works like {nice} in Unix. Negative values are not
00711    * allowed. 0 means priority of the operation same as the process
00712    * priority. 1 means priority of the operation is one less than
00713    * process. And so forth. On Win32, this is a no-op.
00714    * {signal_number} is the POSIX4 real-time signal number to be used
00715    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
00716    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
00717    */
00718   int write (ACE_Message_Block &message_block,
00719              size_t bytes_to_write,
00720              unsigned long offset = 0,
00721              unsigned long offset_high = 0,
00722              const void *act = 0,
00723              int priority = 0,
00724              int signal_number = ACE_SIGRTMIN);
00725 
00726 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE))
00727   /**
00728   * Same as above but with gather support, through chaining of composite
00729   * message blocks using the continuation field.
00730   * @note In win32 Each data block payload must be at least the size of a system
00731   * memory page and must be aligned on a system memory page size boundary
00732   */
00733   int writev (ACE_Message_Block &message_block,
00734               size_t bytes_to_write,
00735               unsigned long offset = 0,
00736               unsigned long offset_high = 0,
00737               const void *act = 0,
00738               int priority = 0,
00739               int signal_number = ACE_SIGRTMIN);
00740 #endif /* (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) */
00741 
00742   /// Return the underlying implementation class.
00743   //  (this should be protected...)
00744   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00745 
00746 protected:
00747   /// Implementation object.
00748   ACE_Asynch_Write_File_Impl *implementation_;
00749 
00750 public:
00751 /**
00752  * @class Result
00753  *
00754  * @brief This is that class which will be passed back to the
00755  * {handler} when the asynchronous write completes. This class
00756  * forwards all the methods to the implementation class.
00757  *
00758  * This class has all the information necessary for the
00759  * {handler} to uniquiely identify the completion of the
00760  * asynchronous write.
00761  * This class differs slightly from
00762  * ACE_Asynch_Write_Stream::Result as it calls back
00763  * {ACE_Handler::handle_write_file} on the {handler} instead
00764  * of {ACE_Handler::handle_write_stream}.  No additional state
00765  * is required by this class as ACE_Asynch_Result can store
00766  * the {offset}.
00767  */
00768   class ACE_Export Result : public ACE_Asynch_Write_Stream::Result
00769   {
00770 
00771     /// The concrete implementation result classes only construct this
00772     /// class.
00773     friend class ACE_POSIX_Asynch_Write_File_Result;
00774     friend class ACE_WIN32_Asynch_Write_File_Result;
00775 
00776   public:
00777     ///  Get the implementation class.
00778     ACE_Asynch_Write_File_Result_Impl *implementation (void) const;
00779 
00780   protected:
00781     /// Constructor. This implementation will not be deleted.
00782     Result (ACE_Asynch_Write_File_Result_Impl *implementation);
00783 
00784     /// Destructor.
00785     virtual ~Result (void);
00786 
00787     /// The implementation class.
00788     ACE_Asynch_Write_File_Result_Impl *implementation_;
00789 
00790   private:
00791     /// Here just to provide an dummpy implementation, since the
00792     /// one auto generated by MSVC is flagged as infinitely recursive
00793     void operator= (Result &) {};
00794   };
00795 };
00796 
00797 // Forward declarations
00798 class ACE_Asynch_Accept_Result_Impl;
00799 class ACE_Asynch_Accept_Impl;
00800 
00801 /**
00802  * @class ACE_Asynch_Accept
00803  *
00804  * @brief This class is a factory for starting off asynchronous accepts
00805  * on a listen handle. This class forwards all methods to its
00806  * implementation class.
00807  *
00808  * Once {open} is called, multiple asynchronous {accept}s can
00809  * started using this class.  A ACE_Asynch_Accept::Result will
00810  * be passed back to the {handler} when the asynchronous accept
00811  * completes through the {ACE_Handler::handle_accept}
00812  * callback.
00813  */
00814 class ACE_Export ACE_Asynch_Accept : public ACE_Asynch_Operation
00815 {
00816 
00817 public:
00818   /// A do nothing constructor.
00819   ACE_Asynch_Accept (void);
00820 
00821   /// Destructor.
00822   virtual ~ACE_Asynch_Accept (void);
00823 
00824   /**
00825    * Initializes the factory with information which will be used with
00826    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
00827    * {ACE_Handler::handle} will be called on the {handler} to get the
00828    * correct handle.
00829    */
00830   int open (ACE_Handler &handler,
00831             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00832             const void *completion_key = 0,
00833             ACE_Proactor *proactor = 0);
00834 
00835   /**
00836    * This starts off an asynchronous accept.  The asynchronous accept
00837    * call also allows any initial data to be returned to the
00838    * handler specified to @c open().
00839    *   @param message_block   A message block to receive initial data, as well
00840    *                          as the local and remote addresses when the
00841    *                          connection is made. Since the block receives
00842    *                          the addresses regardless of whether or not
00843    *                          initial data is available or requested, the
00844    *                          message block size must be at least
00845    *                          @a bytes_to_read plus two times the size of
00846    *                          the addresses used (IPv4 or IPv6).
00847    *   @param bytes_to_read   The maximum number of bytes of initial data
00848    *                          to read into @a message_block.
00849    *   @param accept_handle   The handle that the new connection will be
00850    *                          accepted on. If @c INVALID_HANDLE, a new
00851    *                          handle will be created using @a addr_family.
00852    *   @param act             Value to be passed in result when operation
00853    *                          completes.
00854    *   @param priority        Priority of the operation. On POSIX4-Unix, this
00855    *                          is supported. Works like @c nice in Unix.
00856    *                          Negative values are not allowed. 0 means
00857    *                          priority of the operation same as the process
00858    *                          priority. 1 means priority of the operation is
00859    *                          one less than process. And so forth.
00860    *                          On Win32, this argument is ignored.
00861    *   @param signal_number   The POSIX4 real-time signal number to be used
00862    *                          for the operation. Value range is from
00863    *                          @c ACE_SIGRTMIN to @c ACE_SIGRTMAX.
00864    *                          This argument is ignored on non-POSIX4 systems.
00865    *   @param addr_family     The address family to use if @a accept_handle
00866    *                          is @c ACE_INVALID_HANDLE and a new handle must
00867    *                          be opened. Values are @c AF_INET and @c PF_INET6.
00868    */
00869   int accept (ACE_Message_Block &message_block,
00870               size_t bytes_to_read,
00871               ACE_HANDLE accept_handle = ACE_INVALID_HANDLE,
00872               const void *act = 0,
00873               int priority = 0,
00874               int signal_number = ACE_SIGRTMIN,
00875               int addr_family = AF_INET);
00876 
00877   /// Return the underlying implementation class.
00878   //  (this should be protected...)
00879   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00880 
00881 protected:
00882   /// Delegation/implementation class that all methods will be
00883   /// forwarded to.
00884   ACE_Asynch_Accept_Impl *implementation_;
00885 
00886 public:
00887 /**
00888  * @class Result
00889  *
00890  * @brief This is that class which will be passed back to the
00891  * {handler} when the asynchronous accept completes.
00892  *
00893  * This class has all the information necessary for the
00894  * {handler} to uniquiely identify the completion of the
00895  * asynchronous accept.
00896  */
00897   class ACE_Export Result : public ACE_Asynch_Result
00898   {
00899 
00900     /// The concrete implementation result classes only construct this
00901     /// class.
00902     friend class ACE_POSIX_Asynch_Accept_Result;
00903     friend class ACE_WIN32_Asynch_Accept_Result;
00904 
00905   public:
00906     /// The number of bytes which were requested at the start of the
00907     /// asynchronous accept.
00908     size_t bytes_to_read (void) const;
00909 
00910     /// Message block which contains the read data.
00911     ACE_Message_Block &message_block (void) const;
00912 
00913     /// I/O handle used for accepting new connections.
00914     ACE_HANDLE listen_handle (void) const;
00915 
00916     /// I/O handle for the new connection.
00917     ACE_HANDLE accept_handle (void) const;
00918 
00919     /// Get the implementation.
00920     ACE_Asynch_Accept_Result_Impl *implementation (void) const;
00921 
00922   protected:
00923     /// Contructor. Implementation will not be deleted.
00924     Result (ACE_Asynch_Accept_Result_Impl *implementation);
00925 
00926     /// Destructor.
00927     virtual ~Result (void);
00928 
00929     /// Impelmentation class.
00930     ACE_Asynch_Accept_Result_Impl *implementation_;
00931   };
00932 };
00933 // Forward declarations
00934 class ACE_Asynch_Connect_Result_Impl;
00935 class ACE_Asynch_Connect_Impl;
00936 
00937 /**
00938  * @class ACE_Asynch_Connect
00939  *
00940  * @brief This class is a factory for starting off asynchronous connects
00941  * This class forwards all methods to its implementation class.
00942  *
00943  * Once @c open is called, multiple asynchronous connect operationss can
00944  * started using this class.  A ACE_Asynch_Connect::Result will
00945  * be passed back to the associated ACE_Handler when the asynchronous connect
00946  * completes through the ACE_Handler::handle_connect() callback.
00947  */
00948 class ACE_Export ACE_Asynch_Connect : public ACE_Asynch_Operation
00949 {
00950 
00951 public:
00952   /// A do nothing constructor.
00953   ACE_Asynch_Connect (void);
00954 
00955   /// Destructor.
00956   virtual ~ACE_Asynch_Connect (void);
00957 
00958   /**
00959    * Initializes the factory with information which will be used with
00960    * each asynchronous call.
00961    *
00962    * @note @arg handle is ignored and should be @c ACE_INVALID_HANDLE.
00963    */
00964   int open (ACE_Handler &handler,
00965             ACE_HANDLE handle = ACE_INVALID_HANDLE,
00966             const void *completion_key = 0,
00967             ACE_Proactor *proactor = 0);
00968 
00969   /**
00970    * This starts off an asynchronous Connect.
00971    */
00972   int connect (ACE_HANDLE connect_handle,
00973                const ACE_Addr & remote_sap,
00974                const ACE_Addr & local_sap,
00975                int  reuse_addr,
00976                const void *act=0,
00977                int priority = 0,
00978                int signal_number = ACE_SIGRTMIN);
00979 
00980   /// Return the underlying implementation class.
00981   //  (this should be protected...)
00982   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
00983 
00984 protected:
00985   /// Delegation/implementation class that all methods will be
00986   /// forwarded to.
00987   ACE_Asynch_Connect_Impl *implementation_;
00988 
00989 public:
00990 /**
00991  * @class Result
00992  *
00993  * @brief This is that class which will be passed back to the
00994  * handler when the asynchronous connect completes.
00995  *
00996  * This class has all the information necessary for the
00997  * handler to uniquely identify the completion of the
00998  * asynchronous connect.
00999  */
01000   class ACE_Export Result : public ACE_Asynch_Result
01001   {
01002 
01003     /// The concrete implementation result classes only construct this
01004     /// class.
01005     friend class ACE_POSIX_Asynch_Connect_Result;
01006     friend class ACE_WIN32_Asynch_Connect_Result;
01007 
01008   public:
01009 
01010     /// I/O handle for the  connection.
01011     ACE_HANDLE connect_handle (void) const;
01012 
01013     /// Get the implementation.
01014     ACE_Asynch_Connect_Result_Impl *implementation (void) const;
01015 
01016   protected:
01017     /// Contructor. Implementation will not be deleted.
01018     Result (ACE_Asynch_Connect_Result_Impl *implementation);
01019 
01020     /// Destructor.
01021     virtual ~Result (void);
01022 
01023     /// Impelmentation class.
01024     ACE_Asynch_Connect_Result_Impl *implementation_;
01025   };
01026 };
01027 
01028 // Forward declarations
01029 class ACE_Asynch_Transmit_File_Result_Impl;
01030 class ACE_Asynch_Transmit_File_Impl;
01031 
01032 /**
01033  * @class ACE_Asynch_Transmit_File
01034  *
01035  * @brief This class is a factory for starting off asynchronous
01036  * transmit files on a stream.
01037  *
01038  * Once {open} is called, multiple asynchronous {transmit_file}s
01039  * can started using this class.  A
01040  * ACE_Asynch_Transmit_File::Result will be passed back to the
01041  * {handler} when the asynchronous transmit file completes
01042  * through the {ACE_Handler::handle_transmit_file} callback.
01043  * The transmit_file function transmits file data over a
01044  * connected network connection. The function uses the operating
01045  * system's cache manager to retrieve the file data. This
01046  * function provides high-performance file data transfer over
01047  * network connections.  This function would be of great use in
01048  * a Web Server, Image Server, etc.
01049  */
01050 class ACE_Export ACE_Asynch_Transmit_File : public ACE_Asynch_Operation
01051 {
01052 
01053 public:
01054   // Forward declarations
01055   class Header_And_Trailer;
01056 
01057   /// A do nothing constructor.
01058   ACE_Asynch_Transmit_File (void);
01059 
01060   /// Destructor.
01061   virtual ~ACE_Asynch_Transmit_File (void);
01062 
01063   /**
01064    * Initializes the factory with information which will be used with
01065    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
01066    * {ACE_Handler::handle} will be called on the {handler} to get the
01067    * correct handle.
01068    */
01069   int open (ACE_Handler &handler,
01070             ACE_HANDLE handle = ACE_INVALID_HANDLE,
01071             const void *completion_key = 0,
01072             ACE_Proactor *proactor = 0);
01073 
01074   /**
01075    * This starts off an asynchronous transmit file.  The {file} is a
01076    * handle to an open file.  {header_and_trailer} is a pointer to a
01077    * data structure that contains pointers to data to send before and
01078    * after the file data is sent.  Set this parameter to 0 if you only
01079    * want to transmit the file data.  Upto {bytes_to_write} will be
01080    * written to the {socket}.  If you want to send the entire file,
01081    * let {bytes_to_write} = 0.  {bytes_per_send} is the size of each
01082    * block of data sent per send operation.  Please read the Win32
01083    * documentation on what the flags should be. Priority of the
01084    * operation is specified by {priority}. On POSIX4-Unix, this is
01085    * supported. Works like {nice} in Unix. Negative values are not
01086    * allowed. 0 means priority of the operation same as the process
01087    * priority. 1 means priority of the operation is one less than
01088    * process. And so forth. On Win32, this is a no-op.
01089    * {signal_number} is the POSIX4 real-time signal number to be used
01090    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
01091    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
01092    */
01093   int transmit_file (ACE_HANDLE file,
01094                      Header_And_Trailer *header_and_trailer = 0,
01095                      size_t bytes_to_write = 0,
01096                      unsigned long offset = 0,
01097                      unsigned long offset_high = 0,
01098                      size_t bytes_per_send = 0,
01099                      unsigned long flags = 0,
01100                      const void *act = 0,
01101                      int priority = 0,
01102                      int signal_number = ACE_SIGRTMIN);
01103 
01104   /// Return the underlying implementation class.
01105   //  (this should be protected...)
01106   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
01107 
01108 protected:
01109   /// The implementation class.
01110   ACE_Asynch_Transmit_File_Impl *implementation_;
01111 
01112 public:
01113 /**
01114  * @class Result
01115  *
01116  * @brief This is that class which will be passed back to the
01117  * {handler} when the asynchronous transmit file completes.
01118  *
01119  * This class has all the information necessary for the
01120  * {handler} to uniquiely identify the completion of the
01121  * asynchronous transmit file.
01122  */
01123   class ACE_Export Result : public ACE_Asynch_Result
01124   {
01125 
01126     /// The concrete implementation result classes only construct this
01127     /// class.
01128     friend class ACE_POSIX_Asynch_Transmit_File_Result;
01129     friend class ACE_WIN32_Asynch_Transmit_File_Result;
01130 
01131   public:
01132     /// Socket used for transmitting the file.
01133     ACE_HANDLE socket (void) const;
01134 
01135     /// File from which the data is read.
01136     ACE_HANDLE file (void) const;
01137 
01138     /// Header and trailer data associated with this transmit file.
01139     Header_And_Trailer *header_and_trailer (void) const;
01140 
01141     /// The number of bytes which were requested at the start of the
01142     /// asynchronous transmit file.
01143     size_t bytes_to_write (void) const;
01144 
01145     /// Number of bytes per send requested at the start of the transmit
01146     /// file.
01147     size_t bytes_per_send (void) const;
01148 
01149     /// Flags which were passed into transmit file.
01150     unsigned long flags (void) const;
01151 
01152     /// Get the implementation class.
01153     ACE_Asynch_Transmit_File_Result_Impl *implementation (void) const;
01154 
01155   protected:
01156     /// Constructor.
01157     Result (ACE_Asynch_Transmit_File_Result_Impl *implementation);
01158 
01159     /// Destructor.
01160     virtual ~Result (void);
01161 
01162     /// The implementation class.
01163     ACE_Asynch_Transmit_File_Result_Impl *implementation_;
01164   };
01165 
01166 /**
01167  * @class Header_And_Trailer
01168  *
01169  * @brief The class defines a data structure that contains pointers
01170  * to data to send before and after the file data is sent.
01171  *
01172  * This class provides a wrapper over TRANSMIT_FILE_BUFFERS
01173  * and provided a consistent use of ACE_Message_Blocks.
01174  */
01175   class ACE_Export Header_And_Trailer
01176   {
01177 
01178   public:
01179     /// Constructor.
01180     Header_And_Trailer (ACE_Message_Block *header = 0,
01181                         size_t header_bytes = 0,
01182                         ACE_Message_Block *trailer = 0,
01183                         size_t trailer_bytes = 0);
01184 
01185     /// Destructor
01186     virtual ~Header_And_Trailer (void);
01187 
01188     /// This method allows all the member to be set in one fell swoop.
01189     void header_and_trailer (ACE_Message_Block *header = 0,
01190                              size_t header_bytes = 0,
01191                              ACE_Message_Block *trailer = 0,
01192                              size_t trailer_bytes = 0);
01193 
01194     /// Get header which goes before the file data.
01195     ACE_Message_Block *header (void) const;
01196 
01197     /// Set header which goes before the file data.
01198     void header (ACE_Message_Block *message_block);
01199 
01200     /// Get size of the header data.
01201     size_t header_bytes (void) const;
01202 
01203     /// Set size of the header data.
01204     void header_bytes (size_t bytes);
01205 
01206     /// Get trailer which goes after the file data.
01207     ACE_Message_Block *trailer (void) const;
01208 
01209     /// Set trailer which goes after the file data.
01210     void trailer (ACE_Message_Block *message_block);
01211 
01212     /// Get size of the trailer data.
01213     size_t trailer_bytes (void) const;
01214 
01215     /// Set size of the trailer data.
01216     void trailer_bytes (size_t bytes);
01217 
01218     /// Conversion routine.
01219     ACE_LPTRANSMIT_FILE_BUFFERS transmit_buffers (void);
01220 
01221   protected:
01222     /// Header data.
01223     ACE_Message_Block *header_;
01224 
01225     /// Size of header data.
01226     size_t header_bytes_;
01227 
01228     /// Trailer data.
01229     ACE_Message_Block *trailer_;
01230 
01231     /// Size of trailer data.
01232     size_t trailer_bytes_;
01233 
01234     /// Target data structure.
01235     ACE_TRANSMIT_FILE_BUFFERS transmit_buffers_;
01236   };
01237 };
01238 
01239 
01240 // Forward declarations
01241 class ACE_Asynch_Read_Dgram_Result_Impl;
01242 class ACE_Asynch_Read_Dgram_Impl;
01243 class ACE_Addr;
01244 
01245 /**
01246  * @class ACE_Asynch_Read_Dgram
01247  *
01248  * @brief This class is a factory for starting off asynchronous reads
01249  * on a UDP socket. This class forwards all methods to its
01250  * implementation class.
01251  *
01252  * Once {open} is called, multiple asynchronous {read}s can be
01253  * started using this class.  An ACE_Asynch_Read_Dgram::Result
01254  * will be passed back to the {handler} when the asynchronous
01255  * reads completes through the {ACE_Handler::handle_read_dgram}
01256  * callback.
01257  */
01258 class ACE_Export ACE_Asynch_Read_Dgram : public ACE_Asynch_Operation
01259 {
01260 
01261 public:
01262   /// A do nothing constructor.
01263   ACE_Asynch_Read_Dgram (void);
01264 
01265   /// Destructor
01266   virtual ~ACE_Asynch_Read_Dgram (void);
01267 
01268   /**
01269    * Initializes the factory with information which will be used with
01270    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
01271    * {ACE_Handler::handle} will be called on the {handler} to get the
01272    * correct handle.
01273    */
01274   int open (ACE_Handler &handler,
01275             ACE_HANDLE handle = ACE_INVALID_HANDLE,
01276             const void *completion_key = 0,
01277             ACE_Proactor *proactor = 0);
01278 
01279   /** This starts off an asynchronous read.  Upto
01280    * {message_block->total_size()} will be read and stored in the
01281    * {message_block}.  {message_block}'s {wr_ptr} will be updated to reflect
01282    * the added bytes if the read operation is successfully completed.
01283    * Return code of 1 means immediate success and {number_of_bytes_recvd}
01284    * will contain number of bytes read.  The {ACE_Handler::handle_read_dgram}
01285    * method will still be called.  Return code of 0 means the IO will
01286    * complete proactively.  Return code of -1 means there was an error, use
01287    * errno to get the error code.
01288    *
01289    * Scatter/gather is supported on WIN32 by using the {message_block->cont()}
01290    * method.  Up to ACE_IOV_MAX {message_block}'s are supported.  Upto
01291    * {message_block->size()} bytes will be read into each {message block} for
01292    * a total of {message_block->total_size()} bytes.  All {message_block}'s
01293    * {wr_ptr}'s will be updated to reflect the added bytes for each
01294    * {message_block}
01295    *
01296    * Priority of the operation is specified by {priority}. On POSIX4-Unix,
01297    * this is supported. Works like {nice} in Unix. Negative values are not
01298    * allowed. 0 means priority of the operation same as the process
01299    * priority. 1 means priority of the operation is one less than
01300    * process. And so forth. On Win32, {priority} is a no-op.
01301    * {signal_number} is the POSIX4 real-time signal number to be used
01302    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
01303    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
01304    */
01305   ssize_t recv (ACE_Message_Block *message_block,
01306                 size_t &number_of_bytes_recvd,
01307                 int flags,
01308                 int protocol_family = PF_INET,
01309                 const void *act = 0,
01310                 int priority = 0,
01311                 int signal_number = ACE_SIGRTMIN);
01312 
01313   /// Return the underlying implementation class.
01314   //  (this should be protected...)
01315   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
01316 
01317 protected:
01318   /// Implementation class that all methods will be forwarded to.
01319   ACE_Asynch_Read_Dgram_Impl *implementation_;
01320 
01321 public:
01322 /**
01323  * @class Result
01324  *
01325  * @brief This is the class which will be passed back to the
01326  * {handler} when the asynchronous read completes. This class
01327  * forwards all the methods to the implementation classes.
01328  *
01329  * This class has all the information necessary for the
01330  * {handler} to uniquiely identify the completion of the
01331  * asynchronous read.
01332  */
01333   class ACE_Export Result : public ACE_Asynch_Result
01334   {
01335 
01336     /// The concrete implementation result classes only construct this
01337     /// class.
01338     friend class ACE_POSIX_Asynch_Read_Dgram_Result;
01339     friend class ACE_WIN32_Asynch_Read_Dgram_Result;
01340 
01341   public:
01342 
01343     /// The number of bytes which were requested at the start of the
01344     /// asynchronous read.
01345     size_t bytes_to_read (void) const;
01346 
01347     /// Message block which contains the read data
01348     ACE_Message_Block *message_block (void) const;
01349 
01350     /// The flags used in the read
01351     int flags (void) const;
01352 
01353     /// The address of where the packet came from
01354     int remote_address (ACE_Addr& addr) const;
01355 
01356     /// I/O handle used for reading.
01357     ACE_HANDLE handle (void) const;
01358 
01359     /// Get the implementation class.
01360     ACE_Asynch_Read_Dgram_Result_Impl *implementation (void) const;
01361 
01362   protected:
01363     /// Constructor.
01364     Result (ACE_Asynch_Read_Dgram_Result_Impl *implementation);
01365 
01366     /// Destructor.
01367     virtual ~Result (void);
01368 
01369     /// The implementation class.
01370     ACE_Asynch_Read_Dgram_Result_Impl *implementation_;
01371   };
01372 };
01373 
01374 // Forward declarations
01375 class ACE_Asynch_Write_Dgram_Impl;
01376 class ACE_Asynch_Write_Dgram_Result_Impl;
01377 
01378 /**
01379  * @class ACE_Asynch_Write_Dgram
01380  *
01381  * @brief This class is a factory for starting off asynchronous writes
01382  * on a UDP socket. This class forwards all methods to its
01383  * implementation class.
01384  *
01385  * Once {open} is called, multiple asynchronous {writes}s can
01386  * started using this class.  An ACE_Asynch_Write_Dgram::Result
01387  * will be passed back to the {handler} when the asynchronous
01388  * write completes through the
01389  * {ACE_Handler::handle_write_dgram} callback.
01390  */
01391 class ACE_Export ACE_Asynch_Write_Dgram : public ACE_Asynch_Operation
01392 {
01393 
01394 public:
01395   /// A do nothing constructor.
01396   ACE_Asynch_Write_Dgram (void);
01397 
01398   /// Destructor.
01399   virtual ~ACE_Asynch_Write_Dgram (void);
01400 
01401   /**
01402    * Initializes the factory with information which will be used with
01403    * each asynchronous call. If ({handle} == ACE_INVALID_HANDLE),
01404    * {ACE_Handler::handle} will be called on the {handler} to get the
01405    * correct handle.
01406    */
01407   int open (ACE_Handler &handler,
01408             ACE_HANDLE handle = ACE_INVALID_HANDLE,
01409             const void *completion_key = 0,
01410             ACE_Proactor *proactor = 0);
01411 
01412   /** This starts off an asynchronous send.  Upto
01413    * {message_block->total_length()} will be sent.  {message_block}'s
01414    * {rd_ptr} will be updated to reflect the sent bytes if the send operation
01415    * is successfully completed.
01416    * Return code of 1 means immediate success and {number_of_bytes_sent}
01417    * is updated to number of bytes sent.  The {ACE_Handler::handle_write_dgram}
01418    * method will still be called.  Return code of 0 means the IO will
01419    * complete proactively.  Return code of -1 means there was an error, use
01420    * errno to get the error code.
01421    *
01422    * Scatter/gather is supported on WIN32 by using the {message_block->cont()}
01423    * method.  Up to ACE_IOV_MAX {message_block}'s are supported.  Upto
01424    * {message_block->length()} bytes will be sent from each {message block}
01425    * for a total of {message_block->total_length()} bytes.  All
01426    * {message_block}'s {rd_ptr}'s will be updated to reflect the bytes sent
01427    * from each {message_block}.
01428    *
01429    * Priority of the operation is specified by {priority}. On POSIX4-Unix,
01430    * this is supported. Works like {nice} in Unix. Negative values are not
01431    * allowed. 0 means priority of the operation same as the process
01432    * priority. 1 means priority of the operation is one less than
01433    * process. And so forth. On Win32, this argument is a no-op.
01434    * {signal_number} is the POSIX4 real-time signal number to be used
01435    * for the operation. {signal_number} ranges from ACE_SIGRTMIN to
01436    * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
01437    */
01438   ssize_t send (ACE_Message_Block *message_block,
01439                 size_t &number_of_bytes_sent,
01440                 int flags,
01441                 const ACE_Addr& remote_addr,
01442                 const void *act = 0,
01443                 int priority = 0,
01444                 int signal_number = ACE_SIGRTMIN);
01445 
01446   /// Return the underlying implementation class.
01447   //  (this should be protected...)
01448   virtual ACE_Asynch_Operation_Impl *implementation (void) const;
01449 
01450 protected:
01451   /// Implementation class that all methods will be forwarded to.
01452   ACE_Asynch_Write_Dgram_Impl *implementation_;
01453 
01454 public:
01455 /**
01456  * @class Result
01457  *
01458  * @brief This is that class which will be passed back to the
01459  * {handler} when the asynchronous write completes. This class
01460  * forwards all the methods to the implementation class.
01461  *
01462  * This class has all the information necessary for the
01463  * {handler} to uniquiely identify the completion of the
01464  * asynchronous write.
01465  */
01466   class ACE_Export Result : public ACE_Asynch_Result
01467   {
01468 
01469     /// The concrete implementation result classes only construct this
01470     /// class.
01471     friend class ACE_POSIX_Asynch_Write_Dgram_Result;
01472     friend class ACE_WIN32_Asynch_Write_Dgram_Result;
01473 
01474   public:
01475 
01476     /// The number of bytes which were requested at the start of the
01477     /// asynchronous write.
01478     size_t bytes_to_write (void) const;
01479 
01480     /// Message block which contains the sent data
01481     ACE_Message_Block *message_block (void) const;
01482 
01483     /// The flags using in the write
01484     int flags (void) const;
01485 
01486     /// I/O handle used for writing.
01487     ACE_HANDLE handle (void) const;
01488 
01489     /// Get the implementation class.
01490     ACE_Asynch_Write_Dgram_Result_Impl *implementation (void) const;
01491 
01492   protected:
01493     /// Constructor.
01494     Result (ACE_Asynch_Write_Dgram_Result_Impl *implementation);
01495 
01496     /// Destructor.
01497     virtual ~Result (void);
01498 
01499     /// Implementation class.
01500     ACE_Asynch_Write_Dgram_Result_Impl *implementation_;
01501   };
01502 };
01503 
01504 
01505 /**
01506  * @class ACE_Handler
01507  *
01508  * @brief This base class defines the interface for receiving the
01509  * results of asynchronous operations.
01510  *
01511  * Subclasses of this class will fill in appropriate methods.
01512  */
01513 class ACE_Export ACE_Handler
01514 {
01515 public:
01516   /// A do nothing constructor.
01517   ACE_Handler (void);
01518 
01519   /// A do nothing constructor which allows proactor to be set to <p>.
01520   ACE_Handler (ACE_Proactor *p);
01521 
01522   /// Virtual destruction.
01523   virtual ~ACE_Handler (void);
01524 
01525   /// This method will be called when an asynchronous read completes on
01526   /// a stream.
01527   virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
01528 
01529   /// This method will be called when an asynchronous write completes
01530   /// on a UDP socket.
01531   virtual void handle_write_dgram (const ACE_Asynch_Write_Dgram::Result &result);
01532 
01533   /// This method will be called when an asynchronous read completes on
01534   /// a UDP socket.
01535   virtual void handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result);
01536 
01537   /// This method will be called when an asynchronous write completes
01538   /// on a stream.
01539   virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
01540 
01541   /// This method will be called when an asynchronous read completes on
01542   /// a file.
01543   virtual void handle_read_file (const ACE_Asynch_Read_File::Result &result);
01544 
01545   /// This method will be called when an asynchronous write completes
01546   /// on a file.
01547   virtual void handle_write_file (const ACE_Asynch_Write_File::Result &result);
01548 
01549   /// This method will be called when an asynchronous accept completes.
01550   virtual void handle_accept (const ACE_Asynch_Accept::Result &result);
01551 
01552   /// This method will be called when an asynchronous connect completes.
01553   virtual void handle_connect (const ACE_Asynch_Connect::Result &result);
01554 
01555   /// This method will be called when an asynchronous transmit file
01556   /// completes.
01557   virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result);
01558 
01559   /// Called when timer expires.  {tv} was the requested time value and
01560   /// {act} is the ACT passed when scheduling the timer.
01561   virtual void handle_time_out (const ACE_Time_Value &tv,
01562                                 const void *act = 0);
01563 
01564   /**
01565    * This is method works with the {run_event_loop} of the
01566    * ACE_Proactor. A special {Wake_Up_Completion} is used to wake up
01567    * all the threads that are blocking for completions.
01568    */
01569   virtual void handle_wakeup (void);
01570 
01571   /// Get the proactor associated with this handler.
01572   ACE_Proactor *proactor (void);
01573 
01574   /// Set the proactor.
01575   void proactor (ACE_Proactor *p);
01576 
01577   /**
01578    * Get the I/O handle used by this {handler}. This method will be
01579    * called by the ACE_Asynch_* classes when an ACE_INVALID_HANDLE is
01580    * passed to {open}.
01581    */
01582   virtual ACE_HANDLE handle (void) const;
01583 
01584   /// Set the ACE_HANDLE value for this Handler.
01585   virtual void handle (ACE_HANDLE);
01586 
01587   /**
01588    * @class Proxy
01589    *
01590    * @brief The Proxy class acts as a proxy for dispatch of completions
01591    * to operations issued for the associated handler. It allows the handler
01592    * to be deleted while operations are outstanding. The proxy must be used
01593    * to get the ACE_Handler pointer for dispatching, and if it's 0, the
01594    * handler is no longer valid and the result should not be dispatched.
01595    */
01596   class ACE_Export Proxy
01597   {
01598   public:
01599     Proxy (ACE_Handler *handler) : handler_ (handler) {};
01600     void reset (void) { this->handler_ = 0; };
01601     ACE_Handler *handler (void) { return this->handler_; };
01602   private:
01603     ACE_Handler *handler_;
01604   };
01605   typedef ACE_Refcounted_Auto_Ptr<Proxy, ACE_SYNCH_MUTEX>
01606     Proxy_Ptr;
01607 
01608   Proxy_Ptr &proxy (void);
01609 
01610 protected:
01611   /// The proactor associated with this handler.
01612   ACE_Proactor *proactor_;
01613 
01614   /// The ACE_HANDLE in use with this handler.
01615   ACE_HANDLE    handle_;
01616 
01617   /// Refers to proxy for this handler.
01618   ACE_Refcounted_Auto_Ptr<Proxy, ACE_SYNCH_MUTEX> proxy_;
01619 };
01620 
01621 // Forward declarations
01622 class ACE_INET_Addr;
01623 
01624 // Forward declarations
01625 template <class HANDLER>
01626 class ACE_Asynch_Acceptor;
01627 
01628 /**
01629  * @class ACE_Service_Handler
01630  *
01631  * @brief This base class defines the interface for the
01632  * ACE_Asynch_Acceptor to call into when new connection are
01633  * accepted.
01634  *
01635  * Subclasses of this class will fill in appropriate methods to
01636  * define application specific behavior.
01637  */
01638 class ACE_Export ACE_Service_Handler : public ACE_Handler
01639 {
01640 
01641   /// The Acceptor is the factory and therefore should have special
01642   /// privileges.
01643   friend class ACE_Asynch_Acceptor<ACE_Service_Handler>;
01644 
01645 public:
01646   /// A do nothing constructor.
01647   ACE_Service_Handler (void);
01648 
01649   /// Virtual destruction.
01650   virtual ~ACE_Service_Handler (void);
01651 
01652   /**
01653    * {open} is called by ACE_Asynch_Acceptor to initialize a new
01654    * instance of ACE_Service_Handler that has been created after the
01655    * new connection is accepted. The handle for the new connection is
01656    * passed along with the initial data that may have shown up.
01657    */
01658   virtual void open (ACE_HANDLE new_handle,
01659                      ACE_Message_Block &message_block);
01660 
01661   // protected:
01662   // This should be corrected after the correct semantics of the
01663   // friend has been figured out.
01664 
01665   /// Called by ACE_Asynch_Acceptor to pass the addresses of the new
01666   /// connections.
01667   virtual void addresses (const ACE_INET_Addr &remote_address,
01668                           const ACE_INET_Addr &local_address);
01669 
01670   /// Called by ACE_Asynch_Acceptor to pass the act.
01671   virtual void act (const void *);
01672 };
01673 
01674 ACE_END_VERSIONED_NAMESPACE_DECL
01675 
01676 #endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS*/
01677 #include /**/ "ace/post.h"
01678 #endif /* ACE_ASYNCH_IO_H */

Generated on Thu Nov 9 09:41:46 2006 for ACE by doxygen 1.3.6