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

Unified Diff: net/socket/tcp_socket_libevent.cc

Issue 382143007: Make sure read/write buffer alive in TCPSocketLibevent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comment as suggested Created 6 years, 5 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
« no previous file with comments | « net/socket/tcp_socket_libevent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_socket_libevent.cc
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc
index fe08f9c227f0f42e1190f12066663efcbaacf620..444e3c04231ce3f5279e56dad7e43d557d7bc86e 100644
--- a/net/socket/tcp_socket_libevent.cc
+++ b/net/socket/tcp_socket_libevent.cc
@@ -211,7 +211,10 @@ int TCPSocketLibevent::Read(IOBuffer* buf,
int rv = socket_->Read(
buf, buf_len,
base::Bind(&TCPSocketLibevent::ReadCompleted,
- base::Unretained(this), base::Unretained(buf), callback));
+ // Grab a reference to |buf| so that ReadCompleted() can still
+ // use it when Read() completes, as otherwise, this transfers
+ // ownership of buf to socket.
+ base::Unretained(this), make_scoped_refptr(buf), callback));
if (rv >= 0)
RecordFastOpenStatus();
if (rv != ERR_IO_PENDING)
@@ -227,7 +230,10 @@ int TCPSocketLibevent::Write(IOBuffer* buf,
CompletionCallback write_callback =
base::Bind(&TCPSocketLibevent::WriteCompleted,
- base::Unretained(this), base::Unretained(buf), callback);
+ // Grab a reference to |buf| so that WriteCompleted() can still
+ // use it when Write() completes, as otherwise, this transfers
+ // ownership of buf to socket.
+ base::Unretained(this), make_scoped_refptr(buf), callback);
int rv;
if (use_tcp_fastopen_ && !tcp_fastopen_connected_) {
rv = TcpFastOpenWrite(buf, buf_len, write_callback);
@@ -485,7 +491,7 @@ void TCPSocketLibevent::LogConnectEnd(int net_error) const {
storage.addr_len));
}
-void TCPSocketLibevent::ReadCompleted(IOBuffer* buf,
+void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf,
const CompletionCallback& callback,
int rv) {
DCHECK_NE(ERR_IO_PENDING, rv);
@@ -510,7 +516,7 @@ int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) {
return rv;
}
-void TCPSocketLibevent::WriteCompleted(IOBuffer* buf,
+void TCPSocketLibevent::WriteCompleted(const scoped_refptr<IOBuffer>& buf,
const CompletionCallback& callback,
int rv) const {
DCHECK_NE(ERR_IO_PENDING, rv);
« no previous file with comments | « net/socket/tcp_socket_libevent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698