Index: base/sync_socket_posix.cc |
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc |
index c5dca752b2de81da10f475cf30a3e74bc020513c..3657e32e2678e693bee964babc64cb4d922f8ea4 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> |
@@ -93,13 +94,28 @@ bool SyncSocket::Close() { |
size_t SyncSocket::Send(const void* buffer, size_t length) { |
DCHECK_LE(length, kMaxMessageLength); |
+ long flags = 0; |
tommi (sloooow) - chröme
2012/04/13 10:28:10
suggest you only change this for CancelableSyncSoc
no longer working on chromium
2012/04/13 11:50:50
Done.
|
+ flags = fcntl(handle_, F_GETFL, NULL); |
+ if (flags >= 0 && !(flags & O_NONBLOCK)) { |
tommi (sloooow) - chröme
2012/04/13 10:28:10
instead of >= 0, use != -1
no longer working on chromium
2012/04/13 11:50:50
Done.
|
+ // Set the socket to non-blocking mode if it is blocking. |
+ fcntl(handle_, F_SETFL, flags | O_NONBLOCK); |
+ } |
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 10:28:10
good catch on handling -1!
tommi (sloooow) - chröme
2012/04/13 10:28:10
please reset the state of the socket after sending
no longer working on chromium
2012/04/13 11:50:50
Done.
|
+ return 0; |
+ |
return static_cast<size_t>(len); |
} |
size_t SyncSocket::Receive(void* buffer, size_t length) { |
DCHECK_LE(length, kMaxMessageLength); |
+ long flags = 0; |
tommi (sloooow) - chröme
2012/04/13 10:28:10
imho this should be done after WriteFileDescriptor
no longer working on chromium
2012/04/13 11:50:50
Done.
|
+ flags = fcntl(handle_, F_GETFL, NULL); |
+ if (flags >= 0 && (flags & O_NONBLOCK)) { |
tommi (sloooow) - chröme
2012/04/13 10:28:10
!= -1
no longer working on chromium
2012/04/13 11:50:50
Done.
|
+ // Set the socket to blocking mode if it is non-blocking. |
+ fcntl(handle_, F_SETFL, flags & ~O_NONBLOCK); |
+ } |
char* charbuffer = static_cast<char*>(buffer); |
if (file_util::ReadFromFD(handle_, charbuffer, length)) |
return length; |