找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 6429|回复: 2

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

[复制链接]
发表于 2011-4-12 09:05:55 | 显示全部楼层 |阅读模式
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;
    }
}
发表于 2011-4-12 11:13:02 | 显示全部楼层
#if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
查代码的定义。
 楼主| 发表于 2011-4-12 14:30:42 | 显示全部楼层
已经搞定了。重造一个类似的share_write函数,然后重新编译ACE
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-5 19:01 , Processed in 0.015305 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表