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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 socket->Close(); | 139 socket->Close(); |
140 count = 0; | 140 count = 0; |
141 break; | 141 break; |
142 } else { | 142 } else { |
143 GetOverlappedResult(file, &ol, &len, TRUE); | 143 GetOverlappedResult(file, &ol, &len, TRUE); |
144 } | 144 } |
145 } else { | 145 } else { |
146 return (0 < count) ? count : 0; | 146 return (0 < count) ? count : 0; |
147 } | 147 } |
148 } | 148 } |
149 | |
150 // Quit the operation if we can't write/read anymore. | |
151 if (len == 0) | |
tommi (sloooow) - chröme
2012/04/13 10:28:10
do we actually hit this?
I would have thought that
no longer working on chromium
2012/04/13 11:50:50
Yes, when the buffer is full, the operation return
| |
152 break; | |
153 | |
149 count += len; | 154 count += len; |
150 } | 155 } |
151 return count; | 156 return count; |
152 } | 157 } |
153 | 158 |
154 } // namespace | 159 } // namespace |
155 | 160 |
156 const SyncSocket::Handle SyncSocket::kInvalidHandle = INVALID_HANDLE_VALUE; | 161 const SyncSocket::Handle SyncSocket::kInvalidHandle = INVALID_HANDLE_VALUE; |
157 | 162 |
158 SyncSocket::SyncSocket() : handle_(kInvalidHandle) {} | 163 SyncSocket::SyncSocket() : handle_(kInvalidHandle) {} |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 return true; | 232 return true; |
228 } | 233 } |
229 | 234 |
230 bool CancelableSyncSocket::Close() { | 235 bool CancelableSyncSocket::Close() { |
231 bool ret = SyncSocket::Close(); | 236 bool ret = SyncSocket::Close(); |
232 shutdown_event_.Reset(); | 237 shutdown_event_.Reset(); |
233 return ret; | 238 return ret; |
234 } | 239 } |
235 | 240 |
236 size_t CancelableSyncSocket::Send(const void* buffer, size_t length) { | 241 size_t CancelableSyncSocket::Send(const void* buffer, size_t length) { |
242 DWORD state = 0; | |
243 if (GetNamedPipeHandleState(handle_, &state, NULL, NULL, NULL, NULL, 0)) { | |
244 // Set the socket to non-blocking mode if it is blocking on sending. | |
245 if ((state & PIPE_NOWAIT) == 0) { | |
246 state = PIPE_NOWAIT; | |
247 SetNamedPipeHandleState(handle_, &state, NULL, NULL); | |
248 } | |
249 } | |
237 return CancelableFileOperation(&WriteFile, handle_, | 250 return CancelableFileOperation(&WriteFile, handle_, |
238 reinterpret_cast<const char*>(buffer), length, &file_operation_, | 251 reinterpret_cast<const char*>(buffer), length, &file_operation_, |
239 &shutdown_event_, this); | 252 &shutdown_event_, this); |
240 } | 253 } |
241 | 254 |
242 size_t CancelableSyncSocket::Receive(void* buffer, size_t length) { | 255 size_t CancelableSyncSocket::Receive(void* buffer, size_t length) { |
256 DWORD state = 0; | |
257 if (GetNamedPipeHandleState(handle_, &state, NULL, NULL, NULL, NULL, 0)) { | |
tommi (sloooow) - chröme
2012/04/13 10:28:10
do this inside Send() after the file operation and
no longer working on chromium
2012/04/13 11:50:50
Done.
| |
258 // Set the socket to blocking mode if it is non-blocking on receiving. | |
259 if ((state & PIPE_WAIT) == 0) { | |
260 state = PIPE_WAIT; | |
261 SetNamedPipeHandleState(handle_, &state, NULL, NULL); | |
262 } | |
263 } | |
243 return CancelableFileOperation(&ReadFile, handle_, | 264 return CancelableFileOperation(&ReadFile, handle_, |
244 reinterpret_cast<char*>(buffer), length, &file_operation_, | 265 reinterpret_cast<char*>(buffer), length, &file_operation_, |
245 &shutdown_event_, this); | 266 &shutdown_event_, this); |
246 } | 267 } |
247 | 268 |
248 // static | 269 // static |
249 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 270 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
250 CancelableSyncSocket* socket_b) { | 271 CancelableSyncSocket* socket_b) { |
251 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); | 272 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); |
252 } | 273 } |
253 | 274 |
254 | 275 |
255 } // namespace base | 276 } // namespace base |
OLD | NEW |