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 optval = 1; |
| 60 setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); |
| 61 |
59 SockaddrStorage storage; | 62 SockaddrStorage storage; |
60 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 63 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
61 return ERR_INVALID_ARGUMENT; | 64 return ERR_INVALID_ARGUMENT; |
62 | 65 |
63 int result = bind(socket_, storage.addr, storage.addr_len); | 66 int result = bind(socket_, storage.addr, storage.addr_len); |
64 if (result < 0) { | 67 if (result < 0) { |
65 PLOG(ERROR) << "bind() returned an error"; | 68 PLOG(ERROR) << "bind() returned an error"; |
66 result = MapSystemError(WSAGetLastError()); | 69 result = MapSystemError(WSAGetLastError()); |
67 Close(); | 70 Close(); |
68 return result; | 71 return result; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (result != ERR_IO_PENDING) { | 177 if (result != ERR_IO_PENDING) { |
175 accept_socket_ = NULL; | 178 accept_socket_ = NULL; |
176 CompletionCallback callback = accept_callback_; | 179 CompletionCallback callback = accept_callback_; |
177 accept_callback_.Reset(); | 180 accept_callback_.Reset(); |
178 callback.Run(result); | 181 callback.Run(result); |
179 } | 182 } |
180 } | 183 } |
181 } | 184 } |
182 | 185 |
183 } // namespace net | 186 } // namespace net |
OLD | NEW |