| Index: net/udp/udp_socket_win.cc
|
| diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc
|
| index 4f742b93f03c1b475526bf4683ec86ec63721cc8..cf39f631da6156977a273c38be307283be7c55b5 100644
|
| --- a/net/udp/udp_socket_win.cc
|
| +++ b/net/udp/udp_socket_win.cc
|
| @@ -106,9 +106,7 @@ class UDPSocketWin::Core : public base::RefCounted<Core> {
|
| };
|
|
|
| UDPSocketWin::Core::Core(UDPSocketWin* socket)
|
| - : socket_(socket),
|
| - reader_(this),
|
| - writer_(this) {
|
| + : socket_(socket), reader_(this), writer_(this) {
|
| memset(&read_overlapped_, 0, sizeof(read_overlapped_));
|
| memset(&write_overlapped_, 0, sizeof(write_overlapped_));
|
|
|
| @@ -390,8 +388,11 @@ int UDPSocketWin::CreateSocket(int addr_family) {
|
|
|
| int UDPSocketWin::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));
|
| if (rv != 0)
|
| return MapSystemError(WSAGetLastError());
|
|
|
| @@ -399,35 +400,44 @@ int UDPSocketWin::SetReceiveBufferSize(int32 size) {
|
| // the results via getsockopt to be sure it works on Windows.
|
| int32 actual_size = 0;
|
| int option_size = sizeof(actual_size);
|
| - rv = getsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
|
| - reinterpret_cast<char*>(&actual_size), &option_size);
|
| + rv = getsockopt(socket_,
|
| + SOL_SOCKET,
|
| + SO_RCVBUF,
|
| + reinterpret_cast<char*>(&actual_size),
|
| + &option_size);
|
| if (rv != 0)
|
| return MapSystemError(WSAGetLastError());
|
| if (actual_size >= size)
|
| return OK;
|
| - UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableReceiveBuffer",
|
| - actual_size, 1000, 1000000, 50);
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS(
|
| + "Net.SocketUnchangeableReceiveBuffer", actual_size, 1000, 1000000, 50);
|
| return ERR_SOCKET_RECEIVE_BUFFER_SIZE_UNCHANGEABLE;
|
| }
|
|
|
| int UDPSocketWin::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));
|
| if (rv != 0)
|
| return MapSystemError(WSAGetLastError());
|
| // According to documentation, setsockopt may succeed, but we need to check
|
| // the results via getsockopt to be sure it works on Windows.
|
| int32 actual_size = 0;
|
| int option_size = sizeof(actual_size);
|
| - rv = getsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
|
| - reinterpret_cast<char*>(&actual_size), &option_size);
|
| + rv = getsockopt(socket_,
|
| + SOL_SOCKET,
|
| + SO_SNDBUF,
|
| + reinterpret_cast<char*>(&actual_size),
|
| + &option_size);
|
| if (rv != 0)
|
| return MapSystemError(WSAGetLastError());
|
| if (actual_size >= size)
|
| return OK;
|
| - UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableSendBuffer",
|
| - actual_size, 1000, 1000000, 50);
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS(
|
| + "Net.SocketUnchangeableSendBuffer", actual_size, 1000, 1000000, 50);
|
| return ERR_SOCKET_SEND_BUFFER_SIZE_UNCHANGEABLE;
|
| }
|
|
|
| @@ -467,8 +477,8 @@ void UDPSocketWin::DoWriteCallback(int rv) {
|
|
|
| void UDPSocketWin::DidCompleteRead() {
|
| DWORD num_bytes, flags;
|
| - BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_,
|
| - &num_bytes, FALSE, &flags);
|
| + BOOL ok = WSAGetOverlappedResult(
|
| + socket_, &core_->read_overlapped_, &num_bytes, FALSE, &flags);
|
| WSAResetEvent(core_->read_overlapped_.hEvent);
|
| int result = ok ? num_bytes : MapSystemError(WSAGetLastError());
|
| // Convert address.
|
| @@ -492,11 +502,9 @@ void UDPSocketWin::LogRead(int result, const char* bytes) const {
|
| // Get address for logging, if |address| is NULL.
|
| IPEndPoint address;
|
| bool is_address_valid = ReceiveAddressToIPEndpoint(&address);
|
| - net_log_.AddEvent(
|
| - NetLog::TYPE_UDP_BYTES_RECEIVED,
|
| - CreateNetLogUDPDataTranferCallback(
|
| - result, bytes,
|
| - is_address_valid ? &address : NULL));
|
| + net_log_.AddEvent(NetLog::TYPE_UDP_BYTES_RECEIVED,
|
| + CreateNetLogUDPDataTranferCallback(
|
| + result, bytes, is_address_valid ? &address : NULL));
|
| }
|
|
|
| base::StatsCounter read_bytes("udp.read_bytes");
|
| @@ -505,8 +513,8 @@ void UDPSocketWin::LogRead(int result, const char* bytes) const {
|
|
|
| void UDPSocketWin::DidCompleteWrite() {
|
| 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);
|
| int result = ok ? num_bytes : MapSystemError(WSAGetLastError());
|
| LogWrite(result, core_->write_iobuffer_->data(), send_to_address_.get());
|
| @@ -534,7 +542,8 @@ void UDPSocketWin::LogWrite(int result,
|
| write_bytes.Add(result);
|
| }
|
|
|
| -int UDPSocketWin::InternalRecvFrom(IOBuffer* buf, int buf_len,
|
| +int UDPSocketWin::InternalRecvFrom(IOBuffer* buf,
|
| + int buf_len,
|
| IPEndPoint* address) {
|
| DCHECK(!core_->read_iobuffer_);
|
| SockaddrStorage& storage = core_->recv_addr_storage_;
|
| @@ -548,8 +557,15 @@ int UDPSocketWin::InternalRecvFrom(IOBuffer* buf, int buf_len,
|
| DWORD num;
|
| CHECK_NE(INVALID_SOCKET, socket_);
|
| AssertEventNotSignaled(core_->read_overlapped_.hEvent);
|
| - int rv = WSARecvFrom(socket_, &read_buffer, 1, &num, &flags, storage.addr,
|
| - &storage.addr_len, &core_->read_overlapped_, NULL);
|
| + int rv = WSARecvFrom(socket_,
|
| + &read_buffer,
|
| + 1,
|
| + &num,
|
| + &flags,
|
| + storage.addr,
|
| + &storage.addr_len,
|
| + &core_->read_overlapped_,
|
| + NULL);
|
| if (rv == 0) {
|
| if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) {
|
| int result = num;
|
| @@ -574,7 +590,8 @@ int UDPSocketWin::InternalRecvFrom(IOBuffer* buf, int buf_len,
|
| return ERR_IO_PENDING;
|
| }
|
|
|
| -int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len,
|
| +int UDPSocketWin::InternalSendTo(IOBuffer* buf,
|
| + int buf_len,
|
| const IPEndPoint* address) {
|
| DCHECK(!core_->write_iobuffer_);
|
| SockaddrStorage storage;
|
| @@ -598,8 +615,15 @@ int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len,
|
| DWORD flags = 0;
|
| DWORD num;
|
| AssertEventNotSignaled(core_->write_overlapped_.hEvent);
|
| - int rv = WSASendTo(socket_, &write_buffer, 1, &num, flags,
|
| - addr, storage.addr_len, &core_->write_overlapped_, NULL);
|
| + int rv = WSASendTo(socket_,
|
| + &write_buffer,
|
| + 1,
|
| + &num,
|
| + flags,
|
| + addr,
|
| + storage.addr_len,
|
| + &core_->write_overlapped_,
|
| + NULL);
|
| if (rv == 0) {
|
| if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) {
|
| int result = num;
|
| @@ -623,14 +647,18 @@ int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len,
|
| int UDPSocketWin::SetSocketOptions() {
|
| BOOL true_value = 1;
|
| if (socket_options_ & SOCKET_OPTION_REUSE_ADDRESS) {
|
| - int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
|
| + int rv = setsockopt(socket_,
|
| + SOL_SOCKET,
|
| + SO_REUSEADDR,
|
| reinterpret_cast<const char*>(&true_value),
|
| sizeof(true_value));
|
| if (rv < 0)
|
| return MapSystemError(WSAGetLastError());
|
| }
|
| if (socket_options_ & SOCKET_OPTION_BROADCAST) {
|
| - int rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST,
|
| + int rv = setsockopt(socket_,
|
| + SOL_SOCKET,
|
| + SO_BROADCAST,
|
| reinterpret_cast<const char*>(&true_value),
|
| sizeof(true_value));
|
| if (rv < 0)
|
| @@ -638,23 +666,27 @@ int UDPSocketWin::SetSocketOptions() {
|
| }
|
| if (!(socket_options_ & SOCKET_OPTION_MULTICAST_LOOP)) {
|
| DWORD loop = 0;
|
| - int protocol_level =
|
| - addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| + int protocol_level = addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| int option =
|
| - addr_family_ == AF_INET ? IP_MULTICAST_LOOP: IPV6_MULTICAST_LOOP;
|
| - int rv = setsockopt(socket_, protocol_level, option,
|
| - reinterpret_cast<const char*>(&loop), sizeof(loop));
|
| + addr_family_ == AF_INET ? IP_MULTICAST_LOOP : IPV6_MULTICAST_LOOP;
|
| + int rv = setsockopt(socket_,
|
| + protocol_level,
|
| + option,
|
| + reinterpret_cast<const char*>(&loop),
|
| + sizeof(loop));
|
| if (rv < 0)
|
| return MapSystemError(WSAGetLastError());
|
| }
|
| if (multicast_time_to_live_ != 1) {
|
| DWORD hops = multicast_time_to_live_;
|
| - int protocol_level =
|
| - addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| + int protocol_level = addr_family_ == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
| int option =
|
| - addr_family_ == AF_INET ? IP_MULTICAST_TTL: IPV6_MULTICAST_HOPS;
|
| - int rv = setsockopt(socket_, protocol_level, option,
|
| - reinterpret_cast<const char*>(&hops), sizeof(hops));
|
| + addr_family_ == AF_INET ? IP_MULTICAST_TTL : IPV6_MULTICAST_HOPS;
|
| + int rv = setsockopt(socket_,
|
| + protocol_level,
|
| + option,
|
| + reinterpret_cast<const char*>(&hops),
|
| + sizeof(hops));
|
| if (rv < 0)
|
| return MapSystemError(WSAGetLastError());
|
| }
|
| @@ -663,7 +695,9 @@ int UDPSocketWin::SetSocketOptions() {
|
| case AF_INET: {
|
| in_addr address;
|
| address.s_addr = htonl(multicast_interface_);
|
| - int rv = setsockopt(socket_, IPPROTO_IP, IP_MULTICAST_IF,
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IP,
|
| + IP_MULTICAST_IF,
|
| reinterpret_cast<const char*>(&address),
|
| sizeof(address));
|
| if (rv)
|
| @@ -672,7 +706,9 @@ int UDPSocketWin::SetSocketOptions() {
|
| }
|
| case AF_INET6: {
|
| uint32 interface_index = multicast_interface_;
|
| - int rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_MULTICAST_IF,
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IPV6,
|
| + IPV6_MULTICAST_IF,
|
| reinterpret_cast<const char*>(&interface_index),
|
| sizeof(interface_index));
|
| if (rv)
|
| @@ -711,8 +747,8 @@ int UDPSocketWin::RandomBind(const IPAddressNumber& address) {
|
| DCHECK(bind_type_ == DatagramSocket::RANDOM_BIND && !rand_int_cb_.is_null());
|
|
|
| for (int i = 0; i < kBindRetries; ++i) {
|
| - int rv = DoBind(IPEndPoint(address,
|
| - rand_int_cb_.Run(kPortStart, kPortEnd)));
|
| + int rv =
|
| + DoBind(IPEndPoint(address, rand_int_cb_.Run(kPortStart, kPortEnd)));
|
| if (rv == OK || rv != ERR_ADDRESS_IN_USE)
|
| return rv;
|
| }
|
| @@ -724,8 +760,7 @@ bool UDPSocketWin::ReceiveAddressToIPEndpoint(IPEndPoint* address) const {
|
| return address->FromSockAddr(storage.addr, storage.addr_len);
|
| }
|
|
|
| -int UDPSocketWin::JoinGroup(
|
| - const IPAddressNumber& group_address) const {
|
| +int UDPSocketWin::JoinGroup(const IPAddressNumber& group_address) const {
|
| DCHECK(CalledOnValidThread());
|
| if (!is_connected())
|
| return ERR_SOCKET_NOT_CONNECTED;
|
| @@ -737,7 +772,9 @@ int UDPSocketWin::JoinGroup(
|
| ip_mreq mreq;
|
| mreq.imr_interface.s_addr = htonl(multicast_interface_);
|
| memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
|
| - int rv = setsockopt(socket_, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IP,
|
| + IP_ADD_MEMBERSHIP,
|
| reinterpret_cast<const char*>(&mreq),
|
| sizeof(mreq));
|
| if (rv)
|
| @@ -750,7 +787,9 @@ int UDPSocketWin::JoinGroup(
|
| ipv6_mreq mreq;
|
| mreq.ipv6mr_interface = multicast_interface_;
|
| memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
|
| - int rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IPV6,
|
| + IPV6_ADD_MEMBERSHIP,
|
| reinterpret_cast<const char*>(&mreq),
|
| sizeof(mreq));
|
| if (rv)
|
| @@ -763,8 +802,7 @@ int UDPSocketWin::JoinGroup(
|
| }
|
| }
|
|
|
| -int UDPSocketWin::LeaveGroup(
|
| - const IPAddressNumber& group_address) const {
|
| +int UDPSocketWin::LeaveGroup(const IPAddressNumber& group_address) const {
|
| DCHECK(CalledOnValidThread());
|
| if (!is_connected())
|
| return ERR_SOCKET_NOT_CONNECTED;
|
| @@ -776,8 +814,11 @@ int UDPSocketWin::LeaveGroup(
|
| ip_mreq mreq;
|
| mreq.imr_interface.s_addr = htonl(multicast_interface_);
|
| memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
|
| - int rv = setsockopt(socket_, IPPROTO_IP, IP_DROP_MEMBERSHIP,
|
| - reinterpret_cast<const char*>(&mreq), sizeof(mreq));
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IP,
|
| + IP_DROP_MEMBERSHIP,
|
| + reinterpret_cast<const char*>(&mreq),
|
| + sizeof(mreq));
|
| if (rv)
|
| return MapSystemError(WSAGetLastError());
|
| return OK;
|
| @@ -788,8 +829,11 @@ int UDPSocketWin::LeaveGroup(
|
| ipv6_mreq mreq;
|
| mreq.ipv6mr_interface = multicast_interface_;
|
| memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
|
| - int rv = setsockopt(socket_, IPPROTO_IPV6, IP_DROP_MEMBERSHIP,
|
| - reinterpret_cast<const char*>(&mreq), sizeof(mreq));
|
| + int rv = setsockopt(socket_,
|
| + IPPROTO_IPV6,
|
| + IP_DROP_MEMBERSHIP,
|
| + reinterpret_cast<const char*>(&mreq),
|
| + sizeof(mreq));
|
| if (rv)
|
| return MapSystemError(WSAGetLastError());
|
| return OK;
|
|
|