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 Member Functions

 ACE_WIN32_Asynch_Read_File (ACE_WIN32_Proactor *win32_proactor)
 Constructor.

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.

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


Private Member Functions

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 is called, multiple asynchronous s can started using this class. A ACE_Asynch_Read_File::Result will be passed back to the 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 670 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 1240 of file WIN32_Asynch_IO.cpp.

01241   : ACE_Asynch_Operation_Impl (),
01242     ACE_Asynch_Read_Stream_Impl (),
01243     ACE_Asynch_Read_File_Impl (),
01244     ACE_WIN32_Asynch_Read_Stream (win32_proactor)
01245 {
01246 }

ACE_WIN32_Asynch_Read_File::~ACE_WIN32_Asynch_Read_File void   )  [virtual]
 

Destructor.

Definition at line 1408 of file WIN32_Asynch_IO.cpp.

01409 {
01410 }


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 1457 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::cancel().

01458 {
01459   return ACE_WIN32_Asynch_Operation::cancel ();
01460 }

int ACE_WIN32_Asynch_Read_File::open const ACE_Handler::Proxy_Ptr handler_proxy,
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 ( == ACE_INVALID_HANDLE), <ACE_Handler::handle> will be called on the to get the correct handle.

Reimplemented from ACE_WIN32_Asynch_Read_Stream.

Definition at line 1445 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::open(), and ACE_Handler::Proxy_Ptr.

01449 {
01450   return ACE_WIN32_Asynch_Operation::open (handler_proxy,
01451                                            handle,
01452                                            completion_key,
01453                                            proactor);
01454 }

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 1463 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::proactor().

01464 {
01465   return ACE_WIN32_Asynch_Operation::proactor ();
01466 }

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 1413 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Read_Stream::read().

01418 {
01419   return ACE_WIN32_Asynch_Read_Stream::read (message_block,
01420                                              bytes_to_read,
01421                                              act,
01422                                              priority,
01423                                              signal_number);
01424 }

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 will be read and stored in the . The read will start at from the beginning of the file.

Implements ACE_Asynch_Read_File_Impl.

Definition at line 1249 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(), and ACE_Message_Block::space().

01256 {
01257   size_t space = message_block.space ();
01258   if ( bytes_to_read > space )
01259     bytes_to_read = space;
01260 
01261   if ( bytes_to_read == 0 )
01262     ACE_ERROR_RETURN
01263       ((LM_ERROR,
01264         ACE_LIB_TEXT ("ACE_WIN32_Asynch_Read_File::read:")
01265         ACE_LIB_TEXT ("Attempt to read 0 bytes or no space in the message block\n")),
01266        -1);
01267 
01268 
01269   ACE_WIN32_Asynch_Read_File_Result *result = 0;
01270   ACE_NEW_RETURN (result,
01271                   ACE_WIN32_Asynch_Read_File_Result (this->handler_proxy_,
01272                                                      this->handle_,
01273                                                      message_block,
01274                                                      bytes_to_read,
01275                                                      act,
01276                                                      offset,
01277                                                      offset_high,
01278                                                      this->win32_proactor_->get_handle (),
01279                                                      priority,
01280                                                      signal_number),
01281                   -1);
01282 
01283   // Shared read
01284   int return_val = this->shared_read (result);
01285 
01286   // Upon errors
01287   if (return_val == -1)
01288     delete result;
01289 
01290   return return_val;
01291 }

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 1427 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Read_Stream::readv().

01432 {
01433   return ACE_WIN32_Asynch_Read_Stream::readv (message_block,
01434                                               bytes_to_read,
01435                                               act,
01436                                               priority,
01437                                               signal_number);
01438 }

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 1294 of file WIN32_Asynch_IO.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_IOV_MAX, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_NOTSUP_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().

01301 {
01302 #if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))
01303   static const size_t page_size = ACE_OS::getpagesize();
01304 
01305   FILE_SEGMENT_ELEMENT buffer_pointers[ACE_IOV_MAX + 1];
01306   int buffer_pointers_count = 0;
01307 
01308   // Each buffer must be at least the size of a system memory page
01309   // and must be aligned on a system memory page size boundary
01310 
01311   // We should not read more than user requested,
01312   // but it is allowed to read less
01313 
01314   size_t total_space = 0;
01315 
01316   for (const ACE_Message_Block* msg = &message_block;
01317        msg != 0 && buffer_pointers_count < ACE_IOV_MAX && total_space < bytes_to_read;
01318        msg = msg->cont(), ++buffer_pointers_count )
01319   {
01320     size_t msg_space = msg->space ();
01321 
01322     if (msg_space < page_size)
01323       ACE_ERROR_RETURN ((LM_ERROR,
01324                          ACE_LIB_TEXT ("ACE_WIN32_Asynch_Read_File::readv:")
01325                          ACE_LIB_TEXT ("Invalid message block size\n")),
01326                         -1);
01327 
01328     buffer_pointers[buffer_pointers_count].Buffer = msg->wr_ptr ();
01329     total_space += page_size;
01330   }
01331 
01332   // not read more than buffers space
01333   if (bytes_to_read > total_space)
01334     bytes_to_read = total_space;
01335 
01336   // ReadFileScatter API limits us to DWORD range.
01337   if (bytes_to_read > MAXDWORD)
01338     {
01339       errno = ERANGE;
01340       return -1;
01341     }
01342   DWORD dword_bytes_to_read = static_cast<DWORD> (bytes_to_read);
01343 
01344   // last one should be completely 0
01345   buffer_pointers[buffer_pointers_count].Buffer = 0;
01346 
01347   ACE_WIN32_Asynch_Read_File_Result *result = 0;
01348   ACE_NEW_RETURN (result,
01349                   ACE_WIN32_Asynch_Read_File_Result (this->handler_proxy_,
01350                                                      this->handle_,
01351                                                      message_block,
01352                                                      bytes_to_read,
01353                                                      act,
01354                                                      offset,
01355                                                      offset_high,
01356                                                      this->win32_proactor_->get_handle (),
01357                                                      priority,
01358                                                      signal_number,
01359                                                      1), // scatter read enabled
01360                   -1);
01361 
01362   // do the scatter read
01363   result->set_error (0); // Clear error before starting IO.
01364 
01365   int initiate_result = ::ReadFileScatter (result->handle (),
01366                                            buffer_pointers,
01367                                            dword_bytes_to_read,
01368                                            0, // reserved, must be NULL
01369                                            result);
01370 
01371   if (0 != initiate_result)
01372     // Immediate success: the OVERLAPPED will still get queued.
01373     return 1;
01374 
01375   // If initiate failed, check for a bad error.
01376   ACE_OS::set_errno_to_last_error ();
01377   switch (errno)
01378   {
01379     case ERROR_IO_PENDING:
01380       // The IO will complete proactively: the OVERLAPPED will still
01381       // get queued.
01382       initiate_result = 0;
01383       break;
01384 
01385     default:
01386       // Something else went wrong: the OVERLAPPED will not get
01387       // queued.
01388 
01389       if (ACE::debug ())
01390       {
01391         ACE_DEBUG ((LM_ERROR,
01392                     ACE_LIB_TEXT ("%p\n"),
01393                     ACE_LIB_TEXT ("ReadFileScatter")));
01394       }
01395 
01396       delete result;
01397       initiate_result = -1;
01398       break;
01399   }
01400 
01401   return initiate_result;
01402 #else /*#if ( (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/
01403   ACE_NOTSUP_RETURN (-1);
01404 #endif /*#if ( (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/
01405 }


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:32:56 2006 for ACE by doxygen 1.3.6