From 5f72b6466cca4da0b8de29f4526a6cde23c5368e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 6 Apr 2013 18:36:14 +0200 Subject: [PATCH] Rename client_request to request, and clear it when we are done with it. --- server.cpp | 15 ++++++++------- server.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server.cpp b/server.cpp index 2f3f4c0..08f2afd 100644 --- a/server.cpp +++ b/server.cpp @@ -76,7 +76,7 @@ void Server::add_client(int sock) MutexLock lock(&mutex); Client new_client; new_client.sock = sock; - new_client.client_request.reserve(1024); + new_client.request.reserve(1024); new_client.state = Client::READING_REQUEST; new_client.header_bytes_sent = 0; new_client.bytes_sent = 0; @@ -151,7 +151,7 @@ void Server::process_client(Client *client) } // Guard against overlong requests gobbling up all of our space. - if (client->client_request.size() + ret > MAX_CLIENT_REQUEST) { + if (client->request.size() + ret > MAX_CLIENT_REQUEST) { fprintf(stderr, "WARNING: fd %d sent overlong request!\n", client->sock); close_client(client); return; @@ -159,19 +159,19 @@ void Server::process_client(Client *client) // See if we have \r\n\r\n anywhere in the request. We start three bytes // before what we just appended, in case we just got the final character. - size_t existing_req_bytes = client->client_request.size(); - client->client_request.append(string(buf, buf + ret)); + size_t existing_req_bytes = client->request.size(); + client->request.append(string(buf, buf + ret)); size_t start_at = (existing_req_bytes >= 3 ? existing_req_bytes - 3 : 0); const char *ptr = reinterpret_cast( - memmem(client->client_request.data() + start_at, client->client_request.size() - start_at, + memmem(client->request.data() + start_at, client->request.size() - start_at, "\r\n\r\n", 4)); if (ptr == NULL) { // OK, we don't have the entire header yet. Fine; we'll get it later. return; } - if (ptr != client->client_request.data() + client->client_request.size() - 4) { + if (ptr != client->request.data() + client->request.size() - 4) { fprintf(stderr, "WARNING: fd %d had junk data after request!\n", client->sock); close_client(client); return; @@ -260,9 +260,10 @@ void Server::parse_request(Client *client) { // TODO: Actually parse the request. :-) client->stream_id = "stream"; + client->request.clear(); // Construct the header. - client->header = "HTTP/1.0 200 OK\r\nContent-type: todo/fixme\r\n\r\n" + + client->header = "HTTP/1.0 200 OK\r\n Content-type: video/x-flv\r\nCache-Control: no-cache\r\nContent-type: todo/fixme\r\n\r\n" + streams[client->stream_id].header; // Switch states. diff --git a/server.h b/server.h index 271732b..dea24d8 100644 --- a/server.h +++ b/server.h @@ -21,9 +21,9 @@ struct Client { // The HTTP request, as sent by the client. If we are in READING_REQUEST, // this might not be finished. - std::string client_request; + std::string request; - // What stream we're connecting to; parsed from client_request. + // What stream we're connecting to; parsed from . // Not relevant for READING_REQUEST. std::string stream_id; -- 2.39.2