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

Unified Diff: net/socket/tcp_client_socket_libevent.cc

Issue 344026: Add LoadLog to ClientSocket::Connect(). (Closed)
Patch Set: Minor build fixups and fixed mac bug. Created 11 years, 1 month 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_client_socket_libevent.h ('k') | net/socket/tcp_client_socket_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_client_socket_libevent.cc
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 165c4cd103a049e168e5da260a25cc51aefdbe7f..abf66bcc3e5f597f6b8809d160f69090c7157e28 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -14,6 +14,7 @@
#include "base/string_util.h"
#include "base/trace_event.h"
#include "net/base/io_buffer.h"
+#include "net/base/load_log.h"
#include "net/base/net_errors.h"
#include "third_party/libevent/event.h"
@@ -117,15 +118,37 @@ TCPClientSocketLibevent::~TCPClientSocketLibevent() {
Disconnect();
}
-int TCPClientSocketLibevent::Connect(CompletionCallback* callback) {
+int TCPClientSocketLibevent::Connect(CompletionCallback* callback,
+ LoadLog* load_log) {
// If already connected, then just return OK.
if (socket_ != kInvalidSocket)
return OK;
DCHECK(!waiting_connect_);
+ DCHECK(!load_log_);
TRACE_EVENT_BEGIN("socket.connect", this, "");
+ LoadLog::BeginEvent(load_log, LoadLog::TYPE_TCP_CONNECT);
+
+ int rv = DoConnect();
+
+ if (rv == ERR_IO_PENDING) {
+ // Synchronous operation not supported.
+ DCHECK(callback);
+
+ load_log_ = load_log;
+ waiting_connect_ = true;
+ write_callback_ = callback;
+ } else {
+ TRACE_EVENT_END("socket.connect", this, "");
+ LoadLog::EndEvent(load_log, LoadLog::TYPE_TCP_CONNECT);
+ }
+
+ return rv;
+}
+
+int TCPClientSocketLibevent::DoConnect() {
while (true) {
DCHECK(current_ai_);
@@ -135,7 +158,6 @@ int TCPClientSocketLibevent::Connect(CompletionCallback* callback) {
if (!HANDLE_EINTR(connect(socket_, current_ai_->ai_addr,
static_cast<int>(current_ai_->ai_addrlen)))) {
- TRACE_EVENT_END("socket.connect", this, "");
// Connected without waiting!
return OK;
}
@@ -158,9 +180,6 @@ int TCPClientSocketLibevent::Connect(CompletionCallback* callback) {
}
}
- // Synchronous operation not supported
- DCHECK(callback);
-
// Initialize write_socket_watcher_ and link it to our MessagePump.
// POLLOUT is set if the connection is established.
// POLLIN is set if the connection fails.
@@ -173,8 +192,6 @@ int TCPClientSocketLibevent::Connect(CompletionCallback* callback) {
return MapPosixError(errno);
}
- waiting_connect_ = true;
- write_callback_ = callback;
return ERR_IO_PENDING;
}
@@ -345,8 +362,6 @@ void TCPClientSocketLibevent::DoWriteCallback(int rv) {
void TCPClientSocketLibevent::DidCompleteConnect() {
int result = ERR_UNEXPECTED;
- TRACE_EVENT_END("socket.connect", this, "");
-
// Check to see if connect succeeded
int error_code = 0;
socklen_t len = sizeof(error_code);
@@ -361,12 +376,19 @@ void TCPClientSocketLibevent::DidCompleteConnect() {
const addrinfo* next = current_ai_->ai_next;
Disconnect();
current_ai_ = next;
- result = Connect(write_callback_);
+ scoped_refptr<LoadLog> load_log;
+ load_log.swap(load_log_);
+ TRACE_EVENT_END("socket.connect", this, "");
+ LoadLog::EndEvent(load_log, LoadLog::TYPE_TCP_CONNECT);
+ result = Connect(write_callback_, load_log);
} else {
result = MapConnectError(error_code);
bool ok = write_socket_watcher_.StopWatchingFileDescriptor();
DCHECK(ok);
waiting_connect_ = false;
+ TRACE_EVENT_END("socket.connect", this, "");
+ LoadLog::EndEvent(load_log_, LoadLog::TYPE_TCP_CONNECT);
+ load_log_ = NULL;
}
if (result != ERR_IO_PENDING) {
« no previous file with comments | « net/socket/tcp_client_socket_libevent.h ('k') | net/socket/tcp_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698