| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 40 const SOCKET ListenSocket::kInvalidSocket = INVALID_SOCKET; | 40 const SOCKET ListenSocket::kInvalidSocket = INVALID_SOCKET; |
| 41 const int ListenSocket::kSocketError = SOCKET_ERROR; | 41 const int ListenSocket::kSocketError = SOCKET_ERROR; |
| 42 #elif defined(OS_POSIX) | 42 #elif defined(OS_POSIX) |
| 43 const SOCKET ListenSocket::kInvalidSocket = -1; | 43 const SOCKET ListenSocket::kInvalidSocket = -1; |
| 44 const int ListenSocket::kSocketError = -1; | 44 const int ListenSocket::kSocketError = -1; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 ListenSocket* ListenSocket::Listen(std::string ip, int port, | 47 ListenSocket* ListenSocket::Listen(std::string ip, int port, |
| 48 ListenSocketDelegate* del) { | 48 ListenSocketDelegate* del) { |
| 49 SOCKET s = Listen(ip, port); | 49 SOCKET s = Listen(ip, port, del->protocol()); |
| 50 if (s == kInvalidSocket) { | 50 if (s == kInvalidSocket) { |
| 51 // TODO(erikkay): error handling | 51 // TODO(erikkay): error handling |
| 52 } else { | 52 } else { |
| 53 ListenSocket* sock = new ListenSocket(s, del); | 53 ListenSocket* sock = new ListenSocket(s, del); |
| 54 sock->Listen(); | 54 sock->Listen(); |
| 55 return sock; | 55 return sock; |
| 56 } | 56 } |
| 57 return NULL; | 57 return NULL; |
| 58 } | 58 } |
| 59 | 59 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 ListenSocket::~ListenSocket() { | 97 ListenSocket::~ListenSocket() { |
| 98 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 99 if (socket_event_) { | 99 if (socket_event_) { |
| 100 WSACloseEvent(socket_event_); | 100 WSACloseEvent(socket_event_); |
| 101 socket_event_ = WSA_INVALID_EVENT; | 101 socket_event_ = WSA_INVALID_EVENT; |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 CloseSocket(socket_); | 104 CloseSocket(socket_); |
| 105 } | 105 } |
| 106 | 106 |
| 107 SOCKET ListenSocket::Listen(std::string ip, int port) { | 107 SOCKET ListenSocket::Listen(std::string ip, int port, int protocol) { |
| 108 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 108 SOCKET s = socket(AF_INET, SOCK_STREAM, protocol); |
| 109 if (s != kInvalidSocket) { | 109 if (s != kInvalidSocket) { |
| 110 #if defined(OS_POSIX) | 110 #if defined(OS_POSIX) |
| 111 // Allow rapid reuse. | 111 // Allow rapid reuse. |
| 112 static const int kOn = 1; | 112 static const int kOn = 1; |
| 113 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn)); | 113 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn)); |
| 114 #endif | 114 #endif |
| 115 sockaddr_in addr; | 115 sockaddr_in addr; |
| 116 memset(&addr, 0, sizeof(addr)); | 116 memset(&addr, 0, sizeof(addr)); |
| 117 addr.sin_family = AF_INET; | 117 addr.sin_family = AF_INET; |
| 118 addr.sin_addr.s_addr = inet_addr(ip.c_str()); | 118 addr.sin_addr.s_addr = inet_addr(ip.c_str()); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) { | 319 void ListenSocket::OnFileCanWriteWithoutBlocking(int fd) { |
| 320 // MessagePumpLibevent callback, we don't listen for write events | 320 // MessagePumpLibevent callback, we don't listen for write events |
| 321 // so we shouldn't ever reach here. | 321 // so we shouldn't ever reach here. |
| 322 NOTREACHED(); | 322 NOTREACHED(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 #endif | 325 #endif |
| OLD | NEW |