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