| Index: base/sync_socket_win.cc
|
| ===================================================================
|
| --- base/sync_socket_win.cc (revision 132887)
|
| +++ base/sync_socket_win.cc (working copy)
|
| @@ -114,8 +114,7 @@
|
| BufferType* buffer, size_t length,
|
| base::WaitableEvent* io_event,
|
| base::WaitableEvent* cancel_event,
|
| - CancelableSyncSocket* socket,
|
| - DWORD timeout_in_ms) {
|
| + CancelableSyncSocket* socket) {
|
| // The buffer must be byte size or the length check won't make much sense.
|
| COMPILE_ASSERT(sizeof(buffer[0]) == sizeof(char), incorrect_buffer_type);
|
| DCHECK_LE(length, kMaxMessageLength);
|
| @@ -132,38 +131,24 @@
|
| &len, &ol);
|
| if (!ok) {
|
| if (::GetLastError() == ERROR_IO_PENDING) {
|
| - HANDLE events[] = { io_event->handle(), cancel_event->handle() };
|
| - int wait_result = WaitForMultipleObjects(
|
| - arraysize(events), events, FALSE, timeout_in_ms);
|
| - if (wait_result == (WAIT_OBJECT_0 + 0)) {
|
| - GetOverlappedResult(file, &ol, &len, TRUE);
|
| - } else if (wait_result == (WAIT_OBJECT_0 + 1)) {
|
| + base::WaitableEvent* events[] = { io_event, cancel_event };
|
| + size_t signaled = WaitableEvent::WaitMany(events, arraysize(events));
|
| + if (signaled == 1) {
|
| VLOG(1) << "Shutdown was signaled. Closing socket.";
|
| CancelIo(file);
|
| socket->Close();
|
| count = 0;
|
| break;
|
| } else {
|
| - // Timeout happened.
|
| - DCHECK_EQ(WAIT_TIMEOUT, wait_result);
|
| - if (!CancelIo(file)){
|
| - DLOG(WARNING) << "CancelIo() failed";
|
| - }
|
| - break;
|
| + GetOverlappedResult(file, &ol, &len, TRUE);
|
| }
|
| } else {
|
| - break;
|
| + return (0 < count) ? count : 0;
|
| }
|
| }
|
| -
|
| count += len;
|
| -
|
| - // Quit the operation if we can't write/read anymore.
|
| - if (len != chunk)
|
| - break;
|
| }
|
| -
|
| - return (count > 0) ? count : 0;
|
| + return count;
|
| }
|
|
|
| } // namespace
|
| @@ -249,16 +234,15 @@
|
| }
|
|
|
| size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
|
| - static const DWORD kWaitTimeOutInMs = 500;
|
| - return CancelableFileOperation(
|
| - &WriteFile, handle_, reinterpret_cast<const char*>(buffer),
|
| - length, &file_operation_, &shutdown_event_, this, kWaitTimeOutInMs);
|
| + return CancelableFileOperation(&WriteFile, handle_,
|
| + reinterpret_cast<const char*>(buffer), length, &file_operation_,
|
| + &shutdown_event_, this);
|
| }
|
|
|
| size_t CancelableSyncSocket::Receive(void* buffer, size_t length) {
|
| return CancelableFileOperation(&ReadFile, handle_,
|
| reinterpret_cast<char*>(buffer), length, &file_operation_,
|
| - &shutdown_event_, this, INFINITE);
|
| + &shutdown_event_, this);
|
| }
|
|
|
| // static
|
|
|