OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 // This file implements a simple HTTP server. It can exhibit odd behavior | 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 | 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 | 7 // the updater can continue a connection if it's dropped, or that it |
8 // handles very slow data transfers. | 8 // handles very slow data transfers. |
9 | 9 |
10 // To use this, simply make an HTTP connection to localhost:port and | 10 // To use this, simply make an HTTP connection to localhost:port and |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 struct HttpRequest { | 36 struct HttpRequest { |
37 HttpRequest() : offset(0), return_code(200) {} | 37 HttpRequest() : offset(0), return_code(200) {} |
38 string host; | 38 string host; |
39 string url; | 39 string url; |
40 off_t offset; | 40 off_t offset; |
41 int return_code; | 41 int return_code; |
42 }; | 42 }; |
43 | 43 |
44 namespace { | 44 namespace { |
45 const int kPort = 8080; // hardcoded to 8080 for now | 45 const int kPort = 8088; // hardcoded for now |
46 const int kBigLength = 100000; | 46 const int kBigLength = 100000; |
47 const int kMediumLength = 1000; | 47 const int kMediumLength = 1000; |
48 } | 48 } |
49 | 49 |
50 bool ParseRequest(int fd, HttpRequest* request) { | 50 bool ParseRequest(int fd, HttpRequest* request) { |
51 string headers; | 51 string headers; |
52 while(headers.find("\r\n\r\n") == string::npos) { | 52 while(headers.find("\r\n\r\n") == string::npos) { |
53 vector<char> buf(1024); | 53 vector<char> buf(1024); |
54 memset(&buf[0], 0, buf.size()); | 54 memset(&buf[0], 0, buf.size()); |
55 ssize_t r = read(fd, &buf[0], buf.size() - 1); | 55 ssize_t r = read(fd, &buf[0], buf.size() - 1); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 close(fd); | 255 close(fd); |
256 } | 256 } |
257 | 257 |
258 } // namespace chromeos_update_engine | 258 } // namespace chromeos_update_engine |
259 | 259 |
260 using namespace chromeos_update_engine; | 260 using namespace chromeos_update_engine; |
261 | 261 |
262 int main(int argc, char** argv) { | 262 int main(int argc, char** argv) { |
263 // Ignore SIGPIPE on write() to sockets. | 263 // Ignore SIGPIPE on write() to sockets. |
264 signal(SIGPIPE, SIG_IGN); | 264 signal(SIGPIPE, SIG_IGN); |
265 | 265 |
266 socklen_t clilen; | 266 socklen_t clilen; |
267 struct sockaddr_in server_addr; | 267 struct sockaddr_in server_addr; |
268 struct sockaddr_in client_addr; | 268 struct sockaddr_in client_addr; |
269 memset(&server_addr, 0, sizeof(server_addr)); | 269 memset(&server_addr, 0, sizeof(server_addr)); |
270 memset(&client_addr, 0, sizeof(client_addr)); | 270 memset(&client_addr, 0, sizeof(client_addr)); |
271 | 271 |
272 int listen_fd = socket(AF_INET, SOCK_STREAM, 0); | 272 int listen_fd = socket(AF_INET, SOCK_STREAM, 0); |
273 if (listen_fd < 0) | 273 if (listen_fd < 0) |
274 LOG(FATAL) << "socket() failed"; | 274 LOG(FATAL) << "socket() failed"; |
275 | 275 |
(...skipping 22 matching lines...) Expand all Loading... |
298 int client_fd = accept(listen_fd, | 298 int client_fd = accept(listen_fd, |
299 (struct sockaddr *) &client_addr, | 299 (struct sockaddr *) &client_addr, |
300 &clilen); | 300 &clilen); |
301 LOG(INFO) << "got past accept"; | 301 LOG(INFO) << "got past accept"; |
302 if (client_fd < 0) | 302 if (client_fd < 0) |
303 LOG(FATAL) << "ERROR on accept"; | 303 LOG(FATAL) << "ERROR on accept"; |
304 HandleConnection(client_fd); | 304 HandleConnection(client_fd); |
305 } | 305 } |
306 return 0; | 306 return 0; |
307 } | 307 } |
OLD | NEW |