WIN32_Asynch_IO.h

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

Generated on Thu Nov 9 09:42:10 2006 for ACE by doxygen 1.3.6