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

Unified Diff: net/socket/tcp_socket_libevent.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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: net/socket/tcp_socket_libevent.cc
diff --git a/net/socket/tcp_socket_libevent.cc b/net/socket/tcp_socket_libevent.cc
index 72ae5809e106c6ba37c1f061d93d96e255c7dfb7..3a63b5a7fc40a1113d70423c8cf4342f80124a75 100644
--- a/net/socket/tcp_socket_libevent.cc
+++ b/net/socket/tcp_socket_libevent.cc
@@ -111,9 +111,8 @@ int MapConnectError(int os_error) {
//-----------------------------------------------------------------------------
-TCPSocketLibevent::Watcher::Watcher(
- const base::Closure& read_ready_callback,
- const base::Closure& write_ready_callback)
+TCPSocketLibevent::Watcher::Watcher(const base::Closure& read_ready_callback,
+ const base::Closure& write_ready_callback)
: read_ready_callback_(read_ready_callback),
write_ready_callback_(write_ready_callback) {
}
@@ -166,7 +165,8 @@ TCPSocketLibevent::~TCPSocketLibevent() {
net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE);
if (tcp_fastopen_connected_) {
UMA_HISTOGRAM_ENUMERATION("Net.TcpFastOpenSocketConnection",
- fast_open_status_, FAST_OPEN_MAX_VALUE);
+ fast_open_status_,
+ FAST_OPEN_MAX_VALUE);
}
Close();
}
@@ -175,8 +175,8 @@ int TCPSocketLibevent::Open(AddressFamily family) {
DCHECK(CalledOnValidThread());
DCHECK_EQ(socket_, kInvalidSocket);
- socket_ = CreatePlatformSocket(ConvertAddressFamily(family), SOCK_STREAM,
- IPPROTO_TCP);
+ socket_ = CreatePlatformSocket(
+ ConvertAddressFamily(family), SOCK_STREAM, IPPROTO_TCP);
if (socket_ < 0) {
PLOG(ERROR) << "CreatePlatformSocket() returned an error";
return MapSystemError(errno);
@@ -255,8 +255,11 @@ int TCPSocketLibevent::Accept(scoped_ptr<TCPSocketLibevent>* socket,
if (result == ERR_IO_PENDING) {
if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, base::MessageLoopForIO::WATCH_READ,
- &accept_socket_watcher_, &accept_watcher_)) {
+ socket_,
+ true,
+ base::MessageLoopForIO::WATCH_READ,
+ &accept_socket_watcher_,
+ &accept_watcher_)) {
PLOG(ERROR) << "WatchFileDescriptor failed on read";
return MapSystemError(errno);
}
@@ -361,8 +364,8 @@ int TCPSocketLibevent::Read(IOBuffer* buf,
if (nread >= 0) {
base::StatsCounter read_bytes("tcp.read_bytes");
read_bytes.Add(nread);
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread,
- buf->data());
+ net_log_.AddByteTransferEvent(
+ NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread, buf->data());
RecordFastOpenStatus();
return nread;
}
@@ -374,8 +377,11 @@ int TCPSocketLibevent::Read(IOBuffer* buf,
}
if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, base::MessageLoopForIO::WATCH_READ,
- &read_socket_watcher_, &read_watcher_)) {
+ socket_,
+ true,
+ base::MessageLoopForIO::WATCH_READ,
+ &read_socket_watcher_,
+ &read_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on read, errno " << errno;
return MapSystemError(errno);
}
@@ -401,8 +407,8 @@ int TCPSocketLibevent::Write(IOBuffer* buf,
if (nwrite >= 0) {
base::StatsCounter write_bytes("tcp.write_bytes");
write_bytes.Add(nwrite);
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, nwrite,
- buf->data());
+ net_log_.AddByteTransferEvent(
+ NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, buf->data());
return nwrite;
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -413,8 +419,11 @@ int TCPSocketLibevent::Write(IOBuffer* buf,
}
if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, base::MessageLoopForIO::WATCH_WRITE,
- &write_socket_watcher_, &write_watcher_)) {
+ socket_,
+ true,
+ base::MessageLoopForIO::WATCH_WRITE,
+ &write_socket_watcher_,
+ &write_watcher_)) {
DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno;
return MapSystemError(errno);
}
@@ -459,17 +468,17 @@ void TCPSocketLibevent::SetDefaultOptionsForClient() {
// tcp_socket_win.cc after searching for "NODELAY".
SetTCPNoDelay(socket_, true); // If SetTCPNoDelay fails, we don't care.
- // TCP keep alive wakes up the radio, which is expensive on mobile. Do not
- // enable it there. It's useful to prevent TCP middleboxes from timing out
- // connection mappings. Packets for timed out connection mappings at
- // middleboxes will either lead to:
- // a) Middleboxes sending TCP RSTs. It's up to higher layers to check for this
- // and retry. The HTTP network transaction code does this.
- // b) Middleboxes just drop the unrecognized TCP packet. This leads to the TCP
- // stack retransmitting packets per TCP stack retransmission timeouts, which
- // are very high (on the order of seconds). Given the number of
- // retransmissions required before killing the connection, this can lead to
- // tens of seconds or even minutes of delay, depending on OS.
+// TCP keep alive wakes up the radio, which is expensive on mobile. Do not
+// enable it there. It's useful to prevent TCP middleboxes from timing out
+// connection mappings. Packets for timed out connection mappings at
+// middleboxes will either lead to:
+// a) Middleboxes sending TCP RSTs. It's up to higher layers to check for this
+// and retry. The HTTP network transaction code does this.
+// b) Middleboxes just drop the unrecognized TCP packet. This leads to the TCP
+// stack retransmitting packets per TCP stack retransmission timeouts, which
+// are very high (on the order of seconds). Given the number of
+// retransmissions required before killing the connection, this can lead to
+// tens of seconds or even minutes of delay, depending on OS.
#if !defined(OS_ANDROID) && !defined(OS_IOS)
const int kTCPKeepAliveSeconds = 45;
@@ -494,8 +503,8 @@ int TCPSocketLibevent::SetAddressReuse(bool allow) {
//
// SO_REUSEPORT is provided in MacOS X and iOS.
int boolean_value = allow ? 1 : 0;
- int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &boolean_value,
- sizeof(boolean_value));
+ int rv = setsockopt(
+ socket_, SOL_SOCKET, SO_REUSEADDR, &boolean_value, sizeof(boolean_value));
if (rv < 0)
return MapSystemError(errno);
return OK;
@@ -503,15 +512,21 @@ int TCPSocketLibevent::SetAddressReuse(bool allow) {
int TCPSocketLibevent::SetReceiveBufferSize(int32 size) {
DCHECK(CalledOnValidThread());
- int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<const char*>(&size), sizeof(size));
+ int rv = setsockopt(socket_,
+ SOL_SOCKET,
+ SO_RCVBUF,
+ reinterpret_cast<const char*>(&size),
+ sizeof(size));
return (rv == 0) ? OK : MapSystemError(errno);
}
int TCPSocketLibevent::SetSendBufferSize(int32 size) {
DCHECK(CalledOnValidThread());
- int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<const char*>(&size), sizeof(size));
+ int rv = setsockopt(socket_,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ reinterpret_cast<const char*>(&size),
+ sizeof(size));
return (rv == 0) ? OK : MapSystemError(errno);
}
@@ -592,9 +607,8 @@ void TCPSocketLibevent::EndLoggingMultipleConnectAttempts(int net_error) {
int TCPSocketLibevent::AcceptInternal(scoped_ptr<TCPSocketLibevent>* socket,
IPEndPoint* address) {
SockaddrStorage storage;
- int new_socket = HANDLE_EINTR(accept(socket_,
- storage.addr,
- &storage.addr_len));
+ int new_socket =
+ HANDLE_EINTR(accept(socket_, storage.addr, &storage.addr_len));
if (new_socket < 0) {
int net_error = MapAcceptError(errno);
if (net_error != ERR_IO_PENDING)
@@ -611,8 +625,8 @@ int TCPSocketLibevent::AcceptInternal(scoped_ptr<TCPSocketLibevent>* socket,
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error);
return net_error;
}
- scoped_ptr<TCPSocketLibevent> tcp_socket(new TCPSocketLibevent(
- net_log_.net_log(), net_log_.source()));
+ scoped_ptr<TCPSocketLibevent> tcp_socket(
+ new TCPSocketLibevent(net_log_.net_log(), net_log_.source()));
int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point);
if (adopt_result != OK) {
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result);
@@ -655,8 +669,11 @@ int TCPSocketLibevent::DoConnect() {
// Otherwise the connect() is going to complete asynchronously, so watch
// for its completion.
if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
- socket_, true, base::MessageLoopForIO::WATCH_WRITE,
- &write_socket_watcher_, &write_watcher_)) {
+ socket_,
+ true,
+ base::MessageLoopForIO::WATCH_WRITE,
+ &write_socket_watcher_,
+ &write_watcher_)) {
connect_os_error_ = errno;
DVLOG(1) << "WatchFileDescriptor failed: " << connect_os_error_;
return MapSystemError(connect_os_error_);
@@ -706,9 +723,9 @@ void TCPSocketLibevent::LogConnectEnd(int net_error) {
return;
}
- net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT,
- CreateNetLogSourceAddressCallback(storage.addr,
- storage.addr_len));
+ net_log_.EndEvent(
+ NetLog::TYPE_TCP_CONNECT,
+ CreateNetLogSourceAddressCallback(storage.addr, storage.addr_len));
}
void TCPSocketLibevent::DidCompleteRead() {
@@ -717,16 +734,16 @@ void TCPSocketLibevent::DidCompleteRead() {
return;
int bytes_transferred;
- bytes_transferred = HANDLE_EINTR(read(socket_, read_buf_->data(),
- read_buf_len_));
+ bytes_transferred =
+ HANDLE_EINTR(read(socket_, read_buf_->data(), read_buf_len_));
int result;
if (bytes_transferred >= 0) {
result = bytes_transferred;
base::StatsCounter read_bytes("tcp.read_bytes");
read_bytes.Add(bytes_transferred);
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, result,
- read_buf_->data());
+ net_log_.AddByteTransferEvent(
+ NetLog::TYPE_SOCKET_BYTES_RECEIVED, result, read_buf_->data());
} else {
result = MapSystemError(errno);
if (result != ERR_IO_PENDING) {
@@ -749,16 +766,16 @@ void TCPSocketLibevent::DidCompleteWrite() {
return;
int bytes_transferred;
- bytes_transferred = HANDLE_EINTR(write(socket_, write_buf_->data(),
- write_buf_len_));
+ bytes_transferred =
+ HANDLE_EINTR(write(socket_, write_buf_->data(), write_buf_len_));
int result;
if (bytes_transferred >= 0) {
result = bytes_transferred;
base::StatsCounter write_bytes("tcp.write_bytes");
write_bytes.Add(bytes_transferred);
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, result,
- write_buf_->data());
+ net_log_.AddByteTransferEvent(
+ NetLog::TYPE_SOCKET_BYTES_SENT, result, write_buf_->data());
} else {
result = MapSystemError(errno);
if (result != ERR_IO_PENDING) {
@@ -827,20 +844,16 @@ int TCPSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) {
return -1;
}
- int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN.
+ int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN.
#if defined(OS_LINUX)
// sendto() will fail with EPIPE when the system doesn't support TCP Fast
// Open. Theoretically that shouldn't happen since the caller should check
// for system support on startup, but users may dynamically disable TCP Fast
// Open via sysctl.
flags |= MSG_NOSIGNAL;
-#endif // defined(OS_LINUX)
- nwrite = HANDLE_EINTR(sendto(socket_,
- buf->data(),
- buf_len,
- flags,
- storage.addr,
- storage.addr_len));
+#endif // defined(OS_LINUX)
+ nwrite = HANDLE_EINTR(sendto(
+ socket_, buf->data(), buf_len, flags, storage.addr, storage.addr_len));
tcp_fastopen_connected_ = true;
if (nwrite < 0) {
@@ -880,21 +893,21 @@ void TCPSocketLibevent::RecordFastOpenStatus() {
getsockopt_success =
getsockopt(socket_, IPPROTO_TCP, TCP_INFO, &info, &info_len) == 0 &&
info_len == sizeof(tcp_info);
- server_acked_data = getsockopt_success &&
- (info.tcpi_options & TCPI_OPT_SYN_DATA);
+ server_acked_data =
+ getsockopt_success && (info.tcpi_options & TCPI_OPT_SYN_DATA);
#endif
if (getsockopt_success) {
if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) {
- fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK :
- FAST_OPEN_SYN_DATA_NACK);
+ fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK
+ : FAST_OPEN_SYN_DATA_NACK);
} else {
- fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK :
- FAST_OPEN_NO_SYN_DATA_NACK);
+ fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK
+ : FAST_OPEN_NO_SYN_DATA_NACK);
}
} else {
- fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ?
- FAST_OPEN_SYN_DATA_FAILED :
- FAST_OPEN_NO_SYN_DATA_FAILED);
+ fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN
+ ? FAST_OPEN_SYN_DATA_FAILED
+ : FAST_OPEN_NO_SYN_DATA_FAILED);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698