|
发表于 2009-12-3 12:53:27
|
显示全部楼层
增加函数
int ACE_WIN32_Asynch_Write_Stream::shared_write_file (ACE_WIN32_Asynch_Write_Stream_Result *result)
{
u_long bytes_written;
if (result->bytes_to_write () > MAXDWORD)
{
errno = ERANGE;
return -1;
}
DWORD bytes_to_write = static_cast<DWORD> (result->bytes_to_write ());
result->set_error (0); // Clear error before starting IO.
// Initiate the write; Winsock 2 is required for the higher-performing
// WSASend() function. For Winsock 1, fall back to the slower WriteFile().
int initiate_result = 0;
initiate_result = ::WriteFile (result->handle (),
result->message_block ().rd_ptr (),
bytes_to_write,
&bytes_written,
result);
if (initiate_result == 1)
// Immediate success: the OVERLAPPED will still get queued.
return 0;
// If initiate failed, check for a bad error.
ACE_OS::set_errno_to_last_error ();
switch (errno)
{
case ERROR_IO_PENDING:
// The IO will complete proactively: the OVERLAPPED will still
// get queued.
return 0;
default:
// Something else went wrong: the OVERLAPPED will not get
// queued.
if (ACE::debug ())
ACE_DEBUG ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("Initiating write")));
return -1;
}
}
修改下面的函数:
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)
{
size_t len = message_block.length ();
if ( bytes_to_write > len )
bytes_to_write = len;
if ( bytes_to_write == 0 )
ACE_ERROR_RETURN
((LM_ERROR,
ACE_TEXT ("ACE_WIN32_Asynch_Write_File::write:")
ACE_TEXT ("Attempt to read 0 bytes\n")),
-1);
ACE_WIN32_Asynch_Write_File_Result *result = 0;
ACE_NEW_RETURN (result,
ACE_WIN32_Asynch_Write_File_Result (this->handler_proxy_,
this->handle_,
message_block,
bytes_to_write,
act,
offset,
offset_high,
this->win32_proactor_->get_handle (),
priority,
signal_number),
-1);
// Shared write
int return_val = this->shared_write_file (result);
// Upon errors
if (return_val == -1)
delete result;
return return_val;
}
其实现在的磁盘速度很快了,我想直接写磁盘 应该也是可以的,在文件中用异步来管理可能意义不大。再不然推到另一个队列线程来写可能更合适。 |
|