OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 // winsock2.h must be included first in order to ensure it is included before | 8 // winsock2.h must be included first in order to ensure it is included before |
9 // windows.h. | 9 // windows.h. |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
11 #elif defined(OS_POSIX) | 11 #elif defined(OS_POSIX) |
12 #include <errno.h> | 12 #include <errno.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
15 #include <netinet/in.h> | 15 #include <netinet/in.h> |
16 #include <arpa/inet.h> | 16 #include <arpa/inet.h> |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #endif | 18 #endif |
19 | 19 |
20 #include "base/eintr_wrapper.h" | 20 #include "base/eintr_wrapper.h" |
| 21 #include "base/sys_byteorder.h" |
21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
23 #include "net/base/listen_socket.h" | 24 #include "net/base/listen_socket.h" |
24 | 25 |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 typedef int socklen_t; | 27 typedef int socklen_t; |
27 #endif // defined(OS_WIN) | 28 #endif // defined(OS_WIN) |
28 | 29 |
29 namespace net { | 30 namespace net { |
30 | 31 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (s != kInvalidSocket) { | 110 if (s != kInvalidSocket) { |
110 #if defined(OS_POSIX) | 111 #if defined(OS_POSIX) |
111 // Allow rapid reuse. | 112 // Allow rapid reuse. |
112 static const int kOn = 1; | 113 static const int kOn = 1; |
113 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn)); | 114 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn)); |
114 #endif | 115 #endif |
115 sockaddr_in addr; | 116 sockaddr_in addr; |
116 memset(&addr, 0, sizeof(addr)); | 117 memset(&addr, 0, sizeof(addr)); |
117 addr.sin_family = AF_INET; | 118 addr.sin_family = AF_INET; |
118 addr.sin_addr.s_addr = inet_addr(ip.c_str()); | 119 addr.sin_addr.s_addr = inet_addr(ip.c_str()); |
119 addr.sin_port = htons(port); | 120 addr.sin_port = base::HostToNet16(port); |
120 if (bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr))) { | 121 if (bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr))) { |
121 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
122 closesocket(s); | 123 closesocket(s); |
123 #elif defined(OS_POSIX) | 124 #elif defined(OS_POSIX) |
124 close(s); | 125 close(s); |
125 #endif | 126 #endif |
126 s = kInvalidSocket; | 127 s = kInvalidSocket; |
127 } | 128 } |
128 } | 129 } |
129 return s; | 130 return s; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 323 |
323 void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) { | 324 void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) { |
324 // MessagePumpLibevent callback, we don't listen for write events | 325 // MessagePumpLibevent callback, we don't listen for write events |
325 // so we shouldn't ever reach here. | 326 // so we shouldn't ever reach here. |
326 NOTREACHED(); | 327 NOTREACHED(); |
327 } | 328 } |
328 | 329 |
329 #endif | 330 #endif |
330 | 331 |
331 } // namespace net | 332 } // namespace net |
OLD | NEW |