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

Unified 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: ready for review now. 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 side-by-side diff with in-line comments
Download patch
Index: base/sync_socket_win.cc
diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc
index c6fb1ce789c4b7fe596f8cccd99e704ec1d0713c..41bea9fe44bb837c3aee14d251a36489394ea030 100644
--- a/base/sync_socket_win.cc
+++ b/base/sync_socket_win.cc
@@ -146,6 +146,11 @@ size_t CancelableFileOperation(Function operation, HANDLE file,
return (0 < count) ? count : 0;
}
}
+
+ // Quit the operation if we can't write/read anymore.
+ 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
+ break;
+
count += len;
}
return count;
@@ -234,12 +239,28 @@ bool CancelableSyncSocket::Close() {
}
size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
+ DWORD state = 0;
+ if (GetNamedPipeHandleState(handle_, &state, NULL, NULL, NULL, NULL, 0)) {
+ // Set the socket to non-blocking mode if it is blocking on sending.
+ if ((state & PIPE_NOWAIT) == 0) {
+ state = PIPE_NOWAIT;
+ SetNamedPipeHandleState(handle_, &state, NULL, NULL);
+ }
+ }
return CancelableFileOperation(&WriteFile, handle_,
reinterpret_cast<const char*>(buffer), length, &file_operation_,
&shutdown_event_, this);
}
size_t CancelableSyncSocket::Receive(void* buffer, size_t length) {
+ DWORD state = 0;
+ 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.
+ // Set the socket to blocking mode if it is non-blocking on receiving.
+ if ((state & PIPE_WAIT) == 0) {
+ state = PIPE_WAIT;
+ SetNamedPipeHandleState(handle_, &state, NULL, NULL);
+ }
+ }
return CancelableFileOperation(&ReadFile, handle_,
reinterpret_cast<char*>(buffer), length, &file_operation_,
&shutdown_event_, this);

Powered by Google App Engine
This is Rietveld 408576698