| 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_libevent.h" | 5 #include "net/socket/tcp_server_socket_libevent.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <netdb.h> | 9 #include <netdb.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 PLOG(ERROR) << "socket() returned an error"; | 56 PLOG(ERROR) << "socket() returned an error"; |
| 57 return MapSystemError(errno); | 57 return MapSystemError(errno); |
| 58 } | 58 } |
| 59 | 59 |
| 60 if (SetNonBlocking(socket_)) { | 60 if (SetNonBlocking(socket_)) { |
| 61 int result = MapSystemError(errno); | 61 int result = MapSystemError(errno); |
| 62 Close(); | 62 Close(); |
| 63 return result; | 63 return result; |
| 64 } | 64 } |
| 65 | 65 |
| 66 int optval = 1; |
| 67 setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); |
| 68 |
| 66 SockaddrStorage storage; | 69 SockaddrStorage storage; |
| 67 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 70 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
| 68 return ERR_INVALID_ARGUMENT; | 71 return ERR_INVALID_ARGUMENT; |
| 69 | 72 |
| 70 int result = bind(socket_, storage.addr, storage.addr_len); | 73 int result = bind(socket_, storage.addr, storage.addr_len); |
| 71 if (result < 0) { | 74 if (result < 0) { |
| 72 PLOG(ERROR) << "bind() returned an error"; | 75 PLOG(ERROR) << "bind() returned an error"; |
| 73 result = MapSystemError(errno); | 76 result = MapSystemError(errno); |
| 74 Close(); | 77 Close(); |
| 75 return result; | 78 return result; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 accept_callback_.Reset(); | 187 accept_callback_.Reset(); |
| 185 callback.Run(result); | 188 callback.Run(result); |
| 186 } | 189 } |
| 187 } | 190 } |
| 188 | 191 |
| 189 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) { | 192 void TCPServerSocketLibevent::OnFileCanWriteWithoutBlocking(int fd) { |
| 190 NOTREACHED(); | 193 NOTREACHED(); |
| 191 } | 194 } |
| 192 | 195 |
| 193 } // namespace net | 196 } // namespace net |
| OLD | NEW |