#include <WIN32_Asynch_IO.h>
Inheritance diagram for ACE_WIN32_Asynch_Write_File:
Public Member Functions | |
ACE_WIN32_Asynch_Write_File (ACE_WIN32_Proactor *win32_proactor) | |
Constructor. | |
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. | |
int | open (const ACE_Handler::Proxy_Ptr &handler_proxy, ACE_HANDLE handle, const void *completion_key, ACE_Proactor *proactor) |
int | cancel (void) |
ACE_Proactor * | proactor (void) const |
Return the underlying proactor. | |
Private Member Functions | |
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) |
Once is called, multiple asynchronous s can be started using this class. A ACE_Asynch_Write_File::Result will be passed back to the when the asynchronous writes completes through the <ACE_Handler::handle_write_file> callback.
Definition at line 878 of file WIN32_Asynch_IO.h.
|
Constructor.
Definition at line 1641 of file WIN32_Asynch_IO.cpp.
01642 : ACE_Asynch_Operation_Impl (), 01643 ACE_Asynch_Write_Stream_Impl (), 01644 ACE_Asynch_Write_File_Impl (), 01645 ACE_WIN32_Asynch_Write_Stream (win32_proactor) 01646 { 01647 } |
|
Destrcutor.
Definition at line 1815 of file WIN32_Asynch_IO.cpp.
01816 { 01817 } |
|
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 1864 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Operation::cancel().
01865 { 01866 return ACE_WIN32_Asynch_Operation::cancel (); 01867 } |
|
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_Write_Stream. Definition at line 1852 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Operation::open(), and ACE_Handler::Proxy_Ptr.
01856 { 01857 return ACE_WIN32_Asynch_Operation::open (handler_proxy, 01858 handle, 01859 completion_key, 01860 proactor); 01861 } |
|
Return the underlying proactor.
Reimplemented from ACE_WIN32_Asynch_Write_Stream. Definition at line 1870 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Operation::proactor().
01871 { 01872 return ACE_WIN32_Asynch_Operation::proactor (); 01873 } |
|
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 1820 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Write_Stream::write().
01825 { 01826 return ACE_WIN32_Asynch_Write_Stream::write (message_block, 01827 bytes_to_write, 01828 act, 01829 priority, 01830 signal_number); 01831 } |
|
This starts off an asynchronous write. Upto will be write and stored in the . The write will start at from the beginning of the file. Implements ACE_Asynch_Write_File_Impl. Definition at line 1650 of file WIN32_Asynch_IO.cpp. References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_Message_Block::length(), LM_ERROR, and ACE_WIN32_Asynch_Write_Stream::shared_write().
01657 { 01658 size_t len = message_block.length (); 01659 if ( bytes_to_write > len ) 01660 bytes_to_write = len; 01661 01662 if ( bytes_to_write == 0 ) 01663 ACE_ERROR_RETURN 01664 ((LM_ERROR, 01665 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Write_File::write:") 01666 ACE_LIB_TEXT ("Attempt to read 0 bytes\n")), 01667 -1); 01668 01669 ACE_WIN32_Asynch_Write_File_Result *result = 0; 01670 ACE_NEW_RETURN (result, 01671 ACE_WIN32_Asynch_Write_File_Result (this->handler_proxy_, 01672 this->handle_, 01673 message_block, 01674 bytes_to_write, 01675 act, 01676 offset, 01677 offset_high, 01678 this->win32_proactor_->get_handle (), 01679 priority, 01680 signal_number), 01681 -1); 01682 01683 // Shared write 01684 int return_val = this->shared_write (result); 01685 01686 // Upon errors 01687 if (return_val == -1) 01688 delete result; 01689 01690 return return_val; 01691 } |
|
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 1834 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Write_Stream::writev().
01839 { 01840 return ACE_WIN32_Asynch_Write_Stream::writev (message_block, 01841 bytes_to_write, 01842 act, 01843 priority, 01844 signal_number); 01845 } |
|
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 1694 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::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().
01701 { 01702 #if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) 01703 static const size_t page_size = ACE_OS::getpagesize(); 01704 01705 FILE_SEGMENT_ELEMENT buffer_pointers[ACE_IOV_MAX + 1]; 01706 int buffer_pointers_count = 0; 01707 01708 // Each buffer must be at least the size of a system memory page 01709 // and must be aligned on a system memory page size boundary 01710 01711 // We should not read more than user requested, 01712 // but it is allowed to read less 01713 01714 size_t total_len = 0; 01715 01716 for (const ACE_Message_Block* msg = &message_block; 01717 msg != 0 && buffer_pointers_count < ACE_IOV_MAX && total_len < bytes_to_write; 01718 msg = msg->cont (), ++buffer_pointers_count ) 01719 { 01720 size_t msg_len = msg->length (); 01721 01722 // Don't allow writing less than page_size, unless 01723 // the size of the message block is big enough (so we don't write from 01724 // memory which does not belong to the message block), and the message 01725 // block is the last in the chain. 01726 if (msg_len < page_size && 01727 (msg->size () - (msg->rd_ptr () - msg->base ()) < page_size || // message block too small 01728 bytes_to_write - total_len > page_size ))// NOT last chunk 01729 ACE_ERROR_RETURN ((LM_ERROR, 01730 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Write_File::writev:") 01731 ACE_LIB_TEXT ("Invalid message block length\n")), 01732 -1); 01733 01734 buffer_pointers[buffer_pointers_count].Buffer = msg->rd_ptr (); 01735 total_len += page_size; 01736 } 01737 01738 // not write more than we have in buffers 01739 if (bytes_to_write > total_len) 01740 bytes_to_write = total_len; 01741 // WriteFileGather API limits us to DWORD range. 01742 if (bytes_to_write > MAXDWORD) 01743 { 01744 errno = ERANGE; 01745 return -1; 01746 } 01747 DWORD dword_bytes_to_write = static_cast<DWORD> (bytes_to_write); 01748 01749 // last one should be completely 0 01750 buffer_pointers[buffer_pointers_count].Buffer = 0; 01751 01752 ACE_WIN32_Asynch_Write_File_Result *result = 0; 01753 ACE_NEW_RETURN (result, 01754 ACE_WIN32_Asynch_Write_File_Result (this->handler_proxy_, 01755 this->handle_, 01756 message_block, 01757 bytes_to_write, 01758 act, 01759 offset, 01760 offset_high, 01761 this->win32_proactor_->get_handle (), 01762 priority, 01763 signal_number, 01764 1), // gather write enabled 01765 -1); 01766 01767 result->set_error(0); 01768 01769 // do the gather write 01770 int initiate_result = ::WriteFileGather (result->handle (), 01771 buffer_pointers, 01772 dword_bytes_to_write, 01773 0, // reserved, must be NULL 01774 result); 01775 01776 if (0 != initiate_result) 01777 // Immediate success: the OVERLAPPED will still get queued. 01778 return 1; 01779 01780 // If initiate failed, check for a bad error. 01781 ACE_OS::set_errno_to_last_error (); 01782 switch (errno) 01783 { 01784 case ERROR_IO_PENDING: 01785 // The IO will complete proactively: the OVERLAPPED will still 01786 // get queued. 01787 initiate_result = 0; 01788 break; 01789 01790 default: 01791 // Something else went wrong: the OVERLAPPED will not get 01792 // queued. 01793 01794 if (ACE::debug ()) 01795 { 01796 ACE_DEBUG ((LM_ERROR, 01797 ACE_LIB_TEXT ("%p\n"), 01798 ACE_LIB_TEXT ("WriteFileGather"))); 01799 } 01800 01801 delete result; 01802 initiate_result = -1; 01803 break; 01804 } 01805 01806 return initiate_result; 01807 #else /*#if ((ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0))*/ 01808 01809 ACE_NOTSUP_RETURN (-1); 01810 01811 #endif /* */ 01812 } |