Index: net/socket/tcp_socket_win.cc |
diff --git a/net/socket/tcp_socket_win.cc b/net/socket/tcp_socket_win.cc |
index 4667bd8e423dd5b034969c715569fbf8843085c1..4c80ccfdde9fd4e55c4e9a9f618f43e3a6775a88 100644 |
--- a/net/socket/tcp_socket_win.cc |
+++ b/net/socket/tcp_socket_win.cc |
@@ -29,16 +29,22 @@ namespace { |
const int kTCPKeepAliveSeconds = 45; |
int SetSocketReceiveBufferSize(SOCKET socket, int32 size) { |
- 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)); |
int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError()); |
DCHECK(!rv) << "Could not set socket receive buffer size: " << net_error; |
return net_error; |
} |
int SetSocketSendBufferSize(SOCKET socket, int32 size) { |
- 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)); |
int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError()); |
DCHECK(!rv) << "Could not set socket send buffer size: " << net_error; |
return net_error; |
@@ -68,7 +74,9 @@ int SetSocketSendBufferSize(SOCKET socket, int32 size) { |
// http://technet.microsoft.com/en-us/library/bb726981.aspx |
bool DisableNagle(SOCKET socket, bool disable) { |
BOOL val = disable ? TRUE : FALSE; |
- int rv = setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, |
+ int rv = setsockopt(socket, |
+ IPPROTO_TCP, |
+ TCP_NODELAY, |
reinterpret_cast<const char*>(&val), |
sizeof(val)); |
DCHECK(!rv) << "Could not disable nagle"; |
@@ -80,14 +88,20 @@ bool DisableNagle(SOCKET socket, bool disable) { |
bool SetTCPKeepAlive(SOCKET socket, BOOL enable, int delay_secs) { |
int delay = delay_secs * 1000; |
struct tcp_keepalive keepalive_vals = { |
- enable ? 1 : 0, // TCP keep-alive on. |
- delay, // Delay seconds before sending first TCP keep-alive packet. |
- delay, // Delay seconds between sending TCP keep-alive packets. |
+ enable ? 1 : 0, // TCP keep-alive on. |
+ delay, // Delay seconds before sending first TCP keep-alive packet. |
+ delay, // Delay seconds between sending TCP keep-alive packets. |
}; |
DWORD bytes_returned = 0xABAB; |
- int rv = WSAIoctl(socket, SIO_KEEPALIVE_VALS, &keepalive_vals, |
- sizeof(keepalive_vals), NULL, 0, |
- &bytes_returned, NULL, NULL); |
+ int rv = WSAIoctl(socket, |
+ SIO_KEEPALIVE_VALS, |
+ &keepalive_vals, |
+ sizeof(keepalive_vals), |
+ NULL, |
+ 0, |
+ &bytes_returned, |
+ NULL, |
+ NULL); |
DCHECK(!rv) << "Could not enable TCP Keep-Alive for socket: " << socket |
<< " [error: " << WSAGetLastError() << "]."; |
@@ -249,8 +263,7 @@ void TCPSocketWin::Core::ReadDelegate::OnObjectSignaled(HANDLE object) { |
core_->Release(); |
} |
-void TCPSocketWin::Core::WriteDelegate::OnObjectSignaled( |
- HANDLE object) { |
+void TCPSocketWin::Core::WriteDelegate::OnObjectSignaled(HANDLE object) { |
DCHECK_EQ(object, core_->write_overlapped_.hEvent); |
if (core_->socket_) |
core_->socket_->DidCompleteWrite(); |
@@ -286,8 +299,8 @@ int TCPSocketWin::Open(AddressFamily family) { |
DCHECK(CalledOnValidThread()); |
DCHECK_EQ(socket_, INVALID_SOCKET); |
- socket_ = CreatePlatformSocket(ConvertAddressFamily(family), SOCK_STREAM, |
- IPPROTO_TCP); |
+ socket_ = CreatePlatformSocket( |
+ ConvertAddressFamily(family), SOCK_STREAM, IPPROTO_TCP); |
if (socket_ == INVALID_SOCKET) { |
PLOG(ERROR) << "CreatePlatformSocket() returned an error"; |
return MapSystemError(WSAGetLastError()); |
@@ -511,8 +524,8 @@ int TCPSocketWin::Write(IOBuffer* buf, |
// TODO(wtc): Remove the assertion after enough testing. |
AssertEventNotSignaled(core_->write_overlapped_.hEvent); |
DWORD num; |
- int rv = WSASend(socket_, &write_buffer, 1, &num, 0, |
- &core_->write_overlapped_, NULL); |
+ int rv = WSASend( |
+ socket_, &write_buffer, 1, &num, 0, &core_->write_overlapped_, NULL); |
if (rv == 0) { |
if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) { |
rv = static_cast<int>(num); |
@@ -525,8 +538,8 @@ int TCPSocketWin::Write(IOBuffer* buf, |
} |
base::StatsCounter write_bytes("tcp.write_bytes"); |
write_bytes.Add(rv); |
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, |
- buf->data()); |
+ net_log_.AddByteTransferEvent( |
+ NetLog::TYPE_SOCKET_BYTES_SENT, rv, buf->data()); |
return rv; |
} |
} else { |
@@ -611,7 +624,9 @@ int TCPSocketWin::SetExclusiveAddrUse() { |
// socket. |
BOOL true_value = 1; |
- int rv = setsockopt(socket_, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, |
+ int rv = setsockopt(socket_, |
+ SOL_SOCKET, |
+ SO_EXCLUSIVEADDRUSE, |
reinterpret_cast<const char*>(&true_value), |
sizeof(true_value)); |
if (rv < 0) |
@@ -735,8 +750,8 @@ int TCPSocketWin::AcceptInternal(scoped_ptr<TCPSocketWin>* socket, |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); |
return net_error; |
} |
- scoped_ptr<TCPSocketWin> tcp_socket(new TCPSocketWin( |
- net_log_.net_log(), net_log_.source())); |
+ scoped_ptr<TCPSocketWin> tcp_socket( |
+ new TCPSocketWin(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); |
@@ -870,11 +885,11 @@ void TCPSocketWin::LogConnectEnd(int net_error) { |
sizeof(source_address))); |
} |
-int TCPSocketWin::DoRead(IOBuffer* buf, int buf_len, |
+int TCPSocketWin::DoRead(IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
if (!core_->non_blocking_reads_initialized_) { |
- WSAEventSelect(socket_, core_->read_overlapped_.hEvent, |
- FD_READ | FD_CLOSE); |
+ WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_READ | FD_CLOSE); |
core_->non_blocking_reads_initialized_ = true; |
} |
int rv = recv(socket_, buf->data(), buf_len, 0); |
@@ -882,17 +897,16 @@ int TCPSocketWin::DoRead(IOBuffer* buf, int buf_len, |
int os_error = WSAGetLastError(); |
if (os_error != WSAEWOULDBLOCK) { |
int net_error = MapSystemError(os_error); |
- net_log_.AddEvent( |
- NetLog::TYPE_SOCKET_READ_ERROR, |
- CreateNetLogSocketErrorCallback(net_error, os_error)); |
+ net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, |
+ CreateNetLogSocketErrorCallback(net_error, os_error)); |
return net_error; |
} |
} else { |
base::StatsCounter read_bytes("tcp.read_bytes"); |
if (rv > 0) |
read_bytes.Add(rv); |
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, |
- buf->data()); |
+ net_log_.AddByteTransferEvent( |
+ NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, buf->data()); |
return rv; |
} |
@@ -910,8 +924,8 @@ void TCPSocketWin::DidCompleteConnect() { |
int result; |
WSANETWORKEVENTS events; |
- int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, |
- &events); |
+ int rv = |
+ WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, &events); |
int os_error = 0; |
if (rv == SOCKET_ERROR) { |
NOTREACHED(); |
@@ -938,8 +952,8 @@ void TCPSocketWin::DidCompleteWrite() { |
DCHECK(!write_callback_.is_null()); |
DWORD num_bytes, flags; |
- BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, |
- &num_bytes, FALSE, &flags); |
+ BOOL ok = WSAGetOverlappedResult( |
+ socket_, &core_->write_overlapped_, &num_bytes, FALSE, &flags); |
WSAResetEvent(core_->write_overlapped_.hEvent); |
waiting_write_ = false; |
int rv; |
@@ -960,7 +974,8 @@ void TCPSocketWin::DidCompleteWrite() { |
} else { |
base::StatsCounter write_bytes("tcp.write_bytes"); |
write_bytes.Add(num_bytes); |
- net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
+ net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, |
+ num_bytes, |
core_->write_iobuffer_->data()); |
} |
} |
@@ -977,8 +992,8 @@ void TCPSocketWin::DidSignalRead() { |
int os_error = 0; |
WSANETWORKEVENTS network_events; |
- int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, |
- &network_events); |
+ int rv = WSAEnumNetworkEvents( |
+ socket_, core_->read_overlapped_.hEvent, &network_events); |
if (rv == SOCKET_ERROR) { |
os_error = WSAGetLastError(); |
rv = MapSystemError(os_error); |
@@ -998,8 +1013,8 @@ void TCPSocketWin::DidSignalRead() { |
// DoRead() because recv() reports a more accurate error code |
// (WSAECONNRESET vs. WSAECONNABORTED) when the connection was |
// reset. |
- rv = DoRead(core_->read_iobuffer_, core_->read_buffer_length_, |
- read_callback_); |
+ rv = DoRead( |
+ core_->read_iobuffer_, core_->read_buffer_length_, read_callback_); |
if (rv == ERR_IO_PENDING) |
return; |
} else { |
@@ -1018,4 +1033,3 @@ void TCPSocketWin::DidSignalRead() { |
} |
} // namespace net |
- |