WIN32_Asynch_IO.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    WIN32_Asynch_IO.h
00006  *
00007  *  $Id: WIN32_Asynch_IO.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *
00010  *  These classes only works on Win32 platforms.
00011  *
00012  *  The implementation of ACE_Asynch_Transmit_File,
00013  *  ACE_Asynch_Accept, and ACE_Asynch_Connect are only supported if
00014  *  ACE_HAS_WINSOCK2 is defined or you are on WinNT 4.0 or higher.
00015  *
00016  *
00017  *  @author Irfan Pyarali <irfan@cs.wustl.edu>
00018  *  @author Tim Harrison <harrison@cs.wustl.edu>
00019  *  @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
00020  *  @author Roger Tragin <r.tragin@computer.org>
00021  *  @author Alexander Libman <alibman@ihug.com.au>
00022  */
00023 //=============================================================================
00024 
00025 #ifndef ACE_WIN32_ASYNCH_IO_H
00026 #define ACE_WIN32_ASYNCH_IO_H
00027 #include /**/ "ace/pre.h"
00028 
00029 #include /**/ "ace/config-all.h"
00030 
00031 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00032 #pragma once
00033 #endif /* ACE_LACKS_PRAGMA_ONCE */
00034 
00035 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) && \
00036     (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 == 1))
00037 
00038 #include "ace/Asynch_IO_Impl.h"
00039 #include "ace/Addr.h"
00040 #include "ace/Event_Handler.h"
00041 #include "ace/Handle_Set.h"
00042 #include "ace/Map_Manager.h"
00043 #include "ace/Null_Mutex.h"
00044 
00045 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00046 
00047 // Forward declaration
00048 class ACE_WIN32_Proactor;
00049 
00050 /**
00051  * @class ACE_WIN32_Asynch_Result
00052  *
00053  * @brief An abstract class which adds information to the OVERLAPPED
00054  *     structure to make it more useful.
00055  *
00056  *     An abstract base class from which you can obtain some basic
00057  *     information like the number of bytes transferred, the ACT
00058  *     associated with the asynchronous operation, indication of
00059  *     success or failure, etc.  Subclasses may want to store more
00060  *     information that is particular to the asynchronous operation
00061  *     it represents.
00062  */
00063 class ACE_Export ACE_WIN32_Asynch_Result : public virtual ACE_Asynch_Result_Impl,
00064                                            public OVERLAPPED
00065 {
00066   /// Factory class has special permissions.
00067   friend class ACE_WIN32_Asynch_Accept;
00068 
00069   /// Proactor class has special permission.
00070   friend class ACE_WIN32_Proactor;
00071 
00072 public:
00073   /// Number of bytes transferred by the operation.
00074   size_t bytes_transferred (void) const;
00075 
00076   /// ACT associated with the operation.
00077   const void *act (void) const;
00078 
00079   /// Did the operation succeed?
00080   int success (void) const;
00081 
00082   /**
00083    * This returns the ACT associated with the handle when it was
00084    * registered with the I/O completion port.  This ACT is not the
00085    * same as the ACT associated with the asynchronous operation.
00086    */
00087   const void *completion_key (void) const;
00088 
00089   /// Error value if the operation fail.
00090   u_long error (void) const;
00091 
00092   /// Event associated with the OVERLAPPED structure.
00093   ACE_HANDLE event (void) const;
00094 
00095   /// This really make sense only when doing file I/O.
00096   u_long offset (void) const;
00097 
00098   /// Offset_high associated with the OVERLAPPED structure.
00099   u_long offset_high (void) const;
00100 
00101   /// The priority of the asynchronous operation. Currently, this is
00102   /// not supported on Win32.
00103   int priority (void) const;
00104 
00105   /// Returns 0.
00106   int signal_number (void) const;
00107 
00108   /// Post @c this to the Proactor's completion port.
00109   int post_completion (ACE_Proactor_Impl *proactor);
00110 
00111   /// Destructor.
00112   virtual ~ACE_WIN32_Asynch_Result (void);
00113 
00114   /// Simulate error value to use in the post_completion ()
00115   void set_error (u_long errcode);
00116 
00117   /// Simulate value to use in the post_completion ()
00118   void set_bytes_transferred (size_t nbytes);
00119 
00120 protected:
00121   /// Constructor.
00122   ACE_WIN32_Asynch_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00123                            const void* act,
00124                            ACE_HANDLE event,
00125                            u_long offset,
00126                            u_long offset_high,
00127                            int priority,
00128                            int signal_number = 0);
00129 
00130   /// Proxy for the ACE_Handler that will be called back.
00131   ACE_Handler::Proxy_Ptr handler_proxy_;
00132 
00133   /// ACT for this operation.
00134   const void *act_;
00135 
00136   /// Bytes transferred by this operation.
00137   size_t bytes_transferred_;
00138 
00139   /// Success indicator.
00140   int success_;
00141 
00142   /// ACT associated with handle.
00143   const void *completion_key_;
00144 
00145   /// Error if operation failed.
00146   u_long error_;
00147 };
00148 
00149 /**
00150  * @class ACE_WIN32_Asynch_Operation
00151  *
00152  * @brief This class abstracts out the common things needed for
00153  * implementing Asynch_Operation for WIN32 platform.
00154  *
00155  */
00156 class ACE_Export ACE_WIN32_Asynch_Operation : public virtual ACE_Asynch_Operation_Impl
00157 {
00158 public:
00159   /**
00160    * Initializes the factory with information which will be used with
00161    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
00162    * <ACE_Handler::handle> will be called on the @a handler to get the
00163    * correct handle.
00164    */
00165   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
00166             ACE_HANDLE handle,
00167             const void *completion_key,
00168             ACE_Proactor *proactor);
00169 
00170   /**
00171    * This cancels all pending accepts operations that were issued by
00172    * the calling thread.  The function does not cancel asynchronous
00173    * operations issued by other threads.
00174    */
00175   int cancel (void);
00176 
00177   // = Access methods.
00178 
00179   /// Return the underlying proactor.
00180   ACE_Proactor* proactor (void) const;
00181 
00182 protected:
00183   /// Constructor.
00184   ACE_WIN32_Asynch_Operation (ACE_WIN32_Proactor *win32_proactor);
00185 
00186   /// Destructor.
00187   virtual ~ACE_WIN32_Asynch_Operation (void);
00188 
00189   /// Win32 Proactor.
00190   ACE_WIN32_Proactor *win32_proactor_;
00191 
00192   /// Proactor that this asynch IO is registered with.
00193   ACE_Proactor *proactor_;
00194 
00195   /// Handler that will receive the callback.
00196   ACE_Handler::Proxy_Ptr handler_proxy_;
00197 
00198   /// I/O handle used for reading.
00199   ACE_HANDLE handle_;
00200 };
00201 
00202 /**
00203  * @class ACE_WIN32_Asynch_Read_Stream_Result
00204  *
00205  * @brief This class provides concrete implementation for
00206  * ACE_Asynch_Read_Stream::Result class.
00207  */
00208 class ACE_Export ACE_WIN32_Asynch_Read_Stream_Result : public virtual ACE_Asynch_Read_Stream_Result_Impl,
00209                                                        public ACE_WIN32_Asynch_Result
00210 {
00211   /// Factory class will have special permissions.
00212   friend class ACE_WIN32_Asynch_Read_Stream;
00213 
00214   /// Proactor class has special permission.
00215   friend class ACE_WIN32_Proactor;
00216 
00217 public:
00218   /// The number of bytes which were requested at the start of the
00219   /// asynchronous read.
00220   size_t bytes_to_read (void) const;
00221 
00222   /// Message block which contains the read data.
00223   ACE_Message_Block &message_block (void) const;
00224 
00225   /// I/O handle used for reading.
00226   ACE_HANDLE handle (void) const;
00227 
00228   // Base class operations. These operations are here to kill
00229   // dominance warnings. These methods call the base class methods.
00230 
00231   /// Number of bytes transferred by the operation.
00232   size_t bytes_transferred (void) const;
00233 
00234   /// ACT associated with the operation.
00235   const void *act (void) const;
00236 
00237   /// Did the operation succeed?
00238   int success (void) const;
00239 
00240   /**
00241    * This returns the ACT associated with the handle when it was
00242    * registered with the I/O completion port.  This ACT is not the
00243    * same as the ACT associated with the asynchronous operation.
00244    */
00245   const void *completion_key (void) const;
00246 
00247   /// Error value if the operation fail.
00248   u_long error (void) const;
00249 
00250   /// Event associated with the OVERLAPPED structure.
00251   ACE_HANDLE event (void) const;
00252 
00253   /// This really make sense only when doing file I/O.
00254   u_long offset (void) const;
00255 
00256   /// Offset_high associated with the OVERLAPPED structure.
00257   u_long offset_high (void) const;
00258 
00259   /// The priority of the asynchronous operation. Currently, this is
00260   /// not supported on Win32.
00261   int priority (void) const;
00262 
00263   /// No-op. Returns 0.
00264   int signal_number (void) const;
00265 
00266   /// Post @c this to the Proactor's completion port.
00267   int post_completion (ACE_Proactor_Impl *proactor);
00268 
00269   /// Accessor for the scatter read flag
00270   int scatter_enabled (void) const;
00271 
00272 protected:
00273   /// Constructor is protected since creation is limited to
00274   /// ACE_Asynch_Read_Stream factory.
00275   ACE_WIN32_Asynch_Read_Stream_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00276                                        ACE_HANDLE handle,
00277                                        ACE_Message_Block &message_block,
00278                                        size_t bytes_to_read,
00279                                        const void* act,
00280                                        ACE_HANDLE event,
00281                                        int priority,
00282                                        int signal_number = 0,
00283                                        int scatter_enabled = 0);
00284 
00285   /// Proactor will call this method when the read completes.
00286   virtual void complete (size_t bytes_transferred,
00287                          int success,
00288                          const void *completion_key,
00289                          u_long error);
00290 
00291   /// Destructor.
00292   virtual ~ACE_WIN32_Asynch_Read_Stream_Result (void);
00293 
00294   /// Bytes requested when the asynchronous read was initiated.
00295   size_t bytes_to_read_;
00296 
00297   /// Message block for reading the data into.
00298   ACE_Message_Block &message_block_;
00299 
00300   /// I/O handle used for reading.
00301   ACE_HANDLE handle_;
00302 
00303   /// Flag for scatter read
00304   int scatter_enabled_;
00305 };
00306 
00307 /**
00308  * @class ACE_WIN32_Asynch_Read_Stream
00309  *
00310  * @brief This class is a factory for starting off asynchronous reads
00311  *     on a stream.
00312  *
00313  *     Once <open> is called, multiple asynchronous <read>s can
00314  *     started using this class.  An ACE_Asynch_Read_Stream::Result
00315  *     will be passed back to the @a handler when the asynchronous
00316  *     reads completes through the <ACE_Handler::handle_read_stream>
00317  *     callback.
00318  */
00319 class ACE_Export ACE_WIN32_Asynch_Read_Stream : public virtual ACE_Asynch_Read_Stream_Impl,
00320                                                 public ACE_WIN32_Asynch_Operation
00321 {
00322 
00323 public:
00324   /// Constructor.
00325   ACE_WIN32_Asynch_Read_Stream (ACE_WIN32_Proactor *win32_proactor);
00326 
00327   /// This starts off an asynchronous read.  Upto @a bytes_to_read will
00328   /// be read and stored in the @a message_block.
00329   int read (ACE_Message_Block &message_block,
00330             size_t bytes_to_read,
00331             const void *act,
00332             int priority,
00333             int signal_number = 0);
00334 
00335   /**
00336   * Same as above but with scatter support, through chaining of composite
00337   * message blocks using the continuation field.
00338   */
00339   int readv (ACE_Message_Block &message_block,
00340              size_t bytes_to_read,
00341              const void *act,
00342              int priority,
00343              int signal_number = 0);
00344 
00345   /// Destructor.
00346   virtual ~ACE_WIN32_Asynch_Read_Stream (void);
00347 
00348   // Methods belong to ACE_WIN32_Asynch_Operation base class. These
00349   // methods are defined here to avoid VC++ warnings. They route the
00350   // call to the ACE_WIN32_Asynch_Operation base class.
00351 
00352   /**
00353    * Initializes the factory with information which will be used with
00354    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
00355    * <ACE_Handler::handle> will be called on the @a handler to get the
00356    * correct handle.
00357    */
00358   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
00359             ACE_HANDLE handle,
00360             const void *completion_key,
00361             ACE_Proactor *proactor);
00362 
00363   /**
00364    * This cancels all pending accepts operations that were issued by
00365    * the calling thread.  The function does not cancel asynchronous
00366    * operations issued by other threads.
00367    */
00368   int cancel (void);
00369 
00370   /// Return the underlying proactor.
00371   ACE_Proactor* proactor (void) const;
00372 
00373 protected:
00374   /// This is the method which does the real work and is there so that
00375   /// the ACE_Asynch_Read_File class can use it too.
00376   int shared_read (ACE_WIN32_Asynch_Read_Stream_Result *result);
00377 };
00378 
00379 /**
00380  * @class ACE_WIN32_Asynch_Write_Stream_Result
00381  *
00382  * @brief This class provides concrete implementation for
00383  *    ACE_Asynch_Write_Stream::Result class.
00384  */
00385 class ACE_Export ACE_WIN32_Asynch_Write_Stream_Result : public virtual ACE_Asynch_Write_Stream_Result_Impl,
00386                                                         public ACE_WIN32_Asynch_Result
00387 {
00388   /// Factory class willl have special permissions.
00389   friend class ACE_WIN32_Asynch_Write_Stream;
00390 
00391   /// Proactor class has special permission.
00392   friend class ACE_WIN32_Proactor;
00393 
00394 public:
00395   /// The number of bytes which were requested at the start of the
00396   /// asynchronous write.
00397   size_t bytes_to_write (void) const;
00398 
00399   /// Message block that contains the data to be written.
00400   ACE_Message_Block &message_block (void) const;
00401 
00402   /// I/O handle used for writing.
00403   ACE_HANDLE handle (void) const;
00404 
00405   // = Base class operations. These operations are here to kill some
00406   //   warnings. These methods call the base class methods.
00407 
00408   /// Number of bytes transferred by the operation.
00409   size_t bytes_transferred (void) const;
00410 
00411   /// ACT associated with the operation.
00412   const void *act (void) const;
00413 
00414   /// Did the operation succeed?
00415   int success (void) const;
00416 
00417   /**
00418    * This returns the ACT associated with the handle when it was
00419    * registered with the I/O completion port.  This ACT is not the
00420    * same as the ACT associated with the asynchronous operation.
00421    */
00422   const void *completion_key (void) const;
00423 
00424   /// Error value if the operation fail.
00425   u_long error (void) const;
00426 
00427   /// Event associated with the OVERLAPPED structure.
00428   ACE_HANDLE event (void) const;
00429 
00430   /// This really make sense only when doing file I/O.
00431   u_long offset (void) const;
00432 
00433   /// Offset_high associated with the OVERLAPPED structure.
00434   u_long offset_high (void) const;
00435 
00436   /// The priority of the asynchronous operation. Currently, this is
00437   /// not supported on Win32.
00438   int priority (void) const;
00439 
00440   /// No-op. Returns 0.
00441   int signal_number (void) const;
00442 
00443   /// Post @c this to the Proactor's completion port.
00444   int post_completion (ACE_Proactor_Impl *proactor);
00445 
00446   /// Accessor for the gather write flag
00447   int gather_enabled (void) const;
00448 
00449 protected:
00450   /// Constructor is protected since creation is limited to
00451   /// ACE_Asynch_Write_Stream factory.
00452   ACE_WIN32_Asynch_Write_Stream_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00453                                         ACE_HANDLE handle,
00454                                         ACE_Message_Block &message_block,
00455                                         size_t bytes_to_write,
00456                                         const void* act,
00457                                         ACE_HANDLE event,
00458                                         int priority,
00459                                         int signal_number = 0,
00460                                         int gather_enabled = 0);
00461 
00462   /// ACE_Proactor will call this method when the write completes.
00463   virtual void complete (size_t bytes_transferred,
00464                          int success,
00465                          const void *completion_key,
00466                          u_long error);
00467 
00468   /// Destructor.
00469   virtual ~ACE_WIN32_Asynch_Write_Stream_Result (void);
00470 
00471   /// The number of bytes which were requested at the start of the
00472   /// asynchronous write.
00473   size_t bytes_to_write_;
00474 
00475   /// Message block that contains the data to be written.
00476   ACE_Message_Block &message_block_;
00477 
00478   /// I/O handle used for writing.
00479   ACE_HANDLE handle_;
00480 
00481   /// Flag for gather write
00482   int gather_enabled_;
00483 };
00484 
00485 /**
00486  * @class ACE_WIN32_Asynch_Write_Stream
00487  *
00488  * @brief This class is a factory for starting off asynchronous writes
00489  *    on a stream.
00490  *
00491  *
00492  *     Once <open> is called, multiple asynchronous <writes>s can
00493  *     started using this class.  A ACE_Asynch_Write_Stream::Result
00494  *     will be passed back to the @a handler when the asynchronous
00495  *     write completes through the
00496  *     <ACE_Handler::handle_write_stream> callback.
00497  */
00498 class ACE_Export ACE_WIN32_Asynch_Write_Stream : public virtual ACE_Asynch_Write_Stream_Impl,
00499                                                  public ACE_WIN32_Asynch_Operation
00500 {
00501 public:
00502   /// Constructor.
00503   ACE_WIN32_Asynch_Write_Stream (ACE_WIN32_Proactor *win32_proactor);
00504 
00505   /// This starts off an asynchronous write.  Upto @a bytes_to_write
00506   /// will be written from the @a message_block.
00507   int write (ACE_Message_Block &message_block,
00508              size_t bytes_to_write,
00509              const void *act,
00510              int priority,
00511              int signal_number = 0);
00512 
00513   /**
00514   * Same as above but with gather support, through chaining of composite
00515   * message blocks using the continuation field.
00516   */
00517   int writev (ACE_Message_Block &message_block,
00518               size_t bytes_to_write,
00519               const void *act,
00520               int priority,
00521               int signal_number = 0);
00522 
00523   /// Destructor.
00524   virtual ~ACE_WIN32_Asynch_Write_Stream (void);
00525 
00526   // = Methods belonging to <ACE_WIN32_Asynch_Operation> base class.
00527 
00528   // These methods are defined here to avoid VC++ warnings. They route
00529   // the call to the <ACE_WIN32_Asynch_Operation> base class.
00530 
00531   /**
00532    * Initializes the factory with information which will be used with
00533    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
00534    * <ACE_Handler::handle> will be called on the @a handler to get the
00535    * correct handle.
00536    */
00537   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
00538             ACE_HANDLE handle,
00539             const void *completion_key,
00540             ACE_Proactor *proactor);
00541 
00542   /**
00543    * This cancels all pending accepts operations that were issued by
00544    * the calling thread.  The function does not cancel asynchronous
00545    * operations issued by other threads.
00546    */
00547   int cancel (void);
00548 
00549   /// Return the underlying proactor.
00550   ACE_Proactor* proactor (void) const;
00551 
00552 protected:
00553   /// This is the method which does the real work and is there so that
00554   /// the ACE_Asynch_Write_File class can use it too.
00555   int shared_write (ACE_WIN32_Asynch_Write_Stream_Result *result);
00556 };
00557 
00558 /**
00559  * @class ACE_WIN32_Asynch_Read_File_Result
00560  *
00561  * @brief This class provides concrete implementation for
00562  *     ACE_Asynch_Read_File::Result class.
00563  */
00564 class ACE_Export ACE_WIN32_Asynch_Read_File_Result : public virtual ACE_Asynch_Read_File_Result_Impl,
00565                                                      public ACE_WIN32_Asynch_Read_Stream_Result
00566 {
00567   /// Factory class will have special permissions.
00568   friend class ACE_WIN32_Asynch_Read_File;
00569 
00570   /// Proactor class has special permission.
00571   friend class ACE_WIN32_Proactor;
00572 
00573 public:
00574   // = These methods belong to ACE_WIN32_Asynch_Result class base
00575   //   class. These operations are here to kill some warnings. These
00576   //   methods call the base class methods.
00577 
00578   /// Number of bytes transferred by the operation.
00579   size_t bytes_transferred (void) const;
00580 
00581   /// ACT associated with the operation.
00582   const void *act (void) const;
00583 
00584   /// Did the operation succeed?
00585   int success (void) const;
00586 
00587   /**
00588    * This returns the ACT associated with the handle when it was
00589    * registered with the I/O completion port.  This ACT is not the
00590    * same as the ACT associated with the asynchronous operation.
00591    */
00592   const void *completion_key (void) const;
00593 
00594   /// Error value if the operation fail.
00595   u_long error (void) const;
00596 
00597   /// Event associated with the OVERLAPPED structure.
00598   ACE_HANDLE event (void) const;
00599 
00600   /// This really make sense only when doing file I/O.
00601   u_long offset (void) const;
00602 
00603   /// Offset_high associated with the OVERLAPPED structure.
00604   u_long offset_high (void) const;
00605 
00606   /// The priority of the asynchronous operation. Currently, this is
00607   /// not supported on Win32.
00608   int priority (void) const;
00609 
00610   /// No-op. Returns 0.
00611   int signal_number (void) const;
00612 
00613   // The following methods belong to
00614   // ACE_WIN32_Asynch_Read_Stream_Result. They are here to avoid VC++
00615   // dominance warnings. These methods route their call to the
00616   // ACE_WIN32_Asynch_Read_Stream_Result base class.
00617 
00618   /// The number of bytes which were requested at the start of the
00619   /// asynchronous read.
00620   size_t bytes_to_read (void) const;
00621 
00622   /// Message block which contains the read data.
00623   ACE_Message_Block &message_block (void) const;
00624 
00625   /// I/O handle used for reading.
00626   ACE_HANDLE handle (void) const;
00627 
00628   /// Post @c this to the Proactor's completion port.
00629   int post_completion (ACE_Proactor_Impl *proactor);
00630 
00631 protected:
00632   /// Constructor is protected since creation is limited to
00633   /// ACE_Asynch_Read_File factory.
00634   ACE_WIN32_Asynch_Read_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00635                                      ACE_HANDLE handle,
00636                                      ACE_Message_Block &message_block,
00637                                      size_t bytes_to_read,
00638                                      const void* act,
00639                                      u_long offset,
00640                                      u_long offset_high,
00641                                      ACE_HANDLE event,
00642                                      int priority,
00643                                      int signal_number = 0,
00644                                      int scatter_enabled = 0);
00645 
00646   /// ACE_Proactor will call this method when the read completes.
00647   virtual void complete (size_t bytes_transferred,
00648                          int success,
00649                          const void *completion_key,
00650                          u_long error);
00651 
00652   /// Destructor.
00653   virtual ~ACE_WIN32_Asynch_Read_File_Result (void);
00654 };
00655 
00656 /**
00657  * @class ACE_WIN32_Asynch_Read_File
00658  *
00659  * @brief This class is a factory for starting off asynchronous reads
00660  *     on a file.
00661  *
00662  *     Once <open> is called, multiple asynchronous <read>s can
00663  *     started using this class.  A ACE_Asynch_Read_File::Result
00664  *     will be passed back to the @a handler when the asynchronous
00665  *     reads completes through the <ACE_Handler::handle_read_file>
00666  *     callback.
00667  *
00668  *     This class differs slightly from ACE_Asynch_Read_Stream as it
00669  *     allows the user to specify an offset for the read.
00670  */
00671 class ACE_Export ACE_WIN32_Asynch_Read_File : public virtual ACE_Asynch_Read_File_Impl,
00672                                               public ACE_WIN32_Asynch_Read_Stream
00673 {
00674 
00675 public:
00676   /// Constructor.
00677   ACE_WIN32_Asynch_Read_File (ACE_WIN32_Proactor *win32_proactor);
00678 
00679   /**
00680    * This starts off an asynchronous read.  Upto @a bytes_to_read will
00681    * be read and stored in the @a message_block.  The read will start
00682    * at @a offset from the beginning of the file.
00683    */
00684   int read (ACE_Message_Block &message_block,
00685             size_t bytes_to_read,
00686             u_long offset,
00687             u_long offset_high,
00688             const void *act,
00689             int priority,
00690             int signal_number = 0);
00691 
00692   /**
00693   * Same as above but with scatter support, through chaining of
00694   * composite message blocks using the continuation field.
00695   * @note Each data block payload must be at least the size of a
00696   * system memory page and must be aligned on a system memory page
00697   * size boundary
00698   */
00699   int readv (ACE_Message_Block &message_block,
00700              size_t bytes_to_read,
00701              u_long offset,
00702              u_long offset_high,
00703              const void *act,
00704              int priority,
00705              int signal_number = 0);
00706 
00707 
00708   /// Destructor.
00709   virtual ~ACE_WIN32_Asynch_Read_File (void);
00710 
00711   // = Methods belong to ACE_WIN32_Asynch_Operation base class. These
00712   //   methods are defined here to avoid VC++ warnings. They route the
00713   //   call to the ACE_WIN32_Asynch_Operation base class.
00714 
00715   /**
00716    * Initializes the factory with information which will be used with
00717    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
00718    * <ACE_Handler::handle> will be called on the @a handler to get the
00719    * correct handle.
00720    */
00721   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
00722             ACE_HANDLE handle,
00723             const void *completion_key,
00724             ACE_Proactor *proactor);
00725 
00726   /**
00727    * This cancels all pending accepts operations that were issued by
00728    * the calling thread.  The function does not cancel asynchronous
00729    * operations issued by other threads.
00730    */
00731   int cancel (void);
00732 
00733   /// Return the underlying proactor.
00734   ACE_Proactor* proactor (void) const;
00735 
00736 private:
00737   /**
00738    * This method belongs to ACE_WIN32_Asynch_Read_Stream. It is here
00739    * to avoid the compiler warnings. We forward this call to the
00740    * ACE_WIN32_Asynch_Read_Stream class.
00741    */
00742   int read (ACE_Message_Block &message_block,
00743             size_t bytes_to_read,
00744             const void *act,
00745             int priority,
00746             int signal_number = 0);
00747 
00748   /**
00749   * Same as above but with scatter support, through chaining of composite
00750   * message blocks using the continuation field.
00751   */
00752   int readv (ACE_Message_Block &message_block,
00753              size_t bytes_to_read,
00754              const void *act,
00755              int priority,
00756              int signal_number = 0);
00757 };
00758 
00759 /**
00760  * @class ACE_WIN32_Asynch_Write_File_Result
00761  *
00762  * @brief  This class provides implementation for
00763  *      ACE_Asynch_Write_File_Result for WIN32 platforms.
00764  *
00765  *     This class has all the information necessary for the
00766  *     @a handler to uniquiely identify the completion of the
00767  *     asynchronous write.
00768  *
00769  *     This class differs slightly from
00770  *     ACE_Asynch_Write_Stream::Result as it calls back
00771  *     <ACE_Handler::handle_write_file> on the @a handler instead
00772  *     of <ACE_Handler::handle_write_stream>.  No additional state
00773  *     is required by this class as ACE_Asynch_Result can store
00774  *     the @a offset.
00775  */
00776 class ACE_Export ACE_WIN32_Asynch_Write_File_Result : public virtual ACE_Asynch_Write_File_Result_Impl,
00777                                                       public ACE_WIN32_Asynch_Write_Stream_Result
00778 {
00779   /// Factory class will have special permission.
00780   friend class ACE_WIN32_Asynch_Write_File;
00781 
00782   /// Proactor class has special permission.
00783   friend class ACE_WIN32_Proactor;
00784 
00785 public:
00786   // = Base class operations. These operations are here to kill some
00787   //   warnings. These methods call the base class methods.
00788 
00789   /// Number of bytes transferred by the operation.
00790   size_t bytes_transferred (void) const;
00791 
00792   /// ACT associated with the operation.
00793   const void *act (void) const;
00794 
00795   /// Did the operation succeed?
00796   int success (void) const;
00797 
00798   /**
00799    * This returns the ACT associated with the handle when it was
00800    * registered with the I/O completion port.  This ACT is not the
00801    * same as the ACT associated with the asynchronous operation.
00802    */
00803   const void *completion_key (void) const;
00804 
00805   /// Error value if the operation fail.
00806   u_long error (void) const;
00807 
00808   /// Event associated with the OVERLAPPED structure.
00809   ACE_HANDLE event (void) const;
00810 
00811   /// This really make sense only when doing file I/O.
00812   u_long offset (void) const;
00813 
00814   /// Offset_high associated with the OVERLAPPED structure.
00815   u_long offset_high (void) const;
00816 
00817   /// The priority of the asynchronous operation. Currently, this is
00818   /// not supported on Win32.
00819   int priority (void) const;
00820 
00821   /// No-op. Returns 0.
00822   int signal_number (void) const;
00823 
00824   // The following methods belong to
00825   // ACE_WIN32_Asynch_Read_Stream_Result. They are here to avoid VC++
00826   // warnings. These methods route their call to the
00827   // ACE_WIN32_Asynch_Read_Stream_Result base class.
00828 
00829   /// The number of bytes which were requested at the start of the
00830   /// asynchronous write.
00831   size_t bytes_to_write (void) const;
00832 
00833   /// Message block that contains the data to be written.
00834   ACE_Message_Block &message_block (void) const;
00835 
00836   /// I/O handle used for writing.
00837   ACE_HANDLE handle (void) const;
00838 
00839   /// Post @c this to the Proactor's completion port.
00840   int post_completion (ACE_Proactor_Impl *proactor);
00841 
00842 protected:
00843   /// Constructor is protected since creation is limited to
00844   /// ACE_Asynch_Write_File factory.
00845   ACE_WIN32_Asynch_Write_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00846                                       ACE_HANDLE handle,
00847                                       ACE_Message_Block &message_block,
00848                                       size_t bytes_to_write,
00849                                       const void* act,
00850                                       u_long offset,
00851                                       u_long offset_high,
00852                                       ACE_HANDLE event,
00853                                       int priority,
00854                                       int signal_number = 0,
00855                                       int gather_enabled = 0);
00856 
00857   /// ACE_Proactor will call this method when the write completes.
00858   virtual void complete (size_t bytes_transferred,
00859                          int success,
00860                          const void *completion_key,
00861                          u_long error);
00862 
00863   /// Destructor.
00864   virtual ~ACE_WIN32_Asynch_Write_File_Result (void);
00865 };
00866 
00867 /**
00868  * @class ACE_WIN32_Asynch_Write_File
00869  *
00870  * @brief This class is a factory for starting off asynchronous writes
00871  *     on a file.
00872  *
00873  *     Once <open> is called, multiple asynchronous <write>s can be
00874  *     started using this class.  A ACE_Asynch_Write_File::Result
00875  *     will be passed back to the @a handler when the asynchronous
00876  *     writes completes through the <ACE_Handler::handle_write_file>
00877  *     callback.
00878  */
00879 class ACE_Export ACE_WIN32_Asynch_Write_File : public virtual ACE_Asynch_Write_File_Impl,
00880                                                public ACE_WIN32_Asynch_Write_Stream
00881 {
00882 public:
00883   /// Constructor.
00884   ACE_WIN32_Asynch_Write_File (ACE_WIN32_Proactor *win32_proactor);
00885 
00886   /**
00887    * This starts off an asynchronous write.  Upto @a bytes_to_write
00888    * will be write and stored in the @a message_block.  The write will
00889    * start at @a offset from the beginning of the file.
00890    */
00891   int write (ACE_Message_Block &message_block,
00892              size_t bytes_to_write,
00893              u_long offset,
00894              u_long offset_high,
00895              const void *act,
00896              int priority,
00897              int signal_number = 0);
00898 
00899   /**
00900   * Same as above but with gather support, through chaining of
00901   * composite message blocks using the continuation field.
00902   * @note Each data block payload must be at least the size of a
00903   * system memory page and must be aligned on a system memory page
00904   * size boundary
00905   */
00906   int writev (ACE_Message_Block &message_block,
00907               size_t bytes_to_write,
00908               u_long offset,
00909               u_long offset_high,
00910               const void *act,
00911               int priority,
00912               int signal_number = 0);
00913 
00914   /// Destrcutor.
00915   virtual ~ACE_WIN32_Asynch_Write_File (void);
00916 
00917   // = Methods belong to ACE_WIN32_Asynch_Operation base class. These
00918   //   methods are defined here to avoid VC++ warnings. They route the
00919   //   call to the ACE_WIN32_Asynch_Operation base class.
00920 
00921   /**
00922    * Initializes the factory with information which will be used with
00923    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
00924    * <ACE_Handler::handle> will be called on the @a handler to get the
00925    * correct handle.
00926    */
00927   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
00928             ACE_HANDLE handle,
00929             const void *completion_key,
00930             ACE_Proactor *proactor);
00931 
00932   /**
00933    * This cancels all pending accepts operations that were issued by
00934    * the calling thread.  The function does not cancel asynchronous
00935    * operations issued by other threads.
00936    */
00937   int cancel (void);
00938 
00939   /// Return the underlying proactor.
00940   ACE_Proactor* proactor (void) const;
00941 
00942 private:
00943   /**
00944    * This method belongs to ACE_WIN32_Asynch_Write_Stream. It is here
00945    * to avoid compiler warnings. This method is forwarded to the
00946    * ACE_WIN32_Asynch_Write_Stream class.
00947    */
00948   int write (ACE_Message_Block &message_block,
00949              size_t bytes_to_write,
00950              const void *act,
00951              int priority,
00952              int signal_number = 0);
00953 
00954   /**
00955   * Same as above but with gather support, through chaining of composite
00956   * message blocks using the continuation field.
00957   */
00958   int writev (ACE_Message_Block &message_block,
00959               size_t bytes_to_write,
00960               const void *act,
00961               int priority,
00962               int signal_number = 0);
00963 };
00964 
00965 /**
00966  * @class ACE_WIN32_Asynch_Accept_Result
00967  *
00968  * @brief This class implements ACE_Asynch_Accept::Result for WIN32
00969  *     platform.
00970  *
00971  *     This class has all the information necessary for the
00972  *     @a handler to uniquiely identify the completion of the
00973  *     asynchronous accept.
00974  */
00975 class ACE_Export ACE_WIN32_Asynch_Accept_Result : public virtual ACE_Asynch_Accept_Result_Impl,
00976                                                   public ACE_WIN32_Asynch_Result
00977 {
00978   /// Factory will have special permission.
00979   friend class ACE_WIN32_Asynch_Accept;
00980 
00981   /// Proactor class has special permission.
00982   friend class ACE_WIN32_Proactor;
00983 
00984 public:
00985   /// The number of bytes which were requested at the start of the
00986   /// asynchronous accept.
00987   size_t bytes_to_read (void) const;
00988 
00989   /// Message block which contains the read data.
00990   ACE_Message_Block &message_block (void) const;
00991 
00992   /// I/O handle used for accepting new connections.
00993   ACE_HANDLE listen_handle (void) const;
00994 
00995   /// I/O handle for the new connection.
00996   ACE_HANDLE accept_handle (void) const;
00997 
00998   // = Base class operations. These operations are here to kill some
00999   //   warnings. These methods call the base class methods.
01000 
01001   /// Number of bytes transferred by the operation.
01002   size_t bytes_transferred (void) const;
01003 
01004   /// ACT associated with the operation.
01005   const void *act (void) const;
01006 
01007   /// Did the operation succeed?
01008   int success (void) const;
01009 
01010   /**
01011    * This returns the ACT associated with the handle when it was
01012    * registered with the I/O completion port.  This ACT is not the
01013    * same as the ACT associated with the asynchronous operation.
01014    */
01015   const void *completion_key (void) const;
01016 
01017   /// Error value if the operation fail.
01018   u_long error (void) const;
01019 
01020   /// Event associated with the OVERLAPPED structure.
01021   ACE_HANDLE event (void) const;
01022 
01023   /// This really make sense only when doing file I/O.
01024   u_long offset (void) const;
01025 
01026   /// Offset_high associated with the OVERLAPPED structure.
01027   u_long offset_high (void) const;
01028 
01029   /// The priority of the asynchronous operation. Currently, this is
01030   /// not supported on Win32.
01031   int priority (void) const;
01032 
01033   /// No-op. Returns 0.
01034   int signal_number (void) const;
01035 
01036   /// Post @c this to the Proactor's completion port.
01037   int post_completion (ACE_Proactor_Impl *proactor);
01038 
01039 protected:
01040   /// Constructor is protected since creation is limited to
01041   /// ACE_Asynch_Accept factory.
01042   ACE_WIN32_Asynch_Accept_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
01043                                   ACE_HANDLE listen_handle,
01044                                   ACE_HANDLE accept_handle,
01045                                   ACE_Message_Block &message_block,
01046                                   size_t bytes_to_read,
01047                                   const void* act,
01048                                   ACE_HANDLE event,
01049                                   int priority,
01050                                   int signal_number = 0);
01051 
01052   /// ACE_Proactor will call this method when the accept completes.
01053   virtual void complete (size_t bytes_transferred,
01054                          int success,
01055                          const void *completion_key,
01056                          u_long error);
01057 
01058   /// Destructor.
01059   virtual ~ACE_WIN32_Asynch_Accept_Result (void);
01060 
01061   /// Bytes requested when the asynchronous read was initiated.
01062   size_t bytes_to_read_;
01063 
01064   /// Message block for reading the data into.
01065   ACE_Message_Block &message_block_;
01066 
01067   /// I/O handle used for accepting new connections.
01068   ACE_HANDLE listen_handle_;
01069 
01070   /// I/O handle for the new connection.
01071   ACE_HANDLE accept_handle_;
01072 };
01073 
01074 /**
01075  * @class ACE_WIN32_Asynch_Accept
01076  *
01077  * @brief This class is a factory for starting off asynchronous accepts
01078  *     on a listen handle.
01079  *
01080  *     Once <open> is called, multiple asynchronous <accept>s can
01081  *     started using this class.  A ACE_Asynch_Accept::Result will
01082  *     be passed back to the @a handler when the asynchronous accept
01083  *     completes through the <ACE_Handler::handle_accept>
01084  *     callback.
01085  */
01086 class ACE_Export ACE_WIN32_Asynch_Accept : public virtual ACE_Asynch_Accept_Impl,
01087                                            public ACE_WIN32_Asynch_Operation
01088 {
01089 public:
01090   /// Constructor.
01091   ACE_WIN32_Asynch_Accept (ACE_WIN32_Proactor *win32_proactor);
01092 
01093   /**
01094    * This starts off an asynchronous accept.  The asynchronous accept
01095    * call also allows any initial data to be returned to the
01096    * @a handler.  Upto @a bytes_to_read will be read and stored in the
01097    * @a message_block.  The <accept_handle> will be used for the
01098    * <accept> call.  If (<accept_handle> == INVALID_HANDLE), a new
01099    * handle will be created.
01100    *
01101    * @a message_block must be specified. This is because the address of
01102    * the new connection is placed at the end of this buffer.
01103    */
01104   int accept (ACE_Message_Block &message_block,
01105               size_t bytes_to_read,
01106               ACE_HANDLE accept_handle,
01107               const void *act,
01108               int priority,
01109               int signal_number = 0,
01110               int addr_family = AF_INET);
01111 
01112   /// Destructor.
01113   ~ACE_WIN32_Asynch_Accept (void);
01114 
01115   // Methods belong to ACE_WIN32_Asynch_Operation base class. These
01116   // methods are defined here to avoid VC++ warnings. They route the
01117   // call to the ACE_WIN32_Asynch_Operation base class.
01118 
01119   /**
01120    * Initializes the factory with information which will be used with
01121    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
01122    * <ACE_Handler::handle> will be called on the @a handler to get the
01123    * correct handle.
01124    */
01125   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
01126             ACE_HANDLE handle,
01127             const void *completion_key,
01128             ACE_Proactor *proactor);
01129 
01130   /**
01131    * This cancels all pending accepts operations that were issued by
01132    * the calling thread.  The function does not cancel asynchronous
01133    * operations issued by other threads.
01134    */
01135   int cancel (void);
01136 
01137   /// Return the underlying proactor.
01138   ACE_Proactor* proactor (void) const;
01139 };
01140 
01141 /**
01142  * @class ACE_WIN32_Asynch_Connect_Result
01143  *
01144  * @brief This is that class which will be passed back to the
01145  *        completion handler when the asynchronous connect completes.
01146  *
01147  *     This class has all the information necessary for the
01148  *     completion handler to uniquiely identify the completion of the
01149  *     asynchronous connect.
01150  */
01151 class ACE_Export ACE_WIN32_Asynch_Connect_Result : public virtual ACE_Asynch_Connect_Result_Impl,
01152                                                    public ACE_WIN32_Asynch_Result
01153 {
01154   /// Factory classes will have special permissions.
01155   friend class ACE_WIN32_Asynch_Connect;
01156 
01157   /// The Proactor constructs the Result class for faking results.
01158   friend class ACE_WIN32_Proactor;
01159 
01160 public:
01161 
01162   /// I/O handle for the  connection.
01163   ACE_HANDLE connect_handle (void) const;
01164 
01165   // = Base class operations. These operations are here to kill some
01166   //   warnings. These methods call the base class methods.
01167 
01168   /// Number of bytes transferred by the operation.
01169   size_t bytes_transferred (void) const;
01170 
01171   /// ACT associated with the operation.
01172   const void *act (void) const;
01173 
01174   /// Did the operation succeed?
01175   int success (void) const;
01176 
01177   /**
01178    * Returns the ACT associated with the handle when it was
01179    * registered with the I/O completion port.  This ACT is not the
01180    * same as the ACT associated with the asynchronous operation.
01181    */
01182   const void *completion_key (void) const;
01183 
01184   /// Error value if the operation fail.
01185   u_long error (void) const;
01186 
01187   /// Event associated with the OVERLAPPED structure.
01188   ACE_HANDLE event (void) const;
01189 
01190   /// This really make sense only when doing file I/O.
01191   u_long offset (void) const;
01192 
01193   /// Offset_high associated with the OVERLAPPED structure.
01194   u_long offset_high (void) const;
01195 
01196   /// The priority of the asynchronous operation. Currently, this is
01197   /// not supported on Win32.
01198   int priority (void) const;
01199 
01200   /// No-op. Returns 0.
01201   int signal_number (void) const;
01202 
01203   /// Post this object to the Proactor's completion port.
01204   int post_completion (ACE_Proactor_Impl *proactor);
01205 
01206 protected:
01207   /// Constructor is protected since creation is limited to
01208   /// ACE_Asynch_Connect factory.
01209   ACE_WIN32_Asynch_Connect_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
01210                                    ACE_HANDLE  connect_handle,
01211                                    const void* act,
01212                                    ACE_HANDLE  event,
01213                                    int priority,
01214                                    int signal_number);
01215 
01216   /// ACE_Proactor will call this method when the accept completes.
01217   virtual void complete (size_t bytes_transferred,
01218                          int success,
01219                          const void *completion_key,
01220                          u_long error);
01221 
01222   /// Destructor.
01223   virtual ~ACE_WIN32_Asynch_Connect_Result (void);
01224 
01225   /// Set the I/O handle for the new connection.
01226   void  connect_handle (ACE_HANDLE handle);
01227 
01228   ACE_HANDLE  connect_handle_;
01229 };
01230 
01231 
01232 /**
01233  * @class ACE_WIN32_Asynch_Connect
01234  */
01235 class ACE_Export ACE_WIN32_Asynch_Connect :
01236   public virtual ACE_Asynch_Connect_Impl,
01237   public ACE_WIN32_Asynch_Operation,
01238   public ACE_Event_Handler
01239 {
01240 public:
01241 
01242   /// Constructor.
01243   ACE_WIN32_Asynch_Connect (ACE_WIN32_Proactor * win32_proactor);
01244 
01245   /// Destructor.
01246   virtual ~ACE_WIN32_Asynch_Connect (void);
01247 
01248  /**
01249    * This open belongs to ACE_WIN32_Asynch_Operation. We forward
01250    * this call to that method. We have put this here to avoid the
01251    * compiler warnings.
01252    */
01253   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
01254             ACE_HANDLE handle,
01255             const void *completion_key,
01256             ACE_Proactor *proactor = 0);
01257 
01258   /**
01259    * Start an asynchronous connect.
01260    *
01261    * @param connect_handle Handle to use for the connect. If the value
01262    *                       ACE_INVALID_HANDLE, a new handle will be created.
01263    *
01264    * @retval 0  Success
01265    * @retval -1 Error
01266    */
01267   int connect (ACE_HANDLE connect_handle,
01268                const ACE_Addr &remote_sap,
01269                const ACE_Addr &local_sap,
01270                int  reuse_addr,
01271                const void *act,
01272                int priority,
01273                int signal_number = 0);
01274 
01275   /**
01276    *  Cancel all pending pseudo-asynchronus requests
01277    *  Behavior as usual AIO request
01278    */
01279   int cancel (void);
01280 
01281   /**
01282    *  Close performs cancellation of all pending requests
01283    *  and close the connect handle
01284    */
01285   int close (void);
01286 
01287   /// Virtual from ACE_Event_Handler
01288   ACE_HANDLE get_handle (void) const;
01289 
01290   /// Virtual from ACE_Event_Handler
01291   void set_handle (ACE_HANDLE handle);
01292 
01293   /// Virtual from ACE_Event_Handler
01294   int handle_input  ( ACE_HANDLE handle);
01295   int handle_output ( ACE_HANDLE handle);
01296   int handle_exception ( ACE_HANDLE handle);
01297 
01298   /// Virtual from ACE_Event_Handler
01299   int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask) ;
01300 
01301   // = Methods belong to ACE_WIN32_Asynch_Operation base class. These
01302   //   methods are defined here to avoid dominace warnings. They route
01303   //   the call to the ACE_WIN32_Asynch_Operation base class.
01304   /// Return the underlying proactor.
01305   ACE_Proactor* proactor (void) const;
01306 
01307 private:
01308   int connect_i (ACE_WIN32_Asynch_Connect_Result *result,
01309                  const ACE_Addr &remote_sap,
01310                  const ACE_Addr &local_sap,
01311                  int reuse_addr);
01312 
01313   int post_result (ACE_WIN32_Asynch_Connect_Result *result, bool flg_post);
01314 
01315   /// Cancel uncompleted connect operations.
01316   /**
01317    * @param flg_notify Indicates whether or not to send notification about
01318    *                   canceled connect operations.  If false, don't send
01319    *                   notifications. If true, notify user about canceled
01320    *                   connects.
01321    *                   According WIN32 standards we should receive
01322    *                   notifications on canceled AIO requests.
01323    *
01324    * @param set        Receives the set of I/O handles on which asynchronous
01325    *                   connect requests were canceled as a result of this
01326    *                   method. The contents of @a set are completely
01327    *                   replaced.
01328    */
01329   int cancel_uncompleted (bool flg_notify, ACE_Handle_Set &set);
01330 
01331   /// true  - Connect is registered in ACE_Asynch_Pseudo_Task
01332   /// false - Accept is deregisted in ACE_Asynch_Pseudo_Task
01333   bool flg_open_ ;
01334 
01335   typedef ACE_Map_Manager<ACE_HANDLE, ACE_WIN32_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX>
01336           MAP_MANAGER;
01337 
01338   /// Map of Result pointers that correspond to all the <accept>'s
01339   /// pending.
01340   MAP_MANAGER result_map_;
01341 
01342   /// The lock to protect the result map which is shared. The queue
01343   /// is updated by main thread in the register function call and
01344   /// through the auxillary thread in the asynch pseudo task.
01345   ACE_SYNCH_MUTEX lock_;
01346 };
01347 
01348 /**
01349  * @class ACE_WIN32_Asynch_Transmit_File_Result
01350  *
01351  *
01352  * @brief This class implements ACE_Asynch_Transmit_File::Result for
01353  *     WIN32 platforms.
01354  *
01355  *     This class has all the information necessary for the
01356  *     @a handler to uniquiely identify the completion of the
01357  *     asynchronous transmit file.
01358  */
01359 class ACE_Export ACE_WIN32_Asynch_Transmit_File_Result : public virtual ACE_Asynch_Transmit_File_Result_Impl,
01360                                                          public ACE_WIN32_Asynch_Result
01361 {
01362   /// Factory class will have special permission.
01363   friend class ACE_WIN32_Asynch_Transmit_File;
01364 
01365   /// Proactor class has special permission.
01366   friend class ACE_WIN32_Proactor;
01367 
01368 public:
01369   /// Socket used for transmitting the file.
01370   ACE_HANDLE socket (void) const;
01371 
01372   /// File from which the data is read.
01373   ACE_HANDLE file (void) const;
01374 
01375   /// Header and trailer data associated with this transmit file.
01376   ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer (void) const;
01377 
01378   /// The number of bytes which were requested at the start of the
01379   /// asynchronous transmit file.
01380   size_t bytes_to_write (void) const;
01381 
01382   /// Number of bytes per send requested at the start of the transmit
01383   /// file.
01384   size_t bytes_per_send (void) const;
01385 
01386   /// Flags which were passed into transmit file.
01387   u_long flags (void) const;
01388 
01389   // Base class operations. These operations are here to kill some
01390   // warnings. These methods call the base class methods.
01391 
01392   /// Number of bytes transferred by the operation.
01393   size_t bytes_transferred (void) const;
01394 
01395   /// ACT associated with the operation.
01396   const void *act (void) const;
01397 
01398   /// Did the operation succeed?
01399   int success (void) const;
01400 
01401   /**
01402    * This returns the ACT associated with the handle when it was
01403    * registered with the I/O completion port.  This ACT is not the
01404    * same as the ACT associated with the asynchronous operation.
01405    */
01406   const void *completion_key (void) const;
01407 
01408   /// Error value if the operation fail.
01409   u_long error (void) const;
01410 
01411   /// Event associated with the OVERLAPPED structure.
01412   ACE_HANDLE event (void) const;
01413 
01414   /// This really make sense only when doing file I/O.
01415   u_long offset (void) const;
01416 
01417   /// Offset_high associated with the OVERLAPPED structure.
01418   u_long offset_high (void) const;
01419 
01420   /// The priority of the asynchronous operation. Currently, this is
01421   /// not supported on Win32.
01422   int priority (void) const;
01423 
01424   /// No-op. Returns 0.
01425   int signal_number (void) const;
01426 
01427   /// Post @c this to the Proactor's completion port.
01428   int post_completion (ACE_Proactor_Impl *proactor);
01429 
01430 protected:
01431   /// Constructor is protected since creation is limited to
01432   /// ACE_Asynch_Transmit_File factory.
01433   ACE_WIN32_Asynch_Transmit_File_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
01434                                          ACE_HANDLE socket,
01435                                          ACE_HANDLE file,
01436                                          ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
01437                                          size_t bytes_to_write,
01438                                          u_long offset,
01439                                          u_long offset_high,
01440                                          size_t bytes_per_send,
01441                                          u_long flags,
01442                                          const void *act,
01443                                          ACE_HANDLE event,
01444                                          int priority,
01445                 int signal_number = 0);
01446 
01447   /// Proactor will call this method when the write completes.
01448   virtual void complete (size_t bytes_transferred,
01449                          int success,
01450                          const void *completion_key,
01451                          u_long error);
01452 
01453   /// Destructor.
01454   virtual ~ACE_WIN32_Asynch_Transmit_File_Result (void);
01455 
01456   /// Network I/O handle.
01457   ACE_HANDLE socket_;
01458 
01459   /// File I/O handle.
01460   ACE_HANDLE file_;
01461 
01462   /// Header and trailer data associated with this transmit file.
01463   ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer_;
01464 
01465   /// The number of bytes which were requested at the start of the
01466   /// asynchronous transmit file.
01467   size_t bytes_to_write_;
01468 
01469   /// Number of bytes per send requested at the start of the transmit
01470   /// file.
01471   size_t bytes_per_send_;
01472 
01473   /// Flags which were passed into transmit file.
01474   u_long flags_;
01475 };
01476 
01477 /**
01478  * @class ACE_WIN32_Asynch_Transmit_File
01479  *
01480  * @brief This class is a factory for starting off asynchronous
01481  *     transmit files on a stream.
01482  *
01483  *     Once <open> is called, multiple asynchronous <transmit_file>s
01484  *     can started using this class.  A
01485  *     ACE_Asynch_Transmit_File::Result will be passed back to the
01486  *     @a handler when the asynchronous transmit file completes
01487  *     through the <ACE_Handler::handle_transmit_file> callback.
01488  *
01489  *     The transmit_file function transmits file data over a
01490  *     connected network connection. The function uses the operating
01491  *     system's cache manager to retrieve the file data. This
01492  *     function provides high-performance file data transfer over
01493  *     network connections.  This function would be of great use in
01494  *     a Web Server, Image Server, etc.
01495  */
01496 class ACE_Export ACE_WIN32_Asynch_Transmit_File : public virtual ACE_Asynch_Transmit_File_Impl,
01497                                                   public ACE_WIN32_Asynch_Operation
01498 {
01499 public:
01500   /// Constructor.
01501   ACE_WIN32_Asynch_Transmit_File (ACE_WIN32_Proactor *win32_proactor);
01502 
01503   /**
01504    * This starts off an asynchronous transmit file. The <file> is a
01505    * handle to an open file.  <header_and_trailer> is a pointer to a
01506    * data structure that contains pointers to data to send before and
01507    * after the file data is sent.  Set this parameter to 0 if you only
01508    * want to transmit the file data.  Upto @a bytes_to_write will be
01509    * written to the <socket>.  If you want to send the entire file,
01510    * let @a bytes_to_write = 0.  @a bytes_per_send is the size of each
01511    * block of data sent per send operation.  Please read the Win32
01512    * documentation on what the flags should be.
01513    */
01514   int transmit_file (ACE_HANDLE file,
01515                      ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
01516                      size_t bytes_to_write,
01517                      u_long offset,
01518                      u_long offset_high,
01519                      size_t bytes_per_send,
01520                      u_long flags,
01521                      const void *act,
01522                      int priority,
01523                      int signal_number = 0);
01524 
01525   /// Destructor.
01526   ~ACE_WIN32_Asynch_Transmit_File (void);
01527 
01528   // Methods belong to ACE_WIN32_Asynch_Operation base class. These
01529   // methods are defined here to avoid VC++ warnings. They route the
01530   // call to the ACE_WIN32_Asynch_Operation base class.
01531 
01532   /**
01533    * Initializes the factory with information which will be used with
01534    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
01535    * <ACE_Handler::handle> will be called on the @a handler to get the
01536    * correct handle.
01537    */
01538   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
01539             ACE_HANDLE handle,
01540             const void *completion_key,
01541             ACE_Proactor *proactor);
01542 
01543   /**
01544    * This cancels all pending accepts operations that were issued by
01545    * the calling thread.  The function does not cancel asynchronous
01546    * operations issued by other threads.
01547    */
01548   int cancel (void);
01549 
01550   /// Return the underlying proactor.
01551   ACE_Proactor* proactor (void) const;
01552 };
01553 
01554 /**
01555  * @class ACE_WIN32_Asynch_Read_Dgram_Result
01556  *
01557  * @brief This class provides concrete implementation for
01558  * ACE_Asynch_Read_Dgram::Result class.
01559  */
01560 class ACE_Export ACE_WIN32_Asynch_Read_Dgram_Result : public virtual ACE_Asynch_Read_Dgram_Result_Impl,
01561                                                       public ACE_WIN32_Asynch_Result
01562 {
01563   /// Factory class will have special permissions.
01564   friend class ACE_WIN32_Asynch_Read_Dgram;
01565 
01566   /// Proactor class has special permission.
01567   friend class ACE_WIN32_Proactor;
01568 
01569 public:
01570   /// The number of bytes which were requested at the start of the
01571   /// asynchronous read.
01572   size_t bytes_to_read (void) const;
01573 
01574   /// Message block which contains the read data
01575   ACE_Message_Block *message_block (void) const;
01576 
01577   /// The address of where the packet came from
01578   int remote_address (ACE_Addr& addr) const;
01579 
01580   sockaddr *saddr () const;
01581 
01582   /// The flags used in the read
01583   int flags (void) const;
01584 
01585   /// I/O handle used for reading.
01586   ACE_HANDLE handle (void) const;
01587 
01588   // Base class operations. These operations are here to kill
01589   // dominance warnings. These methods call the base class methods.
01590 
01591   /// Number of bytes transferred by the operation.
01592   size_t bytes_transferred (void) const;
01593 
01594   /// ACT associated with the operation.
01595   const void *act (void) const;
01596 
01597   /// Did the operation succeed?
01598   int success (void) const;
01599 
01600   /**
01601    * This returns the ACT associated with the handle when it was
01602    * registered with the I/O completion port.  This ACT is not the
01603    * same as the ACT associated with the asynchronous operation.
01604    */
01605   const void *completion_key (void) const;
01606 
01607   /// Error value if the operation fail.
01608   u_long error (void) const;
01609 
01610   /// Event associated with the OVERLAPPED structure.
01611   ACE_HANDLE event (void) const;
01612 
01613   /// This really make sense only when doing file I/O.
01614   u_long offset (void) const;
01615 
01616   /// Offset_high associated with the OVERLAPPED structure.
01617   u_long offset_high (void) const;
01618 
01619   /// The priority of the asynchronous operation. Currently, this is
01620   /// not supported on Win32.
01621   int priority (void) const;
01622 
01623   /// No-op. Returns 0.
01624   int signal_number (void) const;
01625 
01626   /// Post @c this to the Proactor's completion port.
01627   int post_completion (ACE_Proactor_Impl *proactor);
01628 
01629 protected:
01630   /// Constructor is protected since creation is limited to
01631   /// ACE_Asynch_Read_Dgram factory.
01632   ACE_WIN32_Asynch_Read_Dgram_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
01633                                       ACE_HANDLE handle,
01634                                       ACE_Message_Block *message_block,
01635                                       size_t bytes_to_read,
01636                                       int flags,
01637                                       int protocol_family,
01638                                       const void* act,
01639                                       ACE_HANDLE event,
01640                                       int priority,
01641                                       int signal_number = 0);
01642 
01643   /// Proactor will call this method when the read completes.
01644   virtual void complete (size_t bytes_transferred,
01645                          int success,
01646                          const void *completion_key,
01647                          u_long error);
01648 
01649   /// Destructor.
01650   virtual ~ACE_WIN32_Asynch_Read_Dgram_Result (void);
01651 
01652   /// Bytes requested when the asynchronous read was initiated.
01653   size_t bytes_to_read_;
01654 
01655   /// Message block for reading the data into.
01656   ACE_Message_Block *message_block_;
01657 
01658   /// The address of where the packet came from
01659   ACE_Addr *remote_address_;
01660 
01661   int addr_len_;
01662 
01663   /// The flags used in the read
01664   int flags_;
01665 
01666   /// I/O handle used for reading.
01667   ACE_HANDLE handle_;
01668 };
01669 
01670 /**
01671  * @class ACE_WIN32_Asynch_Read_Dgram
01672  *
01673  * @brief This class is a factory for starting off asynchronous reads
01674  *     on a UDP socket.
01675  *
01676  *     Once <open> is called, multiple asynchronous <read>s can be
01677  *     started using this class.  An ACE_Asynch_Read_Dgram::Result
01678  *     will be passed back to the @a handler when the asynchronous
01679  *     reads completes through the <ACE_Handler::handle_read_stream>
01680  *     callback.
01681  *
01682  */
01683 class ACE_Export ACE_WIN32_Asynch_Read_Dgram : public virtual ACE_Asynch_Read_Dgram_Impl,
01684                                                public ACE_WIN32_Asynch_Operation
01685 {
01686 public:
01687   /// Constructor.
01688   ACE_WIN32_Asynch_Read_Dgram (ACE_WIN32_Proactor *win32_proactor);
01689 
01690   /// Destructor.
01691   virtual ~ACE_WIN32_Asynch_Read_Dgram (void);
01692 
01693    /** This starts off an asynchronous read.  Upto
01694    * <message_block->total_size()> will be read and stored in the
01695    * @a message_block.  @a message_block's <wr_ptr> will be updated to reflect
01696    * the added bytes if the read operation is successfully completed.
01697    * Return code of 1 means immediate success and <number_of_bytes_recvd>
01698    * will contain number of bytes read.  The <ACE_Handler::handle_read_dgram>
01699    * method will still be called.  Return code of 0 means the IO will
01700    * complete proactively.  Return code of -1 means there was an error, use
01701    * errno to get the error code.
01702    *
01703    * Scatter/gather is supported on WIN32 by using the <message_block->cont()>
01704    * method.  Up to ACE_IOV_MAX @a message_block's are supported.  Upto
01705    * <message_block->size()> bytes will be read into each <message block> for
01706    * a total of <message_block->total_size()> bytes.  All @a message_block's
01707    * <wr_ptr>'s will be updated to reflect the added bytes for each
01708    * @a message_block
01709    */
01710   virtual ssize_t recv (ACE_Message_Block *message_block,
01711                         size_t &number_of_bytes_recvd,
01712                         int flags,
01713                         int protocol_family,
01714                         const void *act,
01715                         int priority,
01716                         int signal_number);
01717 
01718   // Methods belong to ACE_WIN32_Asynch_Operation base class. These
01719   // methods are defined here to avoid VC++ warnings. They route the
01720   // call to the ACE_WIN32_Asynch_Operation base class.
01721 
01722   /**
01723    * Initializes the factory with information which will be used with
01724    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
01725    * <ACE_Handler::handle> will be called on the @a handler to get the
01726    * correct handle.
01727    */
01728   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
01729             ACE_HANDLE handle,
01730             const void *completion_key,
01731             ACE_Proactor *proactor);
01732 
01733   /**
01734    * This cancels all pending accepts operations that were issued by
01735    * the calling thread.  The function does not cancel asynchronous
01736    * operations issued by other threads.
01737    */
01738   int cancel (void);
01739 
01740   /// Return the underlying proactor.
01741   ACE_Proactor* proactor (void) const;
01742 
01743 protected:
01744   /// Do-nothing constructor.
01745   ACE_WIN32_Asynch_Read_Dgram (void);
01746 };
01747 
01748 /**
01749  * @class ACE_WIN32_Asynch_Write_Dgram_Result
01750  *
01751  * @brief This class provides concrete implementation for
01752  *    ACE_Asynch_Write_Dgram::Result class.
01753  */
01754 class ACE_Export ACE_WIN32_Asynch_Write_Dgram_Result : public virtual ACE_Asynch_Write_Dgram_Result_Impl,
01755                                                        public ACE_WIN32_Asynch_Result
01756 {
01757   /// Factory class willl have special permissions.
01758   friend class ACE_WIN32_Asynch_Write_Dgram;
01759 
01760   /// Proactor class has special permission.
01761   friend class ACE_WIN32_Proactor;
01762 
01763 public:
01764   /// The number of bytes which were requested at the start of the
01765   /// asynchronous write.
01766   size_t bytes_to_write (void) const;
01767 
01768   /// Message block which contains the sent data
01769   ACE_Message_Block *message_block (void) const;
01770 
01771   /// The flags using in the write
01772   int flags (void) const;
01773 
01774   /// I/O handle used for writing.
01775   ACE_HANDLE handle (void) const;
01776 
01777   // = Base class operations. These operations are here to kill some
01778   //   warnings. These methods call the base class methods.
01779 
01780   /// Number of bytes transferred by the operation.
01781   size_t bytes_transferred (void) const;
01782 
01783   /// ACT associated with the operation.
01784   const void *act (void) const;
01785 
01786   /// Did the operation succeed?
01787   int success (void) const;
01788 
01789   /**
01790    * This returns the ACT associated with the handle when it was
01791    * registered with the I/O completion port.  This ACT is not the
01792    * same as the ACT associated with the asynchronous operation.
01793    */
01794   const void *completion_key (void) const;
01795 
01796   /// Error value if the operation fail.
01797   u_long error (void) const;
01798 
01799   /// Event associated with the OVERLAPPED structure.
01800   ACE_HANDLE event (void) const;
01801 
01802   /// This really make sense only when doing file I/O.
01803   u_long offset (void) const;
01804 
01805   /// Offset_high associated with the OVERLAPPED structure.
01806   u_long offset_high (void) const;
01807 
01808   /// The priority of the asynchronous operation. Currently, this is
01809   /// not supported on Win32.
01810   int priority (void) const;
01811 
01812   /// No-op. Returns 0.
01813   int signal_number (void) const;
01814 
01815   /// Post @c this to the Proactor's completion port.
01816   int post_completion (ACE_Proactor_Impl *proactor);
01817 
01818 protected:
01819   /// Constructor is protected since creation is limited to
01820   /// ACE_Asynch_Write_Stream factory.
01821   ACE_WIN32_Asynch_Write_Dgram_Result (const ACE_Handler::Proxy_Ptr &handler_proxy,
01822                                        ACE_HANDLE handle,
01823                                        ACE_Message_Block *message_block,
01824                                        size_t bytes_to_write,
01825                                        int flags,
01826                                        const void* act,
01827                                        ACE_HANDLE event,
01828                                        int priority,
01829                                        int signal_number = 0);
01830 
01831   /// ACE_Proactor will call this method when the write completes.
01832   virtual void complete (size_t bytes_transferred,
01833                          int success,
01834                          const void *completion_key,
01835                          u_long error);
01836 
01837   /// Destructor.
01838   virtual ~ACE_WIN32_Asynch_Write_Dgram_Result (void);
01839 
01840   /// The number of bytes which were requested at the start of the
01841   /// asynchronous write.
01842   size_t bytes_to_write_;
01843 
01844   /// Message block used for the send.
01845   ACE_Message_Block *message_block_;
01846 
01847   /// The flags using in the write
01848   int flags_;
01849 
01850   /// I/O handle used for writing.
01851   ACE_HANDLE handle_;
01852 };
01853 
01854 /**
01855  * @class ACE_WIN32_Asynch_Write_Dgram
01856  *
01857  * @brief This class is a factory for starting off asynchronous writes
01858  *    on a UDP socket.
01859  *
01860  *
01861  *     Once <open> is called, multiple asynchronous <writes>s can
01862  *     started using this class.  A ACE_Asynch_Write_Stream::Result
01863  *     will be passed back to the @a handler when the asynchronous
01864  *     write completes through the
01865  *     <ACE_Handler::handle_write_stream> callback.
01866  */
01867 class ACE_Export ACE_WIN32_Asynch_Write_Dgram : public virtual ACE_Asynch_Write_Dgram_Impl,
01868                                                 public ACE_WIN32_Asynch_Operation
01869 {
01870 public:
01871   /// Constructor.
01872   ACE_WIN32_Asynch_Write_Dgram (ACE_WIN32_Proactor *win32_proactor);
01873 
01874   /// Destructor.
01875   virtual ~ACE_WIN32_Asynch_Write_Dgram (void);
01876 
01877   /** This starts off an asynchronous send.  Upto
01878    * <message_block->total_length()> will be sent.  @a message_block's
01879    * <rd_ptr> will be updated to reflect the sent bytes if the send operation
01880    * is successfully completed.
01881    * Return code of 1 means immediate success and <number_of_bytes_sent>
01882    * is updated to number of bytes sent.  The <ACE_Handler::handle_write_dgram>
01883    * method will still be called.  Return code of 0 means the IO will
01884    * complete proactively.  Return code of -1 means there was an error, use
01885    * errno to get the error code.
01886    *
01887    * Scatter/gather is supported on WIN32 by using the <message_block->cont()>
01888    * method.  Up to ACE_IOV_MAX @a message_block's are supported.  Upto
01889    * <message_block->length()> bytes will be sent from each <message block>
01890    * for a total of <message_block->total_length()> bytes.  All
01891    * @a message_block's <rd_ptr>'s will be updated to reflect the bytes sent
01892    * from each @a message_block.
01893    */
01894   virtual ssize_t send (ACE_Message_Block *message_block,
01895                         size_t &number_of_bytes_sent,
01896                         int flags,
01897                         const ACE_Addr &addr,
01898                         const void *act,
01899                         int priority,
01900                         int signal_number);
01901 
01902   // = Methods belonging to <ACE_WIN32_Asynch_Operation> base class.
01903 
01904   // These methods are defined here to avoid VC++ warnings. They route
01905   // the call to the <ACE_WIN32_Asynch_Operation> base class.
01906 
01907   /**
01908    * Initializes the factory with information which will be used with
01909    * each asynchronous call.  If (<handle> == ACE_INVALID_HANDLE),
01910    * <ACE_Handler::handle> will be called on the @a handler to get the
01911    * correct handle.
01912    */
01913   int open (const ACE_Handler::Proxy_Ptr &handler_proxy,
01914             ACE_HANDLE handle,
01915             const void *completion_key,
01916             ACE_Proactor *proactor);
01917 
01918   /**
01919    * This cancels all pending accepts operations that were issued by
01920    * the calling thread.  The function does not cancel asynchronous
01921    * operations issued by other threads.
01922    */
01923   int cancel (void);
01924 
01925   /// Return the underlying proactor.
01926   ACE_Proactor* proactor (void) const;
01927 
01928 protected:
01929   /// Do-nothing constructor.
01930   ACE_WIN32_Asynch_Write_Dgram (void);
01931 };
01932 
01933 ACE_END_VERSIONED_NAMESPACE_DECL
01934 
01935 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO && ACE_HAS_WINSOCK2 */
01936 #include /**/ "ace/post.h"
01937 #endif /* ACE_WIN32_ASYNCH_IO_H */

Generated on Tue Feb 2 17:18:44 2010 for ACE by  doxygen 1.4.7