Index: net/socket/socket_posix.cc |
diff --git a/net/socket/socket_posix.cc b/net/socket/socket_posix.cc |
index 09d9baec87e0139e41226b8a1b8b5a8de5c6a6c6..aac5fbabc103e8fc1b660da10912bc197c19789b 100644 |
--- a/net/socket/socket_posix.cc |
+++ b/net/socket/socket_posix.cc |
@@ -275,6 +275,16 @@ int SocketPosix::Read(IOBuffer* buf, |
return ERR_IO_PENDING; |
} |
+int SocketPosix::ReadIfReady(IOBuffer* buf, |
+ int buf_len, |
+ const CompletionCallback& callback) { |
+ // Reuse Read() but do not hold on to |buf| and |buf_len|. |
+ int rv = Read(buf, buf_len, callback); |
+ read_buf_ = nullptr; |
+ read_buf_len_ = 0; |
+ return rv; |
+} |
davidben
2017/02/01 22:25:57
Nit: It might be a little clearer to make lines 25
xunjieli
2017/02/03 16:35:33
Done. I like your approach better. It's easier to
|
+ |
int SocketPosix::Write(IOBuffer* buf, |
int buf_len, |
const CompletionCallback& callback) { |
@@ -451,6 +461,14 @@ int SocketPosix::DoRead(IOBuffer* buf, int buf_len) { |
} |
void SocketPosix::ReadCompleted() { |
+ // If |read_buf_| is nullptr, ReadIfReady() is used instead of Read(), so |
+ // do not continue reading but wait for the caller to retry. |
+ if (read_buf_ == nullptr) { |
+ bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); |
+ DCHECK(ok); |
+ base::ResetAndReturn(&read_callback_).Run(OK); |
+ return; |
+ } |
int rv = DoRead(read_buf_.get(), read_buf_len_); |
if (rv == ERR_IO_PENDING) |
return; |