| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/win/scoped_handle.h" | 8 #include "base/win/scoped_handle.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 COMPILE_ASSERT(sizeof(buffer[0]) == sizeof(char), incorrect_buffer_type); | 119 COMPILE_ASSERT(sizeof(buffer[0]) == sizeof(char), incorrect_buffer_type); |
| 120 DCHECK_LE(length, kMaxMessageLength); | 120 DCHECK_LE(length, kMaxMessageLength); |
| 121 | 121 |
| 122 OVERLAPPED ol = {0}; | 122 OVERLAPPED ol = {0}; |
| 123 ol.hEvent = io_event->handle(); | 123 ol.hEvent = io_event->handle(); |
| 124 size_t count = 0; | 124 size_t count = 0; |
| 125 while (count < length) { | 125 while (count < length) { |
| 126 DWORD chunk = GetNextChunkSize(count, length); | 126 DWORD chunk = GetNextChunkSize(count, length); |
| 127 // This is either the ReadFile or WriteFile call depending on whether | 127 // This is either the ReadFile or WriteFile call depending on whether |
| 128 // we're receiving or sending data. | 128 // we're receiving or sending data. |
| 129 DWORD len; | 129 DWORD len = 0; |
| 130 BOOL ok = operation(file, static_cast<BufferType*>(buffer) + count, chunk, | 130 BOOL ok = operation(file, static_cast<BufferType*>(buffer) + count, chunk, |
| 131 &len, &ol); | 131 &len, &ol); |
| 132 if (!ok) { | 132 if (!ok) { |
| 133 if (::GetLastError() == ERROR_IO_PENDING) { | 133 if (::GetLastError() == ERROR_IO_PENDING) { |
| 134 base::WaitableEvent* events[] = { io_event, cancel_event }; | 134 base::WaitableEvent* events[] = { io_event, cancel_event }; |
| 135 size_t signaled = WaitableEvent::WaitMany(events, arraysize(events)); | 135 size_t signaled = WaitableEvent::WaitMany(events, arraysize(events)); |
| 136 if (signaled == 1) { | 136 if (signaled == 1) { |
| 137 VLOG(1) << "Shutdown was signaled. Closing socket."; | 137 VLOG(1) << "Shutdown was signaled. Closing socket."; |
| 138 CancelIo(file); |
| 138 socket->Close(); | 139 socket->Close(); |
| 140 count = 0; |
| 139 break; | 141 break; |
| 140 } else { | 142 } else { |
| 141 GetOverlappedResult(file, &ol, &len, TRUE); | 143 GetOverlappedResult(file, &ol, &len, TRUE); |
| 142 } | 144 } |
| 143 } else { | 145 } else { |
| 144 return (0 < count) ? count : 0; | 146 return (0 < count) ? count : 0; |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 count += len; | 149 count += len; |
| 148 } | 150 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 246 } |
| 245 | 247 |
| 246 // static | 248 // static |
| 247 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 249 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
| 248 CancelableSyncSocket* socket_b) { | 250 CancelableSyncSocket* socket_b) { |
| 249 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 251 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
| 250 } | 252 } |
| 251 | 253 |
| 252 | 254 |
| 253 } // namespace base | 255 } // namespace base |
| OLD | NEW |