| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/tcp_server_socket_win.h" | 5 #include "net/socket/tcp_server_socket_win.h" |
| 6 | 6 |
| 7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
| 8 | 8 |
| 9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 PLOG(ERROR) << "socket() returned an error"; | 49 PLOG(ERROR) << "socket() returned an error"; |
| 50 return MapSystemError(WSAGetLastError()); | 50 return MapSystemError(WSAGetLastError()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 if (SetNonBlocking(socket_)) { | 53 if (SetNonBlocking(socket_)) { |
| 54 int result = MapSystemError(WSAGetLastError()); | 54 int result = MapSystemError(WSAGetLastError()); |
| 55 Close(); | 55 Close(); |
| 56 return result; | 56 return result; |
| 57 } | 57 } |
| 58 | 58 |
| 59 int result = SetSocketOptions(); |
| 60 if (result < 0) { |
| 61 return result; |
| 62 } |
| 63 |
| 59 SockaddrStorage storage; | 64 SockaddrStorage storage; |
| 60 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 65 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
| 61 return ERR_INVALID_ARGUMENT; | 66 return ERR_INVALID_ARGUMENT; |
| 62 | 67 |
| 63 int result = bind(socket_, storage.addr, storage.addr_len); | 68 result = bind(socket_, storage.addr, storage.addr_len); |
| 64 if (result < 0) { | 69 if (result < 0) { |
| 65 PLOG(ERROR) << "bind() returned an error"; | 70 PLOG(ERROR) << "bind() returned an error"; |
| 66 result = MapSystemError(WSAGetLastError()); | 71 result = MapSystemError(WSAGetLastError()); |
| 67 Close(); | 72 Close(); |
| 68 return result; | 73 return result; |
| 69 } | 74 } |
| 70 | 75 |
| 71 result = listen(socket_, backlog); | 76 result = listen(socket_, backlog); |
| 72 if (result < 0) { | 77 if (result < 0) { |
| 73 PLOG(ERROR) << "listen() returned an error"; | 78 PLOG(ERROR) << "listen() returned an error"; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 int result = AcceptInternal(accept_socket_); | 178 int result = AcceptInternal(accept_socket_); |
| 174 if (result != ERR_IO_PENDING) { | 179 if (result != ERR_IO_PENDING) { |
| 175 accept_socket_ = NULL; | 180 accept_socket_ = NULL; |
| 176 CompletionCallback callback = accept_callback_; | 181 CompletionCallback callback = accept_callback_; |
| 177 accept_callback_.Reset(); | 182 accept_callback_.Reset(); |
| 178 callback.Run(result); | 183 callback.Run(result); |
| 179 } | 184 } |
| 180 } | 185 } |
| 181 } | 186 } |
| 182 | 187 |
| 188 void TCPServerSocketWin::AllowAddressReuse() { |
| 189 DCHECK(CalledOnValidThread()); |
| 190 DCHECK_EQ(socket_, INVALID_SOCKET); |
| 191 DCHECK_EQ(socket_event_, WSA_INVALID_EVENT); |
| 192 |
| 193 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; |
| 194 } |
| 195 |
| 196 int TCPServerSocketWin::SetSocketOptions() { |
| 197 int true_value = 1; |
| 198 if (socket_options_ & SOCKET_OPTION_REUSE_ADDRESS) { |
| 199 int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &true_value, |
| 200 sizeof(true_value)); |
| 201 if (rv < 0) |
| 202 return MapSystemError(errno); |
| 203 } |
| 204 return OK; |
| 205 } |
| 206 |
| 183 } // namespace net | 207 } // namespace net |
| OLD | NEW |