Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / tools / flip_server / flip_config.cc
blobd0647ae06c5390ca321f64935e1bb0c0e9228a90
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.
5 #include "net/tools/flip_server/flip_config.h"
7 #include <unistd.h>
9 #include "net/tools/flip_server/create_listener.h"
11 namespace net {
13 FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type,
14 std::string listen_ip,
15 std::string listen_port,
16 std::string ssl_cert_filename,
17 std::string ssl_key_filename,
18 std::string http_server_ip,
19 std::string http_server_port,
20 std::string https_server_ip,
21 std::string https_server_port,
22 int spdy_only,
23 int accept_backlog_size,
24 bool disable_nagle,
25 int accepts_per_wake,
26 bool reuseport,
27 bool wait_for_iface,
28 void* memory_cache)
29 : flip_handler_type_(flip_handler_type),
30 listen_ip_(listen_ip),
31 listen_port_(listen_port),
32 ssl_cert_filename_(ssl_cert_filename),
33 ssl_key_filename_(ssl_key_filename),
34 http_server_ip_(http_server_ip),
35 http_server_port_(http_server_port),
36 https_server_ip_(https_server_ip),
37 https_server_port_(https_server_port),
38 spdy_only_(spdy_only),
39 accept_backlog_size_(accept_backlog_size),
40 disable_nagle_(disable_nagle),
41 accepts_per_wake_(accepts_per_wake),
42 memory_cache_(memory_cache),
43 ssl_session_expiry_(300), // TODO(mbelshe): Hook these up!
44 ssl_disable_compression_(false),
45 idle_socket_timeout_s_(300) {
46 VLOG(1) << "Attempting to listen on " << listen_ip_.c_str() << ":"
47 << listen_port_.c_str();
48 if (!https_server_ip_.size())
49 https_server_ip_ = http_server_ip_;
50 if (!https_server_port_.size())
51 https_server_port_ = http_server_port_;
53 while (1) {
54 int ret = CreateListeningSocket(listen_ip_,
55 listen_port_,
56 true,
57 accept_backlog_size_,
58 true,
59 reuseport,
60 wait_for_iface,
61 disable_nagle_,
62 &listen_fd_);
63 if (ret == 0) {
64 break;
65 } else if (ret == -3 && wait_for_iface) {
66 // Binding error EADDRNOTAVAIL was encounted. We need
67 // to wait for the interfaces to raised. try again.
68 usleep(200000);
69 } else {
70 LOG(ERROR) << "Unable to create listening socket for: ret = " << ret
71 << ": " << listen_ip_.c_str() << ":" << listen_port_.c_str();
72 return;
76 FlipSetNonBlocking(listen_fd_);
77 VLOG(1) << "Listening on socket: ";
78 if (flip_handler_type == FLIP_HANDLER_PROXY)
79 VLOG(1) << "\tType : Proxy";
80 else if (FLIP_HANDLER_SPDY_SERVER)
81 VLOG(1) << "\tType : SPDY Server";
82 else if (FLIP_HANDLER_HTTP_SERVER)
83 VLOG(1) << "\tType : HTTP Server";
84 VLOG(1) << "\tIP : " << listen_ip_;
85 VLOG(1) << "\tPort : " << listen_port_;
86 VLOG(1) << "\tHTTP Server : " << http_server_ip_ << ":" << http_server_port_;
87 VLOG(1) << "\tHTTPS Server : " << https_server_ip_ << ":"
88 << https_server_port_;
89 VLOG(1) << "\tSSL : " << (ssl_cert_filename.size() ? "true"
90 : "false");
91 VLOG(1) << "\tCertificate : " << ssl_cert_filename;
92 VLOG(1) << "\tKey : " << ssl_key_filename;
93 VLOG(1) << "\tSpdy Only : " << (spdy_only ? "true" : "false");
96 FlipAcceptor::~FlipAcceptor() {}
98 FlipConfig::FlipConfig()
99 : server_think_time_in_s_(0),
100 log_destination_(logging::LOG_TO_SYSTEM_DEBUG_LOG),
101 wait_for_iface_(false) {}
103 FlipConfig::~FlipConfig() {}
105 void FlipConfig::AddAcceptor(enum FlipHandlerType flip_handler_type,
106 std::string listen_ip,
107 std::string listen_port,
108 std::string ssl_cert_filename,
109 std::string ssl_key_filename,
110 std::string http_server_ip,
111 std::string http_server_port,
112 std::string https_server_ip,
113 std::string https_server_port,
114 int spdy_only,
115 int accept_backlog_size,
116 bool disable_nagle,
117 int accepts_per_wake,
118 bool reuseport,
119 bool wait_for_iface,
120 void* memory_cache) {
121 // TODO(mbelshe): create a struct FlipConfigArgs{} for the arguments.
122 acceptors_.push_back(new FlipAcceptor(flip_handler_type,
123 listen_ip,
124 listen_port,
125 ssl_cert_filename,
126 ssl_key_filename,
127 http_server_ip,
128 http_server_port,
129 https_server_ip,
130 https_server_port,
131 spdy_only,
132 accept_backlog_size,
133 disable_nagle,
134 accepts_per_wake,
135 reuseport,
136 wait_for_iface,
137 memory_cache));
140 } // namespace net