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"
11 FlipAcceptor::FlipAcceptor(enum FlipHandlerType flip_handler_type
,
12 std::string listen_ip
,
13 std::string listen_port
,
14 std::string ssl_cert_filename
,
15 std::string ssl_key_filename
,
16 std::string http_server_ip
,
17 std::string http_server_port
,
18 std::string https_server_ip
,
19 std::string https_server_port
,
21 int accept_backlog_size
,
27 : flip_handler_type_(flip_handler_type
),
28 listen_ip_(listen_ip
),
29 listen_port_(listen_port
),
30 ssl_cert_filename_(ssl_cert_filename
),
31 ssl_key_filename_(ssl_key_filename
),
32 http_server_ip_(http_server_ip
),
33 http_server_port_(http_server_port
),
34 https_server_ip_(https_server_ip
),
35 https_server_port_(https_server_port
),
36 spdy_only_(spdy_only
),
37 accept_backlog_size_(accept_backlog_size
),
38 disable_nagle_(disable_nagle
),
39 accepts_per_wake_(accepts_per_wake
),
40 memory_cache_(memory_cache
),
41 ssl_session_expiry_(300), // TODO(mbelshe): Hook these up!
42 ssl_disable_compression_(false),
43 idle_socket_timeout_s_(300) {
44 VLOG(1) << "Attempting to listen on " << listen_ip_
.c_str() << ":"
45 << listen_port_
.c_str();
46 if (!https_server_ip_
.size())
47 https_server_ip_
= http_server_ip_
;
48 if (!https_server_port_
.size())
49 https_server_port_
= http_server_port_
;
52 int ret
= CreateListeningSocket(listen_ip_
,
63 } else if (ret
== -3 && wait_for_iface
) {
64 // Binding error EADDRNOTAVAIL was encounted. We need
65 // to wait for the interfaces to raised. try again.
68 LOG(ERROR
) << "Unable to create listening socket for: ret = " << ret
69 << ": " << listen_ip_
.c_str() << ":" << listen_port_
.c_str();
74 FlipSetNonBlocking(listen_fd_
);
75 VLOG(1) << "Listening on socket: ";
76 if (flip_handler_type
== FLIP_HANDLER_PROXY
)
77 VLOG(1) << "\tType : Proxy";
78 else if (FLIP_HANDLER_SPDY_SERVER
)
79 VLOG(1) << "\tType : SPDY Server";
80 else if (FLIP_HANDLER_HTTP_SERVER
)
81 VLOG(1) << "\tType : HTTP Server";
82 VLOG(1) << "\tIP : " << listen_ip_
;
83 VLOG(1) << "\tPort : " << listen_port_
;
84 VLOG(1) << "\tHTTP Server : " << http_server_ip_
<< ":" << http_server_port_
;
85 VLOG(1) << "\tHTTPS Server : " << https_server_ip_
<< ":"
86 << https_server_port_
;
87 VLOG(1) << "\tSSL : " << (ssl_cert_filename
.size() ? "true"
89 VLOG(1) << "\tCertificate : " << ssl_cert_filename
;
90 VLOG(1) << "\tKey : " << ssl_key_filename
;
91 VLOG(1) << "\tSpdy Only : " << (spdy_only
? "true" : "false");
94 FlipAcceptor::~FlipAcceptor() {}
96 FlipConfig::FlipConfig()
97 : server_think_time_in_s_(0),
98 log_destination_(logging::LOG_TO_SYSTEM_DEBUG_LOG
),
99 wait_for_iface_(false) {}
101 FlipConfig::~FlipConfig() {}
103 void FlipConfig::AddAcceptor(enum FlipHandlerType flip_handler_type
,
104 std::string listen_ip
,
105 std::string listen_port
,
106 std::string ssl_cert_filename
,
107 std::string ssl_key_filename
,
108 std::string http_server_ip
,
109 std::string http_server_port
,
110 std::string https_server_ip
,
111 std::string https_server_port
,
113 int accept_backlog_size
,
115 int accepts_per_wake
,
118 void* memory_cache
) {
119 // TODO(mbelshe): create a struct FlipConfigArgs{} for the arguments.
120 acceptors_
.push_back(new FlipAcceptor(flip_handler_type
,