Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: base/sync_socket_win.cc

Issue 10000004: Make the CancellableSyncSocket non-blocking on Send, and blocking on Receive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Tommi's comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 12:56:47 I wonder if we should perhaps widen the check a bi
no longer working on chromium 2012/04/16 10:26:45 My test shows that the size of the buffer is 4098
tommi (sloooow) - chröme 2012/04/16 11:24:57 I think we still need the loop for larger buffers.
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
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) {
237 return CancelableFileOperation(&WriteFile, handle_, 242 DWORD state = PIPE_NOWAIT;
238 reinterpret_cast<const char*>(buffer), length, &file_operation_, 243 // The default mode for the socket is blocking, set it to non-blocking mode
239 &shutdown_event_, this); 244 // for sending.
245 state = PIPE_NOWAIT;
tommi (sloooow) - chröme 2012/04/13 12:56:47 remove this line. you've already set the value.
no longer working on chromium 2012/04/16 10:26:45 Done.
246 SetNamedPipeHandleState(handle_, &state, NULL, NULL);
tommi (sloooow) - chröme 2012/04/13 12:56:47 instead of calling this directly, what about doing
no longer working on chromium 2012/04/16 10:26:45 Use WaitForMany.. instead, as we discussed offline
247
248 size_t len = CancelableFileOperation(
249 &WriteFile, handle_, reinterpret_cast<const char*>(buffer),
250 length, &file_operation_, &shutdown_event_, this);
251
252 // Set the socket back to blocking mode.
253 state = PIPE_WAIT;
254 SetNamedPipeHandleState(handle_, &state, NULL, NULL);
255
256 return len;
240 } 257 }
241 258
242 size_t CancelableSyncSocket::Receive(void* buffer, size_t length) { 259 size_t CancelableSyncSocket::Receive(void* buffer, size_t length) {
243 return CancelableFileOperation(&ReadFile, handle_, 260 return CancelableFileOperation(&ReadFile, handle_,
244 reinterpret_cast<char*>(buffer), length, &file_operation_, 261 reinterpret_cast<char*>(buffer), length, &file_operation_,
245 &shutdown_event_, this); 262 &shutdown_event_, this);
246 } 263 }
247 264
248 // static 265 // static
249 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, 266 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a,
250 CancelableSyncSocket* socket_b) { 267 CancelableSyncSocket* socket_b) {
251 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true); 268 return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, true);
252 } 269 }
253 270
254 271
255 } // namespace base 272 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698