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/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "base/win/scoped_handle.h" | 9 #include "base/win/scoped_handle.h" |
10 | 10 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const DWORD chunk = GetNextChunkSize(count, length); | 143 const DWORD chunk = GetNextChunkSize(count, length); |
144 // This is either the ReadFile or WriteFile call depending on whether | 144 // This is either the ReadFile or WriteFile call depending on whether |
145 // we're receiving or sending data. | 145 // we're receiving or sending data. |
146 DWORD len = 0; | 146 DWORD len = 0; |
147 const BOOL operation_ok = operation( | 147 const BOOL operation_ok = operation( |
148 file, static_cast<BufferType*>(buffer) + count, chunk, &len, &ol); | 148 file, static_cast<BufferType*>(buffer) + count, chunk, &len, &ol); |
149 if (!operation_ok) { | 149 if (!operation_ok) { |
150 if (::GetLastError() == ERROR_IO_PENDING) { | 150 if (::GetLastError() == ERROR_IO_PENDING) { |
151 HANDLE events[] = { io_event->handle(), cancel_event->handle() }; | 151 HANDLE events[] = { io_event->handle(), cancel_event->handle() }; |
152 const int wait_result = WaitForMultipleObjects( | 152 const int wait_result = WaitForMultipleObjects( |
153 ARRAYSIZE_UNSAFE(events), events, FALSE, | 153 arraysize(events), events, FALSE, |
154 timeout_in_ms == INFINITE ? | 154 timeout_in_ms == INFINITE ? |
155 timeout_in_ms : | 155 timeout_in_ms : |
156 static_cast<DWORD>( | 156 static_cast<DWORD>( |
157 (finish_time - current_time).InMilliseconds())); | 157 (finish_time - current_time).InMilliseconds())); |
158 if (wait_result != WAIT_OBJECT_0 + 0) { | 158 if (wait_result != WAIT_OBJECT_0 + 0) { |
159 // CancelIo() doesn't synchronously cancel outstanding IO, only marks | 159 // CancelIo() doesn't synchronously cancel outstanding IO, only marks |
160 // outstanding IO for cancellation. We must call GetOverlappedResult() | 160 // outstanding IO for cancellation. We must call GetOverlappedResult() |
161 // below to ensure in flight writes complete before returning. | 161 // below to ensure in flight writes complete before returning. |
162 CancelIo(file); | 162 CancelIo(file); |
163 } | 163 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 static_cast<DWORD>(timeout.InMilliseconds())); | 333 static_cast<DWORD>(timeout.InMilliseconds())); |
334 } | 334 } |
335 | 335 |
336 // static | 336 // static |
337 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 337 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
338 CancelableSyncSocket* socket_b) { | 338 CancelableSyncSocket* socket_b) { |
339 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 339 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
340 } | 340 } |
341 | 341 |
342 } // namespace base | 342 } // namespace base |
OLD | NEW |