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

ACE_WIN32_Asynch_Write_File Class Reference

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

#include <WIN32_Asynch_IO.h>

Inheritance diagram for ACE_WIN32_Asynch_Write_File:

Inheritance graph
[legend]
Collaboration diagram for ACE_WIN32_Asynch_Write_File:

Collaboration graph
[legend]
List of all members.

Public Methods

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

int write (ACE_Message_Block &message_block, size_t bytes_to_write, u_long offset, u_long offset_high, const void *act, int priority, int signal_number=0)
int writev (ACE_Message_Block &message_block, size_t bytes_to_write, u_long offset, u_long offset_high, const void *act, int priority, int signal_number=0)
virtual ~ACE_WIN32_Asynch_Write_File (void)
 Destrcutor. 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 write (ACE_Message_Block &message_block, size_t bytes_to_write, const void *act, int priority, int signal_number=0)
int writev (ACE_Message_Block &message_block, size_t bytes_to_write, const void *act, int priority, int signal_number=0)

Detailed Description

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

Once <open> is called, multiple asynchronous <write>s can be started using this class. A ACE_Asynch_Write_File::Result will be passed back to the <handler> when the asynchronous writes completes through the <ACE_Handler::handle_write_file> callback.

Definition at line 876 of file WIN32_Asynch_IO.h.


Constructor & Destructor Documentation

ACE_WIN32_Asynch_Write_File::ACE_WIN32_Asynch_Write_File ACE_WIN32_Proactor   win32_proactor
 

Constructor.

Definition at line 1598 of file WIN32_Asynch_IO.cpp.

01599   : ACE_Asynch_Operation_Impl (),
01600     ACE_Asynch_Write_Stream_Impl (),
01601     ACE_Asynch_Write_File_Impl (),
01602     ACE_WIN32_Asynch_Write_Stream (win32_proactor)
01603 {
01604 }

ACE_WIN32_Asynch_Write_File::~ACE_WIN32_Asynch_Write_File void    [virtual]
 

Destrcutor.

Definition at line 1772 of file WIN32_Asynch_IO.cpp.

01773 {
01774 }


Member Function Documentation

int ACE_WIN32_Asynch_Write_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_Write_Stream.

Definition at line 1821 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::cancel.

01822 {
01823   return ACE_WIN32_Asynch_Operation::cancel ();
01824 }

int ACE_WIN32_Asynch_Write_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_Write_Stream.

Definition at line 1809 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::open.

01813 {
01814   return ACE_WIN32_Asynch_Operation::open (handler,
01815                                            handle,
01816                                            completion_key,
01817                                            proactor);
01818 }

ACE_Proactor * ACE_WIN32_Asynch_Write_File::proactor void    const [virtual]
 

Return the underlying proactor.

Reimplemented from ACE_WIN32_Asynch_Write_Stream.

Definition at line 1827 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::proactor.

01828 {
01829   return ACE_WIN32_Asynch_Operation::proactor ();
01830 }

int ACE_WIN32_Asynch_Write_File::write ACE_Message_Block   message_block,
size_t    bytes_to_write,
const void *    act,
int    priority,
int    signal_number = 0
[private, virtual]
 

This method belongs to ACE_WIN32_Asynch_Write_Stream. It is here to avoid compiler warnings. This method is forwarded to the ACE_WIN32_Asynch_Write_Stream class.

Implements ACE_Asynch_Write_File_Impl.

Definition at line 1777 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Write_Stream::write.

01782 {
01783   return ACE_WIN32_Asynch_Write_Stream::write (message_block,
01784                                                bytes_to_write,
01785                                                act,
01786                                                priority,
01787                                                signal_number);
01788 }

int ACE_WIN32_Asynch_Write_File::write ACE_Message_Block   message_block,
size_t    bytes_to_write,
u_long    offset,
u_long    offset_high,
const void *    act,
int    priority,
int    signal_number = 0
[virtual]
 

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

Implements ACE_Asynch_Write_File_Impl.

Definition at line 1607 of file WIN32_Asynch_IO.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_Message_Block::length, LM_ERROR, ACE_WIN32_Asynch_Write_Stream::shared_write, and ssize_t.

01614 {
01615   size_t len = message_block.length ();
01616   if ( bytes_to_write > len )
01617      bytes_to_write = len;
01618 
01619   if ( bytes_to_write == 0 )
01620     ACE_ERROR_RETURN
01621       ((LM_ERROR,
01622         ACE_LIB_TEXT ("ACE_WIN32_Asynch_Write_File::write:")
01623         ACE_LIB_TEXT ("Attempt to read 0 bytes\n")),
01624        -1);
01625 
01626   ACE_WIN32_Asynch_Write_File_Result *result = 0;
01627   ACE_NEW_RETURN (result,
01628                   ACE_WIN32_Asynch_Write_File_Result (*this->handler_,
01629                                                       this->handle_,
01630                                                       message_block,
01631                                                       bytes_to_write,
01632                                                       act,
01633                                                       offset,
01634                                                       offset_high,
01635                                                       this->win32_proactor_->get_handle (),
01636                                                       priority,
01637                                                       signal_number),
01638                   -1);
01639 
01640   // Shared write
01641   ssize_t return_val = this->shared_write (result);
01642 
01643   // Upon errors
01644   if (return_val == -1)
01645     delete result;
01646 
01647   return return_val;
01648 }

int ACE_WIN32_Asynch_Write_File::writev ACE_Message_Block   message_block,
size_t    bytes_to_write,
const void *    act,
int    priority,
int    signal_number = 0
[private, virtual]
 

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

Implements ACE_Asynch_Write_File_Impl.

Definition at line 1791 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Write_Stream::writev.

01796 {
01797   return ACE_WIN32_Asynch_Write_Stream::writev (message_block,
01798                                                 bytes_to_write,
01799                                                 act,
01800                                                 priority,
01801                                                 signal_number);
01802 }

int ACE_WIN32_Asynch_Write_File::writev ACE_Message_Block   message_block,
size_t    bytes_to_write,
u_long    offset,
u_long    offset_high,
const void *    act,
int    priority,
int    signal_number = 0
[virtual]
 

Same as above but with gather 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_Write_File_Impl.

Definition at line 1651 of file WIN32_Asynch_IO.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_IOV_MAX, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_Message_Block::base, ACE_Message_Block::cont, ACE::debug, ACE_OS::getpagesize, ACE_WIN32_Asynch_Write_File_Result::handle, ACE_Message_Block::length, LM_ERROR, ACE_Message_Block::rd_ptr, ACE_OS::set_errno_to_last_error, ACE_WIN32_Asynch_Result::set_error, and ACE_Message_Block::size.

01658 {
01659 #if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))
01660   static const size_t page_size = ACE_OS::getpagesize();
01661 
01662   FILE_SEGMENT_ELEMENT buffer_pointers[ACE_IOV_MAX + 1];
01663   int buffer_pointers_count = 0;
01664 
01665   // Each buffer must be at least the size of a system memory page
01666   // and must be aligned on a system memory page size boundary
01667 
01668   // We should not read more than user requested,
01669   // but it is allowed to read less
01670 
01671   size_t total_len = 0;
01672 
01673   for (const ACE_Message_Block* msg = &message_block;
01674        msg != 0 && buffer_pointers_count < ACE_IOV_MAX && total_len < bytes_to_write;
01675        msg = msg->cont (), ++buffer_pointers_count )
01676   {
01677     size_t msg_len = msg->length ();
01678 
01679     // Don't allow writing less than page_size, unless
01680     // the size of the message block is big enough (so we don't write from
01681     // memory which does not belong to the message block), and the message
01682     // block is the last in the chain.
01683     if (msg_len < page_size &&
01684         (msg->size () - (msg->rd_ptr () - msg->base ()) < page_size || // message block too small
01685          bytes_to_write - total_len > page_size ))// NOT last chunk
01686       ACE_ERROR_RETURN ((LM_ERROR,
01687                          ACE_LIB_TEXT ("ACE_WIN32_Asynch_Write_File::writev:")
01688                          ACE_LIB_TEXT ("Invalid message block length\n")),
01689                         -1);
01690 
01691     buffer_pointers[buffer_pointers_count].Buffer = msg->rd_ptr ();
01692     total_len += page_size;
01693   }
01694 
01695   // not write more than we have in buffers
01696   if (bytes_to_write > total_len)
01697     bytes_to_write = total_len;
01698   // WriteFileGather API limits us to DWORD range.
01699   if (bytes_to_write > MAXDWORD)
01700     {
01701       errno = ERANGE;
01702       return -1;
01703     }
01704   DWORD dword_bytes_to_write = ACE_static_cast (DWORD, bytes_to_write);
01705 
01706   // last one should be completely 0
01707   buffer_pointers[buffer_pointers_count].Buffer = 0;
01708 
01709   ACE_WIN32_Asynch_Write_File_Result *result = 0;
01710   ACE_NEW_RETURN (result,
01711                   ACE_WIN32_Asynch_Write_File_Result (*this->handler_,
01712                                                       this->handle_,
01713                                                       message_block,
01714                                                       bytes_to_write,
01715                                                       act,
01716                                                       offset,
01717                                                       offset_high,
01718                                                       this->win32_proactor_->get_handle (),
01719                                                       priority,
01720                                                       signal_number,
01721                                                       1), // gather write enabled
01722                   -1);
01723 
01724   result->set_error(0);
01725 
01726   // do the gather write
01727   int initiate_result = ::WriteFileGather (result->handle (),
01728                                            buffer_pointers,
01729                                            dword_bytes_to_write,
01730                                            0, // reserved, must be NULL
01731                                            result);
01732 
01733   if (0 != initiate_result)
01734     // Immediate success: the OVERLAPPED will still get queued.
01735     return 1;
01736 
01737   // If initiate failed, check for a bad error.
01738   ACE_OS::set_errno_to_last_error ();
01739   switch (errno)
01740   {
01741     case ERROR_IO_PENDING:
01742       // The IO will complete proactively: the OVERLAPPED will still
01743       // get queued.
01744       initiate_result = 0;
01745       break;
01746 
01747     default:
01748       // Something else went wrong: the OVERLAPPED will not get
01749       // queued.
01750 
01751       if (ACE::debug ())
01752       {
01753         ACE_DEBUG ((LM_ERROR,
01754                     ACE_LIB_TEXT ("%p\n"),
01755                     ACE_LIB_TEXT ("WriteFileGather")));
01756       }
01757 
01758       delete result;
01759       initiate_result = -1;
01760       break;
01761   }
01762 
01763   return initiate_result;
01764 #else /*#if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/
01765 
01766   ACE_NOTSUP_RETURN (-1);
01767 
01768 #endif /* */
01769 }


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