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