| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/tools/flip_server/flip_config.h" | |
| 6 | |
| 7 #include <unistd.h> | |
| 8 | |
| 9 #include "base/files/file_util.h" | |
| 10 #include "net/tools/flip_server/tcp_socket_util.h" | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type, | |
| 15 std::string listen_ip, | |
| 16 std::string listen_port, | |
| 17 std::string ssl_cert_filename, | |
| 18 std::string ssl_key_filename, | |
| 19 std::string http_server_ip, | |
| 20 std::string http_server_port, | |
| 21 std::string https_server_ip, | |
| 22 std::string https_server_port, | |
| 23 int spdy_only, | |
| 24 int accept_backlog_size, | |
| 25 bool disable_nagle, | |
| 26 int accepts_per_wake, | |
| 27 bool reuseport, | |
| 28 bool wait_for_iface, | |
| 29 void* memory_cache) | |
| 30 : flip_handler_type_(flip_handler_type), | |
| 31 listen_ip_(listen_ip), | |
| 32 listen_port_(listen_port), | |
| 33 ssl_cert_filename_(ssl_cert_filename), | |
| 34 ssl_key_filename_(ssl_key_filename), | |
| 35 http_server_ip_(http_server_ip), | |
| 36 http_server_port_(http_server_port), | |
| 37 https_server_ip_(https_server_ip), | |
| 38 https_server_port_(https_server_port), | |
| 39 spdy_only_(spdy_only), | |
| 40 accept_backlog_size_(accept_backlog_size), | |
| 41 disable_nagle_(disable_nagle), | |
| 42 accepts_per_wake_(accepts_per_wake), | |
| 43 memory_cache_(memory_cache), | |
| 44 ssl_session_expiry_(300), // TODO(mbelshe): Hook these up! | |
| 45 ssl_disable_compression_(false), | |
| 46 idle_socket_timeout_s_(300) { | |
| 47 VLOG(1) << "Attempting to listen on " << listen_ip_.c_str() << ":" | |
| 48 << listen_port_.c_str(); | |
| 49 if (https_server_ip_.empty()) | |
| 50 https_server_ip_ = http_server_ip_; | |
| 51 if (https_server_port_.empty()) | |
| 52 https_server_port_ = http_server_port_; | |
| 53 | |
| 54 while (1) { | |
| 55 int ret = CreateTCPServerSocket(listen_ip_, | |
| 56 listen_port_, | |
| 57 true, | |
| 58 accept_backlog_size_, | |
| 59 true, | |
| 60 reuseport, | |
| 61 wait_for_iface, | |
| 62 disable_nagle_, | |
| 63 &listen_fd_); | |
| 64 if (ret == 0) | |
| 65 break; | |
| 66 | |
| 67 if (ret == -3 && !wait_for_iface) { | |
| 68 // -3 means binding error EADDRNOTAVAIL was encountered. We need to wait | |
| 69 // for the interfaces to come up and then try again. | |
| 70 usleep(200000); | |
| 71 continue; | |
| 72 } | |
| 73 | |
| 74 LOG(ERROR) << "Unable to create listening socket for: ret = " << ret << ": " | |
| 75 << listen_ip_.c_str() << ":" << listen_port_.c_str(); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 if (!base::SetNonBlocking(listen_fd_)) { | |
| 80 LOG(FATAL) << "base::SetNonBlocking() failed: " << listen_fd_; | |
| 81 } | |
| 82 | |
| 83 VLOG(1) << "Listening on socket: "; | |
| 84 if (flip_handler_type == FLIP_HANDLER_PROXY) | |
| 85 VLOG(1) << "\tType : Proxy"; | |
| 86 else if (FLIP_HANDLER_SPDY_SERVER) | |
| 87 VLOG(1) << "\tType : SPDY Server"; | |
| 88 else if (FLIP_HANDLER_HTTP_SERVER) | |
| 89 VLOG(1) << "\tType : HTTP Server"; | |
| 90 VLOG(1) << "\tIP : " << listen_ip_; | |
| 91 VLOG(1) << "\tPort : " << listen_port_; | |
| 92 VLOG(1) << "\tHTTP Server : " << http_server_ip_ << ":" << http_server_port_; | |
| 93 VLOG(1) << "\tHTTPS Server : " << https_server_ip_ << ":" | |
| 94 << https_server_port_; | |
| 95 VLOG(1) << "\tSSL : " << (ssl_cert_filename.size() ? "true" | |
| 96 : "false"); | |
| 97 VLOG(1) << "\tCertificate : " << ssl_cert_filename; | |
| 98 VLOG(1) << "\tKey : " << ssl_key_filename; | |
| 99 VLOG(1) << "\tSpdy Only : " << (spdy_only ? "true" : "false"); | |
| 100 } | |
| 101 | |
| 102 FlipAcceptor::~FlipAcceptor() {} | |
| 103 | |
| 104 FlipConfig::FlipConfig() | |
| 105 : server_think_time_in_s_(0), | |
| 106 log_destination_(logging::LOG_TO_SYSTEM_DEBUG_LOG), | |
| 107 wait_for_iface_(false) {} | |
| 108 | |
| 109 FlipConfig::~FlipConfig() {} | |
| 110 | |
| 111 void FlipConfig::AddAcceptor(enum FlipHandlerType flip_handler_type, | |
| 112 std::string listen_ip, | |
| 113 std::string listen_port, | |
| 114 std::string ssl_cert_filename, | |
| 115 std::string ssl_key_filename, | |
| 116 std::string http_server_ip, | |
| 117 std::string http_server_port, | |
| 118 std::string https_server_ip, | |
| 119 std::string https_server_port, | |
| 120 int spdy_only, | |
| 121 int accept_backlog_size, | |
| 122 bool disable_nagle, | |
| 123 int accepts_per_wake, | |
| 124 bool reuseport, | |
| 125 bool wait_for_iface, | |
| 126 void* memory_cache) { | |
| 127 // TODO(mbelshe): create a struct FlipConfigArgs{} for the arguments. | |
| 128 acceptors_.push_back(new FlipAcceptor(flip_handler_type, | |
| 129 listen_ip, | |
| 130 listen_port, | |
| 131 ssl_cert_filename, | |
| 132 ssl_key_filename, | |
| 133 http_server_ip, | |
| 134 http_server_port, | |
| 135 https_server_ip, | |
| 136 https_server_port, | |
| 137 spdy_only, | |
| 138 accept_backlog_size, | |
| 139 disable_nagle, | |
| 140 accepts_per_wake, | |
| 141 reuseport, | |
| 142 wait_for_iface, | |
| 143 memory_cache)); | |
| 144 } | |
| 145 | |
| 146 } // namespace net | |
| OLD | NEW |