tengmo535 发表于 2011-4-12 09:05:55

ACE底层的write(),如何使程序运行::WriteFile()代替::WSASend

ACE_WIN32_Asynch_Write_Stream::shared_write (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;
#if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
WSABUF iov;
iov.buf = result->message_block ().rd_ptr ();
iov.len = bytes_to_write;
initiate_result = ::WSASend (reinterpret_cast<SOCKET> (result->handle ()),
                               &iov,
                               1,
                               &bytes_written,
                               0, // flags
                               result,
                               0);
if (initiate_result == 0)
    // Immediate success: the OVERLAPPED will still get queued.
    return 0;
#else                                 
initiate_result = ::WriteFile (result->handle (),//就是程序运行时运行 #else
                                 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;
#endif /* ACE_HAS_WINSOCK2 */

// 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;
    }
}

winston 发表于 2011-4-12 11:13:02

#if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
查代码的定义。

tengmo535 发表于 2011-4-12 14:30:42

已经搞定了。重造一个类似的share_write函数,然后重新编译ACE
页: [1]
查看完整版本: ACE底层的write(),如何使程序运行::WriteFile()代替::WSASend