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

Unified Diff: chrome/browser/extensions/api/socket/tcp_socket.cc

Issue 10310170: Improve socket.write() to make sure all data will be sent out. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix compile error on Mac Created 8 years, 7 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: chrome/browser/extensions/api/socket/tcp_socket.cc
diff --git a/chrome/browser/extensions/api/socket/tcp_socket.cc b/chrome/browser/extensions/api/socket/tcp_socket.cc
index 8c1b1b7a53fe87fa939d1f35204b489462f6af2d..6d3d24de6eeb35aad0bc2d102739817a74e8f8c2 100644
--- a/chrome/browser/extensions/api/socket/tcp_socket.cc
+++ b/chrome/browser/extensions/api/socket/tcp_socket.cc
@@ -115,36 +115,6 @@ void TCPSocket::Read(int count,
OnReadComplete(io_buffer, result);
}
-void TCPSocket::Write(scoped_refptr<net::IOBuffer> io_buffer,
- int byte_count,
- const CompletionCallback& callback) {
- DCHECK(!callback.is_null());
-
- if (!write_callback_.is_null()) {
- // TODO(penghuang): Put requests in a pending queue to support multiple
- // write calls.
- callback.Run(net::ERR_IO_PENDING);
- return;
- } else {
- write_callback_ = callback;
- }
-
- int result = net::ERR_FAILED;
- do {
- if (!socket_.get() || !socket_->IsConnected()) {
- result = net::ERR_SOCKET_NOT_CONNECTED;
- break;
- }
-
- result = socket_->Write(
- io_buffer.get(), byte_count,
- base::Bind(&TCPSocket::OnWriteComplete, base::Unretained(this)));
- } while (false);
-
- if (result != net::ERR_IO_PENDING)
- OnWriteComplete(result);
-}
-
void TCPSocket::RecvFrom(int count,
const RecvFromCompletionCallback& callback) {
callback.Run(net::ERR_FAILED, NULL, NULL, 0);
@@ -158,6 +128,15 @@ void TCPSocket::SendTo(scoped_refptr<net::IOBuffer> io_buffer,
callback.Run(net::ERR_FAILED);
}
+int TCPSocket::WriteImpl(net::IOBuffer* io_buffer,
+ int io_buffer_size,
+ const net::CompletionCallback& callback) {
+ if (!socket_.get() || !socket_->IsConnected())
+ return net::ERR_SOCKET_NOT_CONNECTED;
+ else
+ return socket_->Write(io_buffer, io_buffer_size, callback);
+}
+
void TCPSocket::OnConnectComplete(int result) {
DCHECK(!connect_callback_.is_null());
DCHECK(!is_connected_);
@@ -173,10 +152,4 @@ void TCPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
read_callback_.Reset();
}
-void TCPSocket::OnWriteComplete(int result) {
- DCHECK(!write_callback_.is_null());
- write_callback_.Run(result);
- write_callback_.Reset();
-}
-
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/socket/tcp_socket.h ('k') | chrome/browser/extensions/api/socket/tcp_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698