Revert revert 132842

If we are using blocking write, when the renderer stop getting the data without notifying the browser, it will hang the browser. This happens with some plugins which use the sync sockets provided by the Pepper.
This patch change CancellableSyncSocket to be non-blocking on sending, so that we don't need to worry the whole browser hangs by one plugin application.

Also, we remove the lock in audio_sync_reader.cc since it is not really needed if we don't set the socket_ to NULL when calling Close(). By doing this we allow the user to close the socket while another thread is writing to the socket.

BUG=121152
TEST=ipc_tests

TBR=tommi@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10124004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132975 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 5d272095550875715eb8eec5719f88dc2bd48113
diff --git a/base/sync_socket.h b/base/sync_socket.h
index 9bf8836..d5bfb72 100644
--- a/base/sync_socket.h
+++ b/base/sync_socket.h
@@ -7,7 +7,7 @@
 #pragma once
 
 // A socket abstraction used for sending and receiving plain
-// data.  Because they are blocking, they can be used to perform
+// data.  Because the receiving is blocking, they can be used to perform
 // rudimentary cross-process synchronization with low latency.
 
 #include "base/basictypes.h"
@@ -77,8 +77,8 @@
 };
 
 // Derives from SyncSocket and adds support for shutting down the socket from
-// another thread while a blocking Receive or Send is being done from the thread
-// that owns the socket.
+// another thread while a blocking Receive or Send is being done from the
+// thread that owns the socket.
 class BASE_EXPORT CancelableSyncSocket : public SyncSocket {
  public:
   CancelableSyncSocket();
@@ -102,10 +102,16 @@
   // supported on <Vista. So, for Windows only, we override these
   // SyncSocket methods in order to support shutting down the 'socket'.
   virtual bool Close() OVERRIDE;
-  virtual size_t Send(const void* buffer, size_t length) OVERRIDE;
   virtual size_t Receive(void* buffer, size_t length) OVERRIDE;
 #endif
 
+  // Send() is overridden to catch cases where the remote end is not responding
+  // and we fill the local socket buffer. When the buffer is full, this
+  // implementation of Send() will not block indefinitely as
+  // SyncSocket::Send will, but instead return 0, as no bytes could be sent.
+  // Note that the socket will not be closed in this case.
+  virtual size_t Send(const void* buffer, size_t length) OVERRIDE;
+
  private:
 #if defined(OS_WIN)
   WaitableEvent shutdown_event_;