Mike Frysinger | 8155d08 | 2012-04-06 15:23:18 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This file implements a simple HTTP server. It can exhibit odd behavior |
| 6 | // that's useful for testing. For example, it's useful to test that |
| 7 | // the updater can continue a connection if it's dropped, or that it |
| 8 | // handles very slow data transfers. |
| 9 | |
| 10 | // To use this, simply make an HTTP connection to localhost:port and |
| 11 | // GET a url. |
| 12 | |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 13 | #include <err.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 14 | #include <errno.h> |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 15 | #include <fcntl.h> |
Andrew de los Reyes | 08c4e27 | 2010-04-15 14:02:17 -0700 | [diff] [blame] | 16 | #include <inttypes.h> |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 17 | #include <netinet/in.h> |
| 18 | #include <signal.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 22 | #include <sys/socket.h> |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 23 | #include <sys/stat.h> |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 24 | #include <sys/types.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 25 | #include <unistd.h> |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 26 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 27 | #include <algorithm> |
| 28 | #include <string> |
| 29 | #include <vector> |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 30 | |
| 31 | #include <base/logging.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 32 | #include <base/strings/string_split.h> |
| 33 | #include <base/strings/string_util.h> |
| 34 | #include <base/strings/stringprintf.h> |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 35 | |
| 36 | #include "update_engine/http_common.h" |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 37 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 38 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 39 | // HTTP end-of-line delimiter; sorry, this needs to be a macro. |
| 40 | #define EOL "\r\n" |
| 41 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | using std::string; |
| 43 | using std::vector; |
| 44 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 45 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | namespace chromeos_update_engine { |
| 47 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 48 | static const char* kListeningMsgPrefix = "listening on port "; |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 49 | |
| 50 | enum { |
| 51 | RC_OK = 0, |
| 52 | RC_BAD_ARGS, |
| 53 | RC_ERR_READ, |
| 54 | RC_ERR_SETSOCKOPT, |
| 55 | RC_ERR_BIND, |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 56 | RC_ERR_LISTEN, |
| 57 | RC_ERR_GETSOCKNAME, |
| 58 | RC_ERR_REPORT, |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 61 | struct HttpRequest { |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 62 | HttpRequest() |
| 63 | : start_offset(0), end_offset(0), return_code(kHttpResponseOk) {} |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 64 | string host; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 65 | string url; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 66 | off_t start_offset; |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 67 | off_t end_offset; // non-inclusive, zero indicates unspecified. |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 68 | HttpResponseCode return_code; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 71 | bool ParseRequest(int fd, HttpRequest* request) { |
| 72 | string headers; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 73 | do { |
| 74 | char buf[1024]; |
| 75 | ssize_t r = read(fd, buf, sizeof(buf)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 76 | if (r < 0) { |
| 77 | perror("read"); |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 78 | exit(RC_ERR_READ); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 79 | } |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 80 | headers.append(buf, r); |
| 81 | } while (!EndsWith(headers, EOL EOL, true)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 82 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 83 | LOG(INFO) << "got headers:\n--8<------8<------8<------8<----\n" |
| 84 | << headers |
| 85 | << "\n--8<------8<------8<------8<----"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 87 | // Break header into lines. |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame^] | 88 | vector<string> lines; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 89 | base::SplitStringUsingSubstr( |
| 90 | headers.substr(0, headers.length() - strlen(EOL EOL)), EOL, &lines); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 91 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 92 | // Decode URL line. |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame^] | 93 | vector<string> terms; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 94 | base::SplitStringAlongWhitespace(lines[0], &terms); |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 95 | CHECK_EQ(terms.size(), static_cast<vector<string>::size_type>(3)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 96 | CHECK_EQ(terms[0], "GET"); |
| 97 | request->url = terms[1]; |
| 98 | LOG(INFO) << "URL: " << request->url; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 99 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 100 | // Decode remaining lines. |
| 101 | size_t i; |
| 102 | for (i = 1; i < lines.size(); i++) { |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame^] | 103 | vector<string> terms; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 104 | base::SplitStringAlongWhitespace(lines[i], &terms); |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 105 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 106 | if (terms[0] == "Range:") { |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 107 | CHECK_EQ(terms.size(), static_cast<vector<string>::size_type>(2)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 108 | string &range = terms[1]; |
| 109 | LOG(INFO) << "range attribute: " << range; |
| 110 | CHECK(StartsWithASCII(range, "bytes=", true) && |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 111 | range.find('-') != string::npos); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 112 | request->start_offset = atoll(range.c_str() + strlen("bytes=")); |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 113 | // Decode end offset and increment it by one (so it is non-inclusive). |
| 114 | if (range.find('-') < range.length() - 1) |
| 115 | request->end_offset = atoll(range.c_str() + range.find('-') + 1) + 1; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 116 | request->return_code = kHttpResponsePartialContent; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame^] | 117 | string tmp_str = base::StringPrintf("decoded range offsets: " |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 118 | "start=%jd end=", |
| 119 | (intmax_t)request->start_offset); |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 120 | if (request->end_offset > 0) |
| 121 | base::StringAppendF(&tmp_str, "%jd (non-inclusive)", |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 122 | (intmax_t)request->end_offset); |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 123 | else |
| 124 | base::StringAppendF(&tmp_str, "unspecified"); |
| 125 | LOG(INFO) << tmp_str; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 126 | } else if (terms[0] == "Host:") { |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 127 | CHECK_EQ(terms.size(), static_cast<vector<string>::size_type>(2)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 128 | request->host = terms[1]; |
| 129 | LOG(INFO) << "host attribute: " << request->host; |
| 130 | } else { |
| 131 | LOG(WARNING) << "ignoring HTTP attribute: `" << lines[i] << "'"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 132 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 133 | } |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 134 | |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 135 | return true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | string Itoa(off_t num) { |
| 139 | char buf[100] = {0}; |
Andrew de los Reyes | 08c4e27 | 2010-04-15 14:02:17 -0700 | [diff] [blame] | 140 | snprintf(buf, sizeof(buf), "%" PRIi64, num); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 141 | return buf; |
| 142 | } |
| 143 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 144 | // Writes a string into a file. Returns total number of bytes written or -1 if a |
| 145 | // write error occurred. |
| 146 | ssize_t WriteString(int fd, const string& str) { |
| 147 | const size_t total_size = str.size(); |
| 148 | size_t remaining_size = total_size; |
| 149 | char const *data = str.data(); |
Gilad Arnold | 48085ba | 2011-11-16 09:36:08 -0800 | [diff] [blame] | 150 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 151 | while (remaining_size) { |
| 152 | ssize_t written = write(fd, data, remaining_size); |
| 153 | if (written < 0) { |
| 154 | perror("write"); |
| 155 | LOG(INFO) << "write failed"; |
| 156 | return -1; |
| 157 | } |
| 158 | data += written; |
| 159 | remaining_size -= written; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 160 | } |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 161 | |
| 162 | return total_size; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 165 | // Writes the headers of an HTTP response into a file. |
| 166 | ssize_t WriteHeaders(int fd, const off_t start_offset, const off_t end_offset, |
| 167 | HttpResponseCode return_code) { |
| 168 | ssize_t written = 0, ret; |
| 169 | |
| 170 | ret = WriteString(fd, |
| 171 | string("HTTP/1.1 ") + Itoa(return_code) + " " + |
| 172 | GetHttpResponseDescription(return_code) + |
| 173 | EOL |
| 174 | "Content-Type: application/octet-stream" EOL); |
| 175 | if (ret < 0) |
| 176 | return -1; |
| 177 | written += ret; |
| 178 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 179 | // Compute content legnth. |
| 180 | const off_t content_length = end_offset - start_offset;; |
| 181 | |
| 182 | // A start offset that equals the end offset indicates that the response |
| 183 | // should contain the full range of bytes in the requested resource. |
| 184 | if (start_offset || start_offset == end_offset) { |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 185 | ret = WriteString(fd, |
| 186 | string("Accept-Ranges: bytes" EOL |
| 187 | "Content-Range: bytes ") + |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 188 | Itoa(start_offset == end_offset ? 0 : start_offset) + |
| 189 | "-" + Itoa(end_offset - 1) + "/" + Itoa(end_offset) + |
| 190 | EOL); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 191 | if (ret < 0) |
| 192 | return -1; |
| 193 | written += ret; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | ret = WriteString(fd, string("Content-Length: ") + Itoa(content_length) + |
| 197 | EOL EOL); |
| 198 | if (ret < 0) |
| 199 | return -1; |
| 200 | written += ret; |
| 201 | |
| 202 | return written; |
| 203 | } |
| 204 | |
| 205 | // Writes a predetermined payload of lines of ascending bytes to a file. The |
| 206 | // first byte of output is appropriately offset with respect to the request line |
| 207 | // length. Returns the number of successfully written bytes. |
| 208 | size_t WritePayload(int fd, const off_t start_offset, const off_t end_offset, |
| 209 | const char first_byte, const size_t line_len) { |
| 210 | CHECK_LE(start_offset, end_offset); |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 211 | CHECK_GT(line_len, static_cast<size_t>(0)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 212 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 213 | LOG(INFO) << "writing payload: " << line_len << "-byte lines starting with `" |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 214 | << first_byte << "', offset range " << start_offset << " -> " |
| 215 | << end_offset; |
| 216 | |
| 217 | // Populate line of ascending characters. |
| 218 | string line; |
| 219 | line.reserve(line_len); |
| 220 | char byte = first_byte; |
| 221 | size_t i; |
| 222 | for (i = 0; i < line_len; i++) |
| 223 | line += byte++; |
| 224 | |
| 225 | const size_t total_len = end_offset - start_offset; |
| 226 | size_t remaining_len = total_len; |
| 227 | bool success = true; |
| 228 | |
| 229 | // If start offset is not aligned with line boundary, output partial line up |
| 230 | // to the first line boundary. |
| 231 | size_t start_modulo = start_offset % line_len; |
| 232 | if (start_modulo) { |
| 233 | string partial = line.substr(start_modulo, remaining_len); |
| 234 | ssize_t ret = WriteString(fd, partial); |
| 235 | if ((success = (ret >= 0 && (size_t) ret == partial.length()))) |
| 236 | remaining_len -= partial.length(); |
| 237 | } |
| 238 | |
| 239 | // Output full lines up to the maximal line boundary below the end offset. |
| 240 | while (success && remaining_len >= line_len) { |
| 241 | ssize_t ret = WriteString(fd, line); |
| 242 | if ((success = (ret >= 0 && (size_t) ret == line_len))) |
| 243 | remaining_len -= line_len; |
| 244 | } |
| 245 | |
| 246 | // Output a partial line up to the end offset. |
| 247 | if (success && remaining_len) { |
| 248 | string partial = line.substr(0, remaining_len); |
| 249 | ssize_t ret = WriteString(fd, partial); |
| 250 | if ((success = (ret >= 0 && (size_t) ret == partial.length()))) |
| 251 | remaining_len -= partial.length(); |
| 252 | } |
| 253 | |
| 254 | return (total_len - remaining_len); |
| 255 | } |
| 256 | |
| 257 | // Write default payload lines of the form 'abcdefghij'. |
| 258 | inline size_t WritePayload(int fd, const off_t start_offset, |
| 259 | const off_t end_offset) { |
| 260 | return WritePayload(fd, start_offset, end_offset, 'a', 10); |
| 261 | } |
| 262 | |
| 263 | // Send an empty response, then kill the server. |
| 264 | void HandleQuit(int fd) { |
| 265 | WriteHeaders(fd, 0, 0, kHttpResponseOk); |
Jay Srinivasan | 135a58b | 2012-07-13 12:46:49 -0700 | [diff] [blame] | 266 | LOG(INFO) << "pid(" << getpid() << "): HTTP server exiting ..."; |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 267 | exit(RC_OK); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 270 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 271 | // Generates an HTTP response with payload corresponding to requested offsets |
| 272 | // and length. Optionally, truncate the payload at a given length and add a |
| 273 | // pause midway through the transfer. Returns the total number of bytes |
| 274 | // delivered or -1 for error. |
| 275 | ssize_t HandleGet(int fd, const HttpRequest& request, const size_t total_length, |
| 276 | const size_t truncate_length, const int sleep_every, |
| 277 | const int sleep_secs) { |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 278 | ssize_t ret; |
| 279 | size_t written = 0; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 280 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 281 | // Obtain start offset, make sure it is within total payload length. |
| 282 | const size_t start_offset = request.start_offset; |
| 283 | if (start_offset >= total_length) { |
| 284 | LOG(WARNING) << "start offset (" << start_offset |
| 285 | << ") exceeds total length (" << total_length |
| 286 | << "), generating error response (" |
| 287 | << kHttpResponseReqRangeNotSat << ")"; |
| 288 | return WriteHeaders(fd, total_length, total_length, |
| 289 | kHttpResponseReqRangeNotSat); |
| 290 | } |
| 291 | |
| 292 | // Obtain end offset, adjust to fit in total payload length and ensure it does |
| 293 | // not preceded the start offset. |
| 294 | size_t end_offset = (request.end_offset > 0 ? |
| 295 | request.end_offset : total_length); |
| 296 | if (end_offset < start_offset) { |
| 297 | LOG(WARNING) << "end offset (" << end_offset << ") precedes start offset (" |
| 298 | << start_offset << "), generating error response"; |
| 299 | return WriteHeaders(fd, 0, 0, kHttpResponseBadRequest); |
| 300 | } |
| 301 | if (end_offset > total_length) { |
| 302 | LOG(INFO) << "requested end offset (" << end_offset |
| 303 | << ") exceeds total length (" << total_length << "), adjusting"; |
| 304 | end_offset = total_length; |
| 305 | } |
| 306 | |
| 307 | // Generate headers |
| 308 | LOG(INFO) << "generating response header: range=" << start_offset << "-" |
| 309 | << (end_offset - 1) << "/" << (end_offset - start_offset) |
| 310 | << ", return code=" << request.return_code; |
| 311 | if ((ret = WriteHeaders(fd, start_offset, end_offset, |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 312 | request.return_code)) < 0) |
| 313 | return -1; |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 314 | LOG(INFO) << ret << " header bytes written"; |
| 315 | written += ret; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 316 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 317 | // Compute payload length, truncate as necessary. |
| 318 | size_t payload_length = end_offset - start_offset; |
| 319 | if (truncate_length > 0 && truncate_length < payload_length) { |
| 320 | LOG(INFO) << "truncating request payload length (" << payload_length |
| 321 | << ") at " << truncate_length; |
| 322 | payload_length = truncate_length; |
| 323 | end_offset = start_offset + payload_length; |
| 324 | } |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 325 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 326 | LOG(INFO) << "generating response payload: range=" << start_offset << "-" |
| 327 | << (end_offset - 1) << "/" << (end_offset - start_offset); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 328 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 329 | // Decide about optional midway delay. |
| 330 | if (truncate_length > 0 && sleep_every > 0 && sleep_secs >= 0 && |
| 331 | start_offset % (truncate_length * sleep_every) == 0) { |
| 332 | const off_t midway_offset = start_offset + payload_length / 2; |
| 333 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 334 | if ((ret = WritePayload(fd, start_offset, midway_offset)) < 0) |
| 335 | return -1; |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 336 | LOG(INFO) << ret << " payload bytes written (first chunk)"; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 337 | written += ret; |
| 338 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 339 | LOG(INFO) << "sleeping for " << sleep_secs << " seconds..."; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 340 | sleep(sleep_secs); |
| 341 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 342 | if ((ret = WritePayload(fd, midway_offset, end_offset)) < 0) |
| 343 | return -1; |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 344 | LOG(INFO) << ret << " payload bytes written (second chunk)"; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 345 | written += ret; |
| 346 | } else { |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 347 | if ((ret = WritePayload(fd, start_offset, end_offset)) < 0) |
| 348 | return -1; |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 349 | LOG(INFO) << ret << " payload bytes written"; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 350 | written += ret; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 351 | } |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 352 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 353 | LOG(INFO) << "response generation complete, " << written |
| 354 | << " total bytes written"; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 355 | return written; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Gilad Arnold | e4ad250 | 2011-12-29 17:08:54 -0800 | [diff] [blame] | 358 | ssize_t HandleGet(int fd, const HttpRequest& request, |
| 359 | const size_t total_length) { |
| 360 | return HandleGet(fd, request, total_length, 0, 0, 0); |
| 361 | } |
| 362 | |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 363 | // Handles /redirect/<code>/<url> requests by returning the specified |
| 364 | // redirect <code> with a location pointing to /<url>. |
| 365 | void HandleRedirect(int fd, const HttpRequest& request) { |
| 366 | LOG(INFO) << "Redirecting..."; |
| 367 | string url = request.url; |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 368 | CHECK_EQ(static_cast<size_t>(0), url.find("/redirect/")); |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 369 | url.erase(0, strlen("/redirect/")); |
| 370 | string::size_type url_start = url.find('/'); |
| 371 | CHECK_NE(url_start, string::npos); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 372 | HttpResponseCode code = StringToHttpResponseCode(url.c_str()); |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 373 | url.erase(0, url_start); |
| 374 | url = "http://" + request.host + url; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 375 | const char *status = GetHttpResponseDescription(code); |
| 376 | if (!status) |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 377 | CHECK(false) << "Unrecognized redirection code: " << code; |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 378 | LOG(INFO) << "Code: " << code << " " << status; |
| 379 | LOG(INFO) << "New URL: " << url; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 380 | |
| 381 | ssize_t ret; |
| 382 | if ((ret = WriteString(fd, "HTTP/1.1 " + Itoa(code) + " " + |
| 383 | status + EOL)) < 0) |
| 384 | return; |
| 385 | WriteString(fd, "Location: " + url + EOL); |
| 386 | } |
| 387 | |
| 388 | // Generate a page not found error response with actual text payload. Return |
| 389 | // number of bytes written or -1 for error. |
| 390 | ssize_t HandleError(int fd, const HttpRequest& request) { |
| 391 | LOG(INFO) << "Generating error HTTP response"; |
| 392 | |
| 393 | ssize_t ret; |
| 394 | size_t written = 0; |
| 395 | |
| 396 | const string data("This is an error page."); |
| 397 | |
| 398 | if ((ret = WriteHeaders(fd, 0, data.size(), kHttpResponseNotFound)) < 0) |
| 399 | return -1; |
| 400 | written += ret; |
| 401 | |
| 402 | if ((ret = WriteString(fd, data)) < 0) |
| 403 | return -1; |
| 404 | written += ret; |
| 405 | |
| 406 | return written; |
| 407 | } |
| 408 | |
| 409 | // Generate an error response if the requested offset is nonzero, up to a given |
| 410 | // maximal number of successive failures. The error generated is an "Internal |
| 411 | // Server Error" (500). |
| 412 | ssize_t HandleErrorIfOffset(int fd, const HttpRequest& request, |
| 413 | size_t end_offset, int max_fails) { |
| 414 | static int num_fails = 0; |
| 415 | |
| 416 | if (request.start_offset > 0 && num_fails < max_fails) { |
| 417 | LOG(INFO) << "Generating error HTTP response"; |
| 418 | |
| 419 | ssize_t ret; |
| 420 | size_t written = 0; |
| 421 | |
| 422 | const string data("This is an error page."); |
| 423 | |
| 424 | if ((ret = WriteHeaders(fd, 0, data.size(), |
| 425 | kHttpResponseInternalServerError)) < 0) |
| 426 | return -1; |
| 427 | written += ret; |
| 428 | |
| 429 | if ((ret = WriteString(fd, data)) < 0) |
| 430 | return -1; |
| 431 | written += ret; |
| 432 | |
| 433 | num_fails++; |
| 434 | return written; |
| 435 | } else { |
| 436 | num_fails = 0; |
| 437 | return HandleGet(fd, request, end_offset); |
| 438 | } |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 439 | } |
| 440 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 441 | void HandleDefault(int fd, const HttpRequest& request) { |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 442 | const off_t start_offset = request.start_offset; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 443 | const string data("unhandled path"); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 444 | const size_t size = data.size(); |
| 445 | ssize_t ret; |
| 446 | |
| 447 | if ((ret = WriteHeaders(fd, start_offset, size, request.return_code)) < 0) |
| 448 | return; |
| 449 | WriteString(fd, (start_offset < static_cast<off_t>(size) ? |
| 450 | data.substr(start_offset) : "")); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Gilad Arnold | 48085ba | 2011-11-16 09:36:08 -0800 | [diff] [blame] | 453 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 454 | // Break a URL into terms delimited by slashes. |
| 455 | class UrlTerms { |
| 456 | public: |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 457 | UrlTerms(const string &url, size_t num_terms) { |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 458 | // URL must be non-empty and start with a slash. |
Mike Frysinger | 0f9547d | 2012-02-16 12:11:37 -0500 | [diff] [blame] | 459 | CHECK_GT(url.size(), static_cast<size_t>(0)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 460 | CHECK_EQ(url[0], '/'); |
| 461 | |
| 462 | // Split it into terms delimited by slashes, omitting the preceeding slash. |
| 463 | base::SplitStringDontTrim(url.substr(1), '/', &terms); |
| 464 | |
| 465 | // Ensure expected length. |
| 466 | CHECK_EQ(terms.size(), num_terms); |
| 467 | } |
| 468 | |
| 469 | inline string Get(const off_t index) const { |
| 470 | return terms[index]; |
| 471 | } |
| 472 | inline const char *GetCStr(const off_t index) const { |
| 473 | return Get(index).c_str(); |
| 474 | } |
| 475 | inline int GetInt(const off_t index) const { |
| 476 | return atoi(GetCStr(index)); |
| 477 | } |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 478 | inline size_t GetSizeT(const off_t index) const { |
| 479 | return static_cast<size_t>(atol(GetCStr(index))); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | private: |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame^] | 483 | vector<string> terms; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 484 | }; |
Gilad Arnold | 48085ba | 2011-11-16 09:36:08 -0800 | [diff] [blame] | 485 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 486 | void HandleConnection(int fd) { |
| 487 | HttpRequest request; |
| 488 | ParseRequest(fd, &request); |
| 489 | |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 490 | string &url = request.url; |
Jay Srinivasan | 135a58b | 2012-07-13 12:46:49 -0700 | [diff] [blame] | 491 | LOG(INFO) << "pid(" << getpid() << "): handling url " << url; |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 492 | if (url == "/quitquitquit") { |
| 493 | HandleQuit(fd); |
| 494 | } else if (StartsWithASCII(url, "/download/", true)) { |
| 495 | const UrlTerms terms(url, 2); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 496 | HandleGet(fd, request, terms.GetSizeT(1)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 497 | } else if (StartsWithASCII(url, "/flaky/", true)) { |
| 498 | const UrlTerms terms(url, 5); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 499 | HandleGet(fd, request, terms.GetSizeT(1), terms.GetSizeT(2), |
| 500 | terms.GetInt(3), terms.GetInt(4)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 501 | } else if (url.find("/redirect/") == 0) { |
Darin Petkov | 41c2fcf | 2010-08-25 13:14:48 -0700 | [diff] [blame] | 502 | HandleRedirect(fd, request); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 503 | } else if (url == "/error") { |
Gilad Arnold | 48085ba | 2011-11-16 09:36:08 -0800 | [diff] [blame] | 504 | HandleError(fd, request); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 505 | } else if (StartsWithASCII(url, "/error-if-offset/", true)) { |
| 506 | const UrlTerms terms(url, 3); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 507 | HandleErrorIfOffset(fd, request, terms.GetSizeT(1), terms.GetInt(2)); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 508 | } else { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 509 | HandleDefault(fd, request); |
Gilad Arnold | 9bedeb5 | 2011-11-17 16:19:57 -0800 | [diff] [blame] | 510 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 511 | |
| 512 | close(fd); |
| 513 | } |
| 514 | |
| 515 | } // namespace chromeos_update_engine |
| 516 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 517 | using namespace chromeos_update_engine; // NOLINT(build/namespaces) |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 518 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 519 | |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 520 | void usage(const char *prog_arg) { |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 521 | fprintf( |
| 522 | stderr, |
| 523 | "Usage: %s [ FILE ]\n" |
| 524 | "Once accepting connections, the following is written to FILE (or " |
| 525 | "stdout):\n" |
| 526 | "\"%sN\" (where N is an integer port number)\n", |
| 527 | basename(prog_arg), kListeningMsgPrefix); |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 528 | } |
| 529 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 530 | int main(int argc, char** argv) { |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 531 | // Check invocation. |
| 532 | if (argc > 2) |
| 533 | errx(RC_BAD_ARGS, "unexpected number of arguments (use -h for usage)"); |
| 534 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 535 | // Parse (optional) argument. |
| 536 | int report_fd = STDOUT_FILENO; |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 537 | if (argc == 2) { |
| 538 | if (!strcmp(argv[1], "-h")) { |
| 539 | usage(argv[0]); |
| 540 | exit(RC_OK); |
| 541 | } |
| 542 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 543 | report_fd = open(argv[1], O_WRONLY | O_CREAT, 00644); |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Andrew de los Reyes | 3fd5d30 | 2010-10-07 20:07:18 -0700 | [diff] [blame] | 546 | // Ignore SIGPIPE on write() to sockets. |
| 547 | signal(SIGPIPE, SIG_IGN); |
Darin Petkov | f67bb1f | 2010-11-08 16:10:26 -0800 | [diff] [blame] | 548 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 549 | int listen_fd = socket(AF_INET, SOCK_STREAM, 0); |
| 550 | if (listen_fd < 0) |
| 551 | LOG(FATAL) << "socket() failed"; |
| 552 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 553 | struct sockaddr_in server_addr = sockaddr_in(); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 554 | server_addr.sin_family = AF_INET; |
| 555 | server_addr.sin_addr.s_addr = INADDR_ANY; |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 556 | server_addr.sin_port = 0; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 557 | |
| 558 | { |
| 559 | // Get rid of "Address in use" error |
| 560 | int tr = 1; |
| 561 | if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &tr, |
| 562 | sizeof(int)) == -1) { |
| 563 | perror("setsockopt"); |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 564 | exit(RC_ERR_SETSOCKOPT); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 568 | // Bind the socket and set for listening. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 569 | if (bind(listen_fd, reinterpret_cast<struct sockaddr *>(&server_addr), |
| 570 | sizeof(server_addr)) < 0) { |
| 571 | perror("bind"); |
Gilad Arnold | 97bdb3f | 2013-06-30 23:05:50 -0700 | [diff] [blame] | 572 | exit(RC_ERR_BIND); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 573 | } |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 574 | if (listen(listen_fd, 5) < 0) { |
| 575 | perror("listen"); |
| 576 | exit(RC_ERR_LISTEN); |
| 577 | } |
| 578 | |
| 579 | // Check the actual port. |
| 580 | struct sockaddr_in bound_addr = sockaddr_in(); |
| 581 | socklen_t bound_addr_len = sizeof(bound_addr); |
| 582 | if (getsockname(listen_fd, reinterpret_cast<struct sockaddr*>(&bound_addr), |
| 583 | &bound_addr_len) < 0) { |
| 584 | perror("getsockname"); |
| 585 | exit(RC_ERR_GETSOCKNAME); |
| 586 | } |
| 587 | in_port_t port = ntohs(bound_addr.sin_port); |
| 588 | |
| 589 | // Output the listening port, indicating that the server is processing |
| 590 | // requests. IMPORTANT! (a) the format of this message is as expected by some |
| 591 | // unit tests, avoid unilateral changes; (b) it is necessary to flush/sync the |
| 592 | // file to prevent the spawning process from waiting indefinitely for this |
| 593 | // message. |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 594 | string listening_msg = base::StringPrintf("%s%hu", kListeningMsgPrefix, port); |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 595 | LOG(INFO) << listening_msg; |
| 596 | CHECK_EQ(write(report_fd, listening_msg.c_str(), listening_msg.length()), |
| 597 | static_cast<int>(listening_msg.length())); |
| 598 | CHECK_EQ(write(report_fd, "\n", 1), 1); |
| 599 | if (report_fd == STDOUT_FILENO) |
| 600 | fsync(report_fd); |
| 601 | else |
| 602 | close(report_fd); |
| 603 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 604 | while (1) { |
Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 605 | LOG(INFO) << "pid(" << getpid() << "): waiting to accept new connection"; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 606 | int client_fd = accept(listen_fd, nullptr, nullptr); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 607 | LOG(INFO) << "got past accept"; |
| 608 | if (client_fd < 0) |
| 609 | LOG(FATAL) << "ERROR on accept"; |
| 610 | HandleConnection(client_fd); |
| 611 | } |
| 612 | return 0; |
| 613 | } |