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"
9 #include "net/tools/flip_server/create_listener.h"
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
,
23 int accept_backlog_size
,
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_
;
54 int ret
= CreateListeningSocket(listen_ip_
,
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.
70 LOG(ERROR
) << "Unable to create listening socket for: ret = " << ret
71 << ": " << listen_ip_
.c_str() << ":" << listen_port_
.c_str();
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"
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
,
115 int accept_backlog_size
,
117 int accepts_per_wake
,
120 void* memory_cache
) {
121 // TODO(mbelshe): create a struct FlipConfigArgs{} for the arguments.
122 acceptors_
.push_back(new FlipAcceptor(flip_handler_type
,