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

Unified Diff: base/sync_socket_posix.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 side-by-side diff with in-line comments
Download patch
Index: base/sync_socket_posix.cc
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc
index c5dca752b2de81da10f475cf30a3e74bc020513c..d2afd155c9155cd8be8d3f6c79ef5d106ef63856 100644
--- a/base/sync_socket_posix.cc
+++ b/base/sync_socket_posix.cc
@@ -6,10 +6,11 @@
#include <errno.h>
#include <limits.h>
+#include <fcntl.h>
#include <stdio.h>
-#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <sys/types.h>
#if defined(OS_SOLARIS)
#include <sys/filio.h>
@@ -95,6 +96,9 @@ size_t SyncSocket::Send(const void* buffer, size_t length) {
DCHECK_LE(length, kMaxMessageLength);
const char* charbuffer = static_cast<const char*>(buffer);
int len = file_util::WriteFileDescriptor(handle_, charbuffer, length);
+ if (-1 == len)
tommi (sloooow) - chröme 2012/04/13 12:56:47 condense this to: return len == -1 ? 0 : static_c
no longer working on chromium 2012/04/16 10:26:45 Done.
+ return 0;
+
return static_cast<size_t>(len);
}
@@ -124,6 +128,25 @@ bool CancelableSyncSocket::Shutdown() {
return HANDLE_EINTR(shutdown(handle(), SHUT_RDWR)) >= 0;
}
+size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
+ long flags = 0;
+ flags = fcntl(handle_, F_GETFL, NULL);
+ if (flags != -1) {
tommi (sloooow) - chröme 2012/04/13 12:56:47 nit: if (flags != -1 && (flags & O_NONBLOCK) == 0)
no longer working on chromium 2012/04/16 10:26:45 Done.
+ // The default mode for the socket is blocking, set it to non-blocking mode
+ // for sending.
+ fcntl(handle_, F_SETFL, flags | O_NONBLOCK);
+ }
+
+ size_t len = SyncSocket::Send(buffer, length);
+
+ if (flags != -1) {
tommi (sloooow) - chröme 2012/04/13 12:56:47 nit: if (flags != -1 && (flags & O_NONBLOCK) == 0)
no longer working on chromium 2012/04/16 10:26:45 Done.
+ // Set the socket back to blocking mode.
tommi (sloooow) - chröme 2012/04/13 12:56:47 nit: // Restore the original flags.
no longer working on chromium 2012/04/16 10:26:45 Done.
+ fcntl(handle_, F_SETFL, flags);
+ }
+
+ return len;
+}
+
// static
bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a,
CancelableSyncSocket* socket_b) {
« no previous file with comments | « base/sync_socket.h ('k') | base/sync_socket_win.cc » ('j') | base/sync_socket_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698