Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_WIN32_Asynch_Read_File Class Reference

This class is a factory for starting off asynchronous reads on a file. More...

#include <WIN32_Asynch_IO.h>

Inheritance diagram for ACE_WIN32_Asynch_Read_File:

Inheritance graph
[legend]
Collaboration diagram for ACE_WIN32_Asynch_Read_File:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_WIN32_Asynch_Read_File (ACE_WIN32_Proactor *win32_proactor)
 Constructor. More...

int read (ACE_Message_Block &message_block, size_t bytes_to_read, u_long offset, u_long offset_high, const void *act, int priority, int signal_number=0)
int readv (ACE_Message_Block &message_block, size_t bytes_to_read, u_long offset, u_long offset_high, const void *act, int priority, int signal_number=0)
virtual ~ACE_WIN32_Asynch_Read_File (void)
 Destructor. More...

int open (ACE_Handler &handler, ACE_HANDLE handle, const void *completion_key, ACE_Proactor *proactor)
int cancel (void)
ACE_Proactorproactor (void) const
 Return the underlying proactor. More...


Private Methods

int read (ACE_Message_Block &message_block, size_t bytes_to_read, const void *act, int priority, int signal_number=0)
int readv (ACE_Message_Block &message_block, size_t bytes_to_read, const void *act, int priority, int signal_number=0)

Detailed Description

This class is a factory for starting off asynchronous reads on a file.

Once <open> is called, multiple asynchronous <read>s can started using this class. A ACE_Asynch_Read_File::Result will be passed back to the <handler> when the asynchronous reads completes through the <ACE_Handler::handle_read_file> callback.

This class differs slightly from ACE_Asynch_Read_Stream as it allows the user to specify an offset for the read.

Definition at line 668 of file WIN32_Asynch_IO.h.


Constructor & Destructor Documentation

ACE_WIN32_Asynch_Read_File::ACE_WIN32_Asynch_Read_File ACE_WIN32_Proactor   win32_proactor
 

Constructor.

Definition at line 1200 of file WIN32_Asynch_IO.cpp.

01201   : ACE_Asynch_Operation_Impl (),
01202     ACE_Asynch_Read_Stream_Impl (),
01203     ACE_Asynch_Read_File_Impl (),
01204     ACE_WIN32_Asynch_Read_Stream (win32_proactor)
01205 {
01206 }

ACE_WIN32_Asynch_Read_File::~ACE_WIN32_Asynch_Read_File void    [virtual]
 

Destructor.

Definition at line 1368 of file WIN32_Asynch_IO.cpp.

01369 {
01370 }


Member Function Documentation

int ACE_WIN32_Asynch_Read_File::cancel void    [virtual]
 

This cancels all pending accepts operations that were issued by the calling thread. The function does not cancel asynchronous operations issued by other threads.

Reimplemented from ACE_WIN32_Asynch_Read_Stream.

Definition at line 1417 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::cancel.

01418 {
01419   return ACE_WIN32_Asynch_Operation::cancel ();
01420 }

int ACE_WIN32_Asynch_Read_File::open ACE_Handler   handler,
ACE_HANDLE    handle,
const void *    completion_key,
ACE_Proactor   proactor
[virtual]
 

Initializes the factory with information which will be used with each asynchronous call. If (<handle> == ACE_INVALID_HANDLE), <ACE_Handler::handle> will be called on the <handler> to get the correct handle.

Reimplemented from ACE_WIN32_Asynch_Read_Stream.

Definition at line 1405 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::open.

01409 {
01410   return ACE_WIN32_Asynch_Operation::open (handler,
01411                                            handle,
01412                                            completion_key,
01413                                            proactor);
01414 }

ACE_Proactor * ACE_WIN32_Asynch_Read_File::proactor void    const [virtual]
 

Return the underlying proactor.

Reimplemented from ACE_WIN32_Asynch_Read_Stream.

Definition at line 1423 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::proactor.

01424 {
01425   return ACE_WIN32_Asynch_Operation::proactor ();
01426 }

int ACE_WIN32_Asynch_Read_File::read ACE_Message_Block   message_block,
size_t    bytes_to_read,
const void *    act,
int    priority,
int    signal_number = 0
[private, virtual]
 

This method belongs to ACE_WIN32_Asynch_Read_Stream. It is here to avoid the compiler warnings. We forward this call to the ACE_WIN32_Asynch_Read_Stream class.

Implements ACE_Asynch_Read_File_Impl.

Definition at line 1373 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Read_Stream::read.

01378 {
01379   return ACE_WIN32_Asynch_Read_Stream::read (message_block,
01380                                              bytes_to_read,
01381                                              act,
01382                                              priority,
01383                                              signal_number);
01384 }

int ACE_WIN32_Asynch_Read_File::read ACE_Message_Block   message_block,
size_t    bytes_to_read,
u_long    offset,
u_long    offset_high,
const void *    act,
int    priority,
int    signal_number = 0
[virtual]
 

This starts off an asynchronous read. Upto <bytes_to_read> will be read and stored in the <message_block>. The read will start at <offset> from the beginning of the file.

Implements ACE_Asynch_Read_File_Impl.

Definition at line 1209 of file WIN32_Asynch_IO.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, LM_ERROR, ACE_WIN32_Asynch_Read_Stream::shared_read, ACE_Message_Block::space, and ssize_t.

01216 {
01217   size_t space = message_block.space ();
01218   if ( bytes_to_read > space )
01219     bytes_to_read = space;
01220 
01221   if ( bytes_to_read == 0 )
01222     ACE_ERROR_RETURN
01223       ((LM_ERROR,
01224         ACE_LIB_TEXT ("ACE_WIN32_Asynch_Read_File::read:")
01225         ACE_LIB_TEXT ("Attempt to read 0 bytes or no space in the message block\n")),
01226        -1);
01227 
01228 
01229   ACE_WIN32_Asynch_Read_File_Result *result = 0;
01230   ACE_NEW_RETURN (result,
01231                   ACE_WIN32_Asynch_Read_File_Result (*this->handler_,
01232                                                      this->handle_,
01233                                                      message_block,
01234                                                      bytes_to_read,
01235                                                      act,
01236                                                      offset,
01237                                                      offset_high,
01238                                                      this->win32_proactor_->get_handle (),
01239                                                      priority,
01240                                                      signal_number),
01241                   -1);
01242 
01243   // Shared read
01244   ssize_t return_val = this->shared_read (result);
01245 
01246   // Upon errors
01247   if (return_val == -1)
01248     delete result;
01249 
01250   return return_val;
01251 }

int ACE_WIN32_Asynch_Read_File::readv ACE_Message_Block   message_block,
size_t    bytes_to_read,
const void *    act,
int    priority,
int    signal_number = 0
[private, virtual]
 

Same as above but with scatter support, through chaining of composite message blocks using the continuation field.

Implements ACE_Asynch_Read_File_Impl.

Definition at line 1387 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Read_Stream::readv.

01392 {
01393   return ACE_WIN32_Asynch_Read_Stream::readv (message_block,
01394                                               bytes_to_read,
01395                                               act,
01396                                               priority,
01397                                               signal_number);
01398 }

int ACE_WIN32_Asynch_Read_File::readv ACE_Message_Block   message_block,
size_t    bytes_to_read,
u_long    offset,
u_long    offset_high,
const void *    act,
int    priority,
int    signal_number = 0
[virtual]
 

Same as above but with scatter support, through chaining of composite message blocks using the continuation field. NOTE: Each data block payload must be at least the size of a system memory page and must be aligned on a system memory page size boundary

Implements ACE_Asynch_Read_File_Impl.

Definition at line 1254 of file WIN32_Asynch_IO.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_IOV_MAX, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_Message_Block::cont, ACE::debug, ACE_OS::getpagesize, ACE_WIN32_Asynch_Read_File_Result::handle, LM_ERROR, ACE_OS::set_errno_to_last_error, ACE_WIN32_Asynch_Result::set_error, ACE_Message_Block::space, and ACE_Message_Block::wr_ptr.

01261 {
01262 #if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))
01263   static const size_t page_size = ACE_OS::getpagesize();
01264 
01265   FILE_SEGMENT_ELEMENT buffer_pointers[ACE_IOV_MAX + 1];
01266   int buffer_pointers_count = 0;
01267 
01268   // Each buffer must be at least the size of a system memory page
01269   // and must be aligned on a system memory page size boundary
01270 
01271   // We should not read more than user requested,
01272   // but it is allowed to read less
01273 
01274   size_t total_space = 0;
01275 
01276   for (const ACE_Message_Block* msg = &message_block;
01277        msg != 0 && buffer_pointers_count < ACE_IOV_MAX && total_space < bytes_to_read;
01278        msg = msg->cont(), ++buffer_pointers_count )
01279   {
01280     size_t msg_space = msg->space ();
01281 
01282     if (msg_space < page_size)
01283       ACE_ERROR_RETURN ((LM_ERROR,
01284                          ACE_LIB_TEXT ("ACE_WIN32_Asynch_Read_File::readv:")
01285                          ACE_LIB_TEXT ("Invalid message block size\n")),
01286                         -1);
01287 
01288     buffer_pointers[buffer_pointers_count].Buffer = msg->wr_ptr ();
01289     total_space += page_size;
01290   }
01291 
01292   // not read more than buffers space
01293   if (bytes_to_read > total_space)
01294     bytes_to_read = total_space;
01295 
01296   // ReadFileScatter API limits us to DWORD range.
01297   if (bytes_to_read > MAXDWORD)
01298     {
01299       errno = ERANGE;
01300       return -1;
01301     }
01302   DWORD dword_bytes_to_read = ACE_static_cast (DWORD, bytes_to_read);
01303 
01304   // last one should be completely 0
01305   buffer_pointers[buffer_pointers_count].Buffer = 0;
01306 
01307   ACE_WIN32_Asynch_Read_File_Result *result = 0;
01308   ACE_NEW_RETURN (result,
01309                   ACE_WIN32_Asynch_Read_File_Result (*this->handler_,
01310                                                      this->handle_,
01311                                                      message_block,
01312                                                      bytes_to_read,
01313                                                      act,
01314                                                      offset,
01315                                                      offset_high,
01316                                                      this->win32_proactor_->get_handle (),
01317                                                      priority,
01318                                                      signal_number,
01319                                                      1), // scatter read enabled
01320                   -1);
01321 
01322   // do the scatter read
01323   result->set_error (0); // Clear error before starting IO.
01324 
01325   int initiate_result = ::ReadFileScatter (result->handle (),
01326                                            buffer_pointers,
01327                                            dword_bytes_to_read,
01328                                            0, // reserved, must be NULL
01329                                            result);
01330 
01331   if (0 != initiate_result)
01332     // Immediate success: the OVERLAPPED will still get queued.
01333     return 1;
01334 
01335   // If initiate failed, check for a bad error.
01336   ACE_OS::set_errno_to_last_error ();
01337   switch (errno)
01338   {
01339     case ERROR_IO_PENDING:
01340       // The IO will complete proactively: the OVERLAPPED will still
01341       // get queued.
01342       initiate_result = 0;
01343       break;
01344 
01345     default:
01346       // Something else went wrong: the OVERLAPPED will not get
01347       // queued.
01348 
01349       if (ACE::debug ())
01350       {
01351         ACE_DEBUG ((LM_ERROR,
01352                     ACE_LIB_TEXT ("%p\n"),
01353                     ACE_LIB_TEXT ("ReadFileScatter")));
01354       }
01355 
01356       delete result;
01357       initiate_result = -1;
01358       break;
01359   }
01360 
01361   return initiate_result;
01362 #else /*#if ( (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/
01363   ACE_NOTSUP_RETURN (-1);
01364 #endif /*#if ( (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/
01365 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 13:00:01 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002