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

Unified Diff: chrome/browser/extensions/api/socket/udp_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: Update 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/udp_socket.cc
diff --git a/chrome/browser/extensions/api/socket/udp_socket.cc b/chrome/browser/extensions/api/socket/udp_socket.cc
index b6a2904d50340c5b05581ee014fc2bc5f5eb244d..059208189ddcad8fff7087028f200b6f1685df2c 100644
--- a/chrome/browser/extensions/api/socket/udp_socket.cc
+++ b/chrome/browser/extensions/api/socket/udp_socket.cc
@@ -95,34 +95,13 @@ void UDPSocket::Read(int count,
OnReadComplete(io_buffer, result);
}
-void UDPSocket::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_.is_connected()) {
- result = net::ERR_SOCKET_NOT_CONNECTED;
- break;
- }
-
- result = socket_.Write(
- io_buffer.get(), byte_count,
- base::Bind(&UDPSocket::OnWriteComplete, base::Unretained(this)));
- } while (false);
-
- if (result != net::ERR_IO_PENDING)
- OnWriteComplete(result);
+int UDPSocket::WriteImpl(net::IOBuffer* io_buffer,
+ int io_buffer_size,
+ const net::CompletionCallback& callback) {
+ if (!socket_.is_connected())
+ return net::ERR_SOCKET_NOT_CONNECTED;
+ else
+ return socket_.Write(io_buffer, io_buffer_size, callback);
}
void UDPSocket::RecvFrom(int count,
@@ -213,12 +192,6 @@ void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
read_callback_.Reset();
}
-void UDPSocket::OnWriteComplete(int result) {
- DCHECK(!write_callback_.is_null());
- write_callback_.Run(result);
- write_callback_.Reset();
-}
-
void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer,
scoped_refptr<IPEndPoint> address,
int result) {

Powered by Google App Engine
This is Rietveld 408576698