| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <errno.h> | 5 #include <errno.h> | 
| 6 #include <signal.h> | 6 #include <signal.h> | 
|  | 7 #include <stdio.h> | 
| 7 #include <sys/file.h> | 8 #include <sys/file.h> | 
| 8 #include <sys/stat.h> | 9 #include <sys/stat.h> | 
| 9 | 10 | 
| 10 #include <iostream> |  | 
| 11 #include <string> | 11 #include <string> | 
| 12 #include <vector> | 12 #include <vector> | 
| 13 | 13 | 
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" | 
| 15 #include "base/logging.h" | 15 #include "base/logging.h" | 
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" | 
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" | 
| 18 #include "net/tools/balsa/split.h" | 18 #include "net/tools/balsa/split.h" | 
| 19 #include "net/tools/flip_server/acceptor_thread.h" | 19 #include "net/tools/flip_server/acceptor_thread.h" | 
| 20 #include "net/tools/flip_server/constants.h" | 20 #include "net/tools/flip_server/constants.h" | 
| 21 #include "net/tools/flip_server/flip_config.h" | 21 #include "net/tools/flip_server/flip_config.h" | 
| 22 #include "net/tools/flip_server/output_ordering.h" | 22 #include "net/tools/flip_server/output_ordering.h" | 
| 23 #include "net/tools/flip_server/sm_connection.h" | 23 #include "net/tools/flip_server/sm_connection.h" | 
| 24 #include "net/tools/flip_server/sm_interface.h" | 24 #include "net/tools/flip_server/sm_interface.h" | 
| 25 #include "net/tools/flip_server/spdy_interface.h" | 25 #include "net/tools/flip_server/spdy_interface.h" | 
| 26 #include "net/tools/flip_server/streamer_interface.h" | 26 #include "net/tools/flip_server/streamer_interface.h" | 
| 27 | 27 | 
| 28 using std::cout; |  | 
| 29 using std::cerr; |  | 
| 30 |  | 
| 31 // If true, then disables the nagle algorithm); | 28 // If true, then disables the nagle algorithm); | 
| 32 bool FLAGS_disable_nagle = true; | 29 bool FLAGS_disable_nagle = true; | 
| 33 | 30 | 
| 34 // The number of times that accept() will be called when the | 31 // The number of times that accept() will be called when the | 
| 35 //  alarm goes off when the accept_using_alarm flag is set to true. | 32 //  alarm goes off when the accept_using_alarm flag is set to true. | 
| 36 //  If set to 0, accept() will be performed until the accept queue | 33 //  If set to 0, accept() will be performed until the accept queue | 
| 37 //  is completely drained and the accept() call returns an error); | 34 //  is completely drained and the accept() call returns an error); | 
| 38 int32 FLAGS_accepts_per_wake = 0; | 35 int32 FLAGS_accepts_per_wake = 0; | 
| 39 | 36 | 
| 40 // The size of the TCP accept backlog); | 37 // The size of the TCP accept backlog); | 
| 41 int32 FLAGS_accept_backlog_size = 1024; | 38 int32 FLAGS_accept_backlog_size = 1024; | 
| 42 | 39 | 
| 43 // If set to false a single socket will be used. If set to true | 40 // If set to false a single socket will be used. If set to true | 
| 44 //  then a new socket will be created for each accept thread. | 41 //  then a new socket will be created for each accept thread. | 
| 45 //  Note that this only works with kernels that support | 42 //  Note that this only works with kernels that support | 
| 46 //  SO_REUSEPORT); | 43 //  SO_REUSEPORT); | 
| 47 bool FLAGS_reuseport = false; | 44 bool FLAGS_reuseport = false; | 
| 48 | 45 | 
| 49 // Flag to force spdy, even if NPN is not negotiated. | 46 // Flag to force spdy, even if NPN is not negotiated. | 
| 50 bool FLAGS_force_spdy = false; | 47 bool FLAGS_force_spdy = false; | 
| 51 | 48 | 
| 52 // The amount of time the server delays before sending back the | 49 // The amount of time the server delays before sending back the | 
| 53 //  reply); | 50 //  reply); | 
| 54 double FLAGS_server_think_time_in_s = 0; | 51 double FLAGS_server_think_time_in_s = 0; | 
| 55 | 52 | 
| 56 net::FlipConfig g_proxy_config; | 53 net::FlipConfig g_proxy_config; | 
| 57 | 54 | 
| 58 //////////////////////////////////////////////////////////////////////////////// | 55 std::vector<std::string>& split(const std::string& s, | 
| 59 |  | 
| 60 std::vector<std::string> &split(const std::string &s, |  | 
| 61                                 char delim, | 56                                 char delim, | 
| 62                                 std::vector<std::string> &elems) { | 57                                 std::vector<std::string>& elems) { | 
| 63   std::stringstream ss(s); | 58   std::stringstream ss(s); | 
| 64   std::string item; | 59   std::string item; | 
| 65   while(std::getline(ss, item, delim)) { | 60   while (std::getline(ss, item, delim)) { | 
| 66     elems.push_back(item); | 61     elems.push_back(item); | 
| 67   } | 62   } | 
| 68   return elems; | 63   return elems; | 
| 69 } | 64 } | 
| 70 | 65 | 
| 71 std::vector<std::string> split(const std::string &s, char delim) { | 66 std::vector<std::string> split(const std::string& s, char delim) { | 
| 72   std::vector<std::string> elems; | 67   std::vector<std::string> elems; | 
| 73   return split(s, delim, elems); | 68   return split(s, delim, elems); | 
| 74 } | 69 } | 
| 75 | 70 | 
| 76 bool GotQuitFromStdin() { | 71 bool GotQuitFromStdin() { | 
| 77   // Make stdin nonblocking. Yes this is done each time. Oh well. | 72   // Make stdin nonblocking. Yes this is done each time. Oh well. | 
| 78   fcntl(0, F_SETFL, O_NONBLOCK); | 73   fcntl(0, F_SETFL, O_NONBLOCK); | 
| 79   char c; | 74   char c; | 
| 80   std::string maybequit; | 75   std::string maybequit; | 
| 81   while (read(0, &c, 1) > 0) { | 76   while (read(0, &c, 1) > 0) { | 
| 82     maybequit += c; | 77     maybequit += c; | 
| 83   } | 78   } | 
| 84   if (maybequit.size()) { | 79   if (maybequit.size()) { | 
| 85     VLOG(1) << "scanning string: \"" << maybequit << "\""; | 80     VLOG(1) << "scanning string: \"" << maybequit << "\""; | 
| 86   } | 81   } | 
| 87   return (maybequit.size() > 1 && | 82   return (maybequit.size() > 1 && | 
| 88           (maybequit.c_str()[0] == 'q' || | 83           (maybequit.c_str()[0] == 'q' || maybequit.c_str()[0] == 'Q')); | 
| 89            maybequit.c_str()[0] == 'Q')); |  | 
| 90 } | 84 } | 
| 91 | 85 | 
| 92 const char* BoolToStr(bool b) { | 86 const char* BoolToStr(bool b) { | 
| 93   if (b) | 87   if (b) | 
| 94     return "true"; | 88     return "true"; | 
| 95   return "false"; | 89   return "false"; | 
| 96 } | 90 } | 
| 97 | 91 | 
| 98 //////////////////////////////////////////////////////////////////////////////// |  | 
| 99 |  | 
| 100 static bool wantExit = false; | 92 static bool wantExit = false; | 
| 101 static bool wantLogClose = false; | 93 static bool wantLogClose = false; | 
| 102 void SignalHandler(int signum) | 94 void SignalHandler(int signum) { | 
| 103 { | 95   switch (signum) { | 
| 104   switch(signum) { |  | 
| 105     case SIGTERM: | 96     case SIGTERM: | 
| 106     case SIGINT: | 97     case SIGINT: | 
| 107       wantExit = true; | 98       wantExit = true; | 
| 108       break; | 99       break; | 
| 109     case SIGHUP: | 100     case SIGHUP: | 
| 110       wantLogClose = true; | 101       wantLogClose = true; | 
| 111       break; | 102       break; | 
| 112   } | 103   } | 
| 113 } | 104 } | 
| 114 | 105 | 
| 115 static int OpenPidFile(const char *pidfile) | 106 static int OpenPidFile(const char* pidfile) { | 
| 116 { |  | 
| 117   int fd; | 107   int fd; | 
| 118   struct stat pid_stat; | 108   struct stat pid_stat; | 
| 119   int ret; | 109   int ret; | 
| 120 | 110 | 
| 121   fd = open(pidfile, O_RDWR | O_CREAT, 0600); | 111   fd = open(pidfile, O_RDWR | O_CREAT, 0600); | 
| 122   if (fd == -1) { | 112   if (fd == -1) { | 
| 123       cerr << "Could not open pid file '" << pidfile << "' for reading.\n"; | 113     fprintf(stderr, "Could not open pid file '%s' for reading.\n", pidfile); | 
| 124       exit(1); | 114     exit(1); | 
| 125   } | 115   } | 
| 126 | 116 | 
| 127   ret = flock(fd, LOCK_EX | LOCK_NB); | 117   ret = flock(fd, LOCK_EX | LOCK_NB); | 
| 128   if (ret == -1) { | 118   if (ret == -1) { | 
| 129     if (errno == EWOULDBLOCK) { | 119     if (errno == EWOULDBLOCK) { | 
| 130       cerr << "Flip server is already running.\n"; | 120       fprintf(stderr, "Flip server is already running.\n"); | 
| 131     } else { | 121     } else { | 
| 132       cerr << "Error getting lock on pid file: " << strerror(errno) << "\n"; | 122       perror("Error getting lock on pid file"); | 
| 133     } | 123     } | 
| 134     exit(1); | 124     exit(1); | 
| 135   } | 125   } | 
| 136 | 126 | 
| 137   if (fstat(fd, &pid_stat) == -1) { | 127   if (fstat(fd, &pid_stat) == -1) { | 
| 138     cerr << "Could not stat pid file '" << pidfile << "': " << strerror(errno) | 128     fprintf( | 
| 139          << "\n"; | 129         stderr, "Could not stat pid file '%s': %s\n", pidfile, strerror(errno)); | 
|  | 130     exit(1); | 
| 140   } | 131   } | 
| 141   if (pid_stat.st_size != 0) { | 132   if (pid_stat.st_size != 0) { | 
| 142     if (ftruncate(fd, pid_stat.st_size) == -1) { | 133     if (ftruncate(fd, pid_stat.st_size) == -1) { | 
| 143       cerr << "Could not truncate pid file '" << pidfile << "': " | 134       fprintf(stderr, | 
| 144            << strerror(errno) << "\n"; | 135               "Could not truncate pid file '%s': %s\n", | 
|  | 136               pidfile, | 
|  | 137               strerror(errno)); | 
|  | 138       exit(1); | 
| 145     } | 139     } | 
| 146   } | 140   } | 
| 147 | 141 | 
| 148   char pid_str[8]; | 142   char pid_str[8]; | 
| 149   snprintf(pid_str, sizeof(pid_str), "%d", getpid()); | 143   snprintf(pid_str, sizeof(pid_str), "%d", getpid()); | 
| 150   int bytes = static_cast<int>(strlen(pid_str)); | 144   int bytes = static_cast<int>(strlen(pid_str)); | 
| 151   if (write(fd, pid_str, strlen(pid_str)) != bytes) { | 145   if (write(fd, pid_str, strlen(pid_str)) != bytes) { | 
| 152     cerr << "Could not write pid file: " << strerror(errno) << "\n"; | 146     perror("Could not write pid file"); | 
| 153     close(fd); | 147     close(fd); | 
| 154     exit(1); | 148     exit(1); | 
| 155   } | 149   } | 
| 156 | 150 | 
| 157   return fd; | 151   return fd; | 
| 158 } | 152 } | 
| 159 | 153 | 
| 160 int main (int argc, char**argv) | 154 int main(int argc, char** argv) { | 
| 161 { |  | 
| 162   unsigned int i = 0; | 155   unsigned int i = 0; | 
| 163   bool wait_for_iface = false; | 156   bool wait_for_iface = false; | 
| 164   int pidfile_fd; | 157   int pidfile_fd; | 
| 165 | 158 | 
| 166   signal(SIGPIPE, SIG_IGN); | 159   signal(SIGPIPE, SIG_IGN); | 
| 167   signal(SIGTERM, SignalHandler); | 160   signal(SIGTERM, SignalHandler); | 
| 168   signal(SIGINT, SignalHandler); | 161   signal(SIGINT, SignalHandler); | 
| 169   signal(SIGHUP, SignalHandler); | 162   signal(SIGHUP, SignalHandler); | 
| 170 | 163 | 
| 171   CommandLine::Init(argc, argv); | 164   CommandLine::Init(argc, argv); | 
| 172   CommandLine cl(argc, argv); | 165   CommandLine cl(argc, argv); | 
| 173 | 166 | 
| 174   if (cl.HasSwitch("help") || argc < 2) { | 167   if (cl.HasSwitch("help") || argc < 2) { | 
| 175     cout << argv[0] << " <options>\n"; | 168     printf("%s <options>\n", argv[0]); | 
| 176     cout << "  Proxy options:\n"; | 169     printf("  Proxy options:\n"); | 
| 177     cout << "\t--proxy<1..n>=\"<listen ip>,<listen port>," | 170     printf( | 
| 178          << "<ssl cert filename>,\n" | 171         "\t--proxy<1..n>=\"<listen ip>,<listen port>," | 
| 179          << "\t               <ssl key filename>,<http server ip>," | 172         "<ssl cert filename>,\n" | 
| 180          << "<http server port>,\n" | 173         "\t               <ssl key filename>,<http server ip>," | 
| 181          << "\t               [https server ip],[https server port]," | 174         "<http server port>,\n" | 
| 182          << "<spdy only 0|1>\"\n"; | 175         "\t               [https server ip],[https server port]," | 
| 183     cout << "\t  * The https server ip and port may be left empty if they are" | 176         "<spdy only 0|1>\"\n" | 
| 184          << " the same as\n" | 177         "\t  * The https server ip and port may be left empty if they are" | 
| 185          << "\t    the http server fields.\n"; | 178         " the same as\n" | 
| 186     cout << "\t  * spdy only prevents non-spdy https connections from being" | 179         "\t    the http server fields.\n" | 
| 187          << " passed\n" | 180         "\t  * spdy only prevents non-spdy https connections from being" | 
| 188          << "\t    through the proxy listen ip:port.\n"; | 181         " passed\n" | 
| 189     cout << "\t--forward-ip-header=<header name>\n"; | 182         "\t    through the proxy listen ip:port.\n" | 
| 190     cout << "\n  Server options:\n"; | 183         "\t--forward-ip-header=<header name>\n" | 
| 191     cout << "\t--spdy-server=\"<listen ip>,<listen port>,[ssl cert filename]," | 184         "\n  Server options:\n" | 
| 192          << "\n\t               [ssl key filename]\"\n"; | 185         "\t--spdy-server=\"<listen ip>,<listen port>,[ssl cert filename]," | 
| 193     cout << "\t--http-server=\"<listen ip>,<listen port>,[ssl cert filename]," | 186         "\n\t               [ssl key filename]\"\n" | 
| 194          << "\n\t               [ssl key filename]\"\n"; | 187         "\t--http-server=\"<listen ip>,<listen port>,[ssl cert filename]," | 
| 195     cout << "\t  * Leaving the ssl cert and key fields empty will disable ssl" | 188         "\n\t               [ssl key filename]\"\n" | 
| 196          << " for the\n" | 189         "\t  * Leaving the ssl cert and key fields empty will disable ssl" | 
| 197          << "\t    http and spdy flip servers\n"; | 190         " for the\n" | 
| 198     cout << "\n  Global options:\n"; | 191         "\t    http and spdy flip servers\n" | 
| 199     cout << "\t--logdest=<file|system|both>\n"; | 192         "\n  Global options:\n" | 
| 200     cout << "\t--logfile=<logfile>\n"; | 193         "\t--logdest=<file|system|both>\n" | 
| 201     cout << "\t--wait-for-iface\n"; | 194         "\t--logfile=<logfile>\n" | 
| 202     cout << "\t  * The flip server will block until the listen ip has been" | 195         "\t--wait-for-iface\n" | 
| 203          << " raised.\n"; | 196         "\t  * The flip server will block until the listen ip has been" | 
| 204     cout << "\t--ssl-session-expiry=<seconds> (default is 300)\n"; | 197         " raised.\n" | 
| 205     cout << "\t--ssl-disable-compression\n"; | 198         "\t--ssl-session-expiry=<seconds> (default is 300)\n" | 
| 206     cout << "\t--idle-timeout=<seconds> (default is 300)\n"; | 199         "\t--ssl-disable-compression\n" | 
| 207     cout << "\t--pidfile=<filepath> (default /var/run/flip-server.pid)\n"; | 200         "\t--idle-timeout=<seconds> (default is 300)\n" | 
| 208     cout << "\t--help\n"; | 201         "\t--pidfile=<filepath> (default /var/run/flip-server.pid)\n" | 
|  | 202         "\t--help\n"); | 
| 209     exit(0); | 203     exit(0); | 
| 210   } | 204   } | 
| 211 | 205 | 
| 212   if (cl.HasSwitch("pidfile")) { | 206   if (cl.HasSwitch("pidfile")) { | 
| 213     pidfile_fd = OpenPidFile(cl.GetSwitchValueASCII("pidfile").c_str()); | 207     pidfile_fd = OpenPidFile(cl.GetSwitchValueASCII("pidfile").c_str()); | 
| 214   } else { | 208   } else { | 
| 215     pidfile_fd = OpenPidFile(PIDFILE); | 209     pidfile_fd = OpenPidFile(PIDFILE); | 
| 216   } | 210   } | 
| 217 | 211 | 
| 218   net::OutputOrdering::set_server_think_time_in_s(FLAGS_server_think_time_in_s); | 212   net::OutputOrdering::set_server_think_time_in_s(FLAGS_server_think_time_in_s); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 256     std::string session_expiry = cl.GetSwitchValueASCII("ssl-session-expiry"); | 250     std::string session_expiry = cl.GetSwitchValueASCII("ssl-session-expiry"); | 
| 257     g_proxy_config.ssl_session_expiry_ = atoi(session_expiry.c_str()); | 251     g_proxy_config.ssl_session_expiry_ = atoi(session_expiry.c_str()); | 
| 258   } | 252   } | 
| 259 | 253 | 
| 260   if (cl.HasSwitch("ssl-disable-compression")) { | 254   if (cl.HasSwitch("ssl-disable-compression")) { | 
| 261     g_proxy_config.ssl_disable_compression_ = true; | 255     g_proxy_config.ssl_disable_compression_ = true; | 
| 262   } | 256   } | 
| 263 | 257 | 
| 264   if (cl.HasSwitch("idle-timeout")) { | 258   if (cl.HasSwitch("idle-timeout")) { | 
| 265     g_proxy_config.idle_socket_timeout_s_ = | 259     g_proxy_config.idle_socket_timeout_s_ = | 
| 266       atoi(cl.GetSwitchValueASCII("idle-timeout").c_str()); | 260         atoi(cl.GetSwitchValueASCII("idle-timeout").c_str()); | 
| 267   } | 261   } | 
| 268 | 262 | 
| 269   if (cl.HasSwitch("force_spdy")) | 263   if (cl.HasSwitch("force_spdy")) | 
| 270     net::SMConnection::set_force_spdy(true); | 264     net::SMConnection::set_force_spdy(true); | 
| 271 | 265 | 
| 272   logging::LoggingSettings settings; | 266   logging::LoggingSettings settings; | 
| 273   settings.logging_dest = g_proxy_config.log_destination_; | 267   settings.logging_dest = g_proxy_config.log_destination_; | 
| 274   settings.log_file = g_proxy_config.log_filename_.c_str(); | 268   settings.log_file = g_proxy_config.log_filename_.c_str(); | 
| 275   settings.lock_log = logging::DONT_LOCK_LOG_FILE; | 269   settings.lock_log = logging::DONT_LOCK_LOG_FILE; | 
| 276   logging::InitLogging(settings); | 270   logging::InitLogging(settings); | 
| 277 | 271 | 
| 278   LOG(INFO) << "Flip SPDY proxy started with configuration:"; | 272   LOG(INFO) << "Flip SPDY proxy started with configuration:"; | 
| 279   LOG(INFO) << "Logging destination     : " << g_proxy_config.log_destination_; | 273   LOG(INFO) << "Logging destination     : " << g_proxy_config.log_destination_; | 
| 280   LOG(INFO) << "Log file                : " << g_proxy_config.log_filename_; | 274   LOG(INFO) << "Log file                : " << g_proxy_config.log_filename_; | 
| 281   LOG(INFO) << "Forward IP Header       : " | 275   LOG(INFO) << "Forward IP Header       : " | 
| 282             << (net::SpdySM::forward_ip_header().length() ? | 276             << (net::SpdySM::forward_ip_header().length() | 
| 283                net::SpdySM::forward_ip_header() : "<disabled>"); | 277                     ? net::SpdySM::forward_ip_header() | 
| 284   LOG(INFO) << "Wait for interfaces     : " << (wait_for_iface?"true":"false"); | 278                     : "<disabled>"); | 
|  | 279   LOG(INFO) << "Wait for interfaces     : " << (wait_for_iface ? "true" | 
|  | 280                                                                : "false"); | 
| 285   LOG(INFO) << "Accept backlog size     : " << FLAGS_accept_backlog_size; | 281   LOG(INFO) << "Accept backlog size     : " << FLAGS_accept_backlog_size; | 
| 286   LOG(INFO) << "Accepts per wake        : " << FLAGS_accepts_per_wake; | 282   LOG(INFO) << "Accepts per wake        : " << FLAGS_accepts_per_wake; | 
| 287   LOG(INFO) << "Disable nagle           : " | 283   LOG(INFO) << "Disable nagle           : " << (FLAGS_disable_nagle ? "true" | 
| 288             << (FLAGS_disable_nagle?"true":"false"); | 284                                                                     : "false"); | 
| 289   LOG(INFO) << "Reuseport               : " | 285   LOG(INFO) << "Reuseport               : " << (FLAGS_reuseport ? "true" | 
| 290             << (FLAGS_reuseport?"true":"false"); | 286                                                                 : "false"); | 
| 291   LOG(INFO) << "Force SPDY              : " | 287   LOG(INFO) << "Force SPDY              : " << (FLAGS_force_spdy ? "true" | 
| 292             << (FLAGS_force_spdy?"true":"false"); | 288                                                                  : "false"); | 
| 293   LOG(INFO) << "SSL session expiry      : " | 289   LOG(INFO) << "SSL session expiry      : " | 
| 294             << g_proxy_config.ssl_session_expiry_; | 290             << g_proxy_config.ssl_session_expiry_; | 
| 295   LOG(INFO) << "SSL disable compression : " | 291   LOG(INFO) << "SSL disable compression : " | 
| 296             << g_proxy_config.ssl_disable_compression_; | 292             << g_proxy_config.ssl_disable_compression_; | 
| 297   LOG(INFO) << "Connection idle timeout : " | 293   LOG(INFO) << "Connection idle timeout : " | 
| 298             << g_proxy_config.idle_socket_timeout_s_; | 294             << g_proxy_config.idle_socket_timeout_s_; | 
| 299 | 295 | 
| 300   // Proxy Acceptors | 296   // Proxy Acceptors | 
| 301   while (true) { | 297   while (true) { | 
| 302     i += 1; | 298     i += 1; | 
| 303     std::stringstream name; | 299     std::stringstream name; | 
| 304     name << "proxy" << i; | 300     name << "proxy" << i; | 
| 305     if (!cl.HasSwitch(name.str())) { | 301     if (!cl.HasSwitch(name.str())) { | 
| 306       break; | 302       break; | 
| 307     } | 303     } | 
| 308     std::string value = cl.GetSwitchValueASCII(name.str()); | 304     std::string value = cl.GetSwitchValueASCII(name.str()); | 
| 309     std::vector<std::string> valueArgs = split(value, ','); | 305     std::vector<std::string> valueArgs = split(value, ','); | 
| 310     CHECK_EQ((unsigned int)9, valueArgs.size()); | 306     CHECK_EQ((unsigned int)9, valueArgs.size()); | 
| 311     int spdy_only = atoi(valueArgs[8].c_str()); | 307     int spdy_only = atoi(valueArgs[8].c_str()); | 
| 312     // If wait_for_iface is enabled, then this call will block | 308     // If wait_for_iface is enabled, then this call will block | 
| 313     // indefinitely until the interface is raised. | 309     // indefinitely until the interface is raised. | 
| 314     g_proxy_config.AddAcceptor(net::FLIP_HANDLER_PROXY, | 310     g_proxy_config.AddAcceptor(net::FLIP_HANDLER_PROXY, | 
| 315                                valueArgs[0], valueArgs[1], | 311                                valueArgs[0], | 
| 316                                valueArgs[2], valueArgs[3], | 312                                valueArgs[1], | 
| 317                                valueArgs[4], valueArgs[5], | 313                                valueArgs[2], | 
| 318                                valueArgs[6], valueArgs[7], | 314                                valueArgs[3], | 
|  | 315                                valueArgs[4], | 
|  | 316                                valueArgs[5], | 
|  | 317                                valueArgs[6], | 
|  | 318                                valueArgs[7], | 
| 319                                spdy_only, | 319                                spdy_only, | 
| 320                                FLAGS_accept_backlog_size, | 320                                FLAGS_accept_backlog_size, | 
| 321                                FLAGS_disable_nagle, | 321                                FLAGS_disable_nagle, | 
| 322                                FLAGS_accepts_per_wake, | 322                                FLAGS_accepts_per_wake, | 
| 323                                FLAGS_reuseport, | 323                                FLAGS_reuseport, | 
| 324                                wait_for_iface, | 324                                wait_for_iface, | 
| 325                                NULL); | 325                                NULL); | 
| 326   } | 326   } | 
| 327 | 327 | 
| 328   // Spdy Server Acceptor | 328   // Spdy Server Acceptor | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 373                                FLAGS_disable_nagle, | 373                                FLAGS_disable_nagle, | 
| 374                                FLAGS_accepts_per_wake, | 374                                FLAGS_accepts_per_wake, | 
| 375                                FLAGS_reuseport, | 375                                FLAGS_reuseport, | 
| 376                                wait_for_iface, | 376                                wait_for_iface, | 
| 377                                &http_memory_cache); | 377                                &http_memory_cache); | 
| 378   } | 378   } | 
| 379 | 379 | 
| 380   std::vector<net::SMAcceptorThread*> sm_worker_threads_; | 380   std::vector<net::SMAcceptorThread*> sm_worker_threads_; | 
| 381 | 381 | 
| 382   for (i = 0; i < g_proxy_config.acceptors_.size(); i++) { | 382   for (i = 0; i < g_proxy_config.acceptors_.size(); i++) { | 
| 383     net::FlipAcceptor *acceptor = g_proxy_config.acceptors_[i]; | 383     net::FlipAcceptor* acceptor = g_proxy_config.acceptors_[i]; | 
| 384 | 384 | 
| 385     sm_worker_threads_.push_back( | 385     sm_worker_threads_.push_back(new net::SMAcceptorThread( | 
| 386         new net::SMAcceptorThread(acceptor, | 386         acceptor, (net::MemoryCache*)acceptor->memory_cache_)); | 
| 387                                   (net::MemoryCache *)acceptor->memory_cache_)); |  | 
| 388     // Note that spdy_memory_cache is not threadsafe, it is merely | 387     // Note that spdy_memory_cache is not threadsafe, it is merely | 
| 389     // thread compatible. Thus, if ever we are to spawn multiple threads, | 388     // thread compatible. Thus, if ever we are to spawn multiple threads, | 
| 390     // we either must make the MemoryCache threadsafe, or use | 389     // we either must make the MemoryCache threadsafe, or use | 
| 391     // a separate MemoryCache for each thread. | 390     // a separate MemoryCache for each thread. | 
| 392     // | 391     // | 
| 393     // The latter is what is currently being done as we spawn | 392     // The latter is what is currently being done as we spawn | 
| 394     // a separate thread for each http and spdy server acceptor. | 393     // a separate thread for each http and spdy server acceptor. | 
| 395 | 394 | 
| 396     sm_worker_threads_.back()->InitWorker(); | 395     sm_worker_threads_.back()->InitWorker(); | 
| 397     sm_worker_threads_.back()->Start(); | 396     sm_worker_threads_.back()->Start(); | 
| 398   } | 397   } | 
| 399 | 398 | 
| 400   while (!wantExit) { | 399   while (!wantExit) { | 
| 401     // Close logfile when HUP signal is received. Logging system will | 400     // Close logfile when HUP signal is received. Logging system will | 
| 402     // automatically reopen on next log message. | 401     // automatically reopen on next log message. | 
| 403     if ( wantLogClose ) { | 402     if (wantLogClose) { | 
| 404       wantLogClose = false; | 403       wantLogClose = false; | 
| 405       VLOG(1) << "HUP received, reopening log file."; | 404       VLOG(1) << "HUP received, reopening log file."; | 
| 406       logging::CloseLogFile(); | 405       logging::CloseLogFile(); | 
| 407     } | 406     } | 
| 408     if (GotQuitFromStdin()) { | 407     if (GotQuitFromStdin()) { | 
| 409       for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { | 408       for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { | 
| 410         sm_worker_threads_[i]->Quit(); | 409         sm_worker_threads_[i]->Quit(); | 
| 411       } | 410       } | 
| 412       for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { | 411       for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) { | 
| 413         sm_worker_threads_[i]->Join(); | 412         sm_worker_threads_[i]->Join(); | 
| 414       } | 413       } | 
| 415       break; | 414       break; | 
| 416     } | 415     } | 
| 417     usleep(1000*10);  // 10 ms | 416     usleep(1000 * 10);  // 10 ms | 
| 418   } | 417   } | 
| 419 | 418 | 
| 420   unlink(PIDFILE); | 419   unlink(PIDFILE); | 
| 421   close(pidfile_fd); | 420   close(pidfile_fd); | 
| 422   return 0; | 421   return 0; | 
| 423 } | 422 } | 
| OLD | NEW | 
|---|