]> git.sesse.net Git - cubemap/commitdiff
Rename header_or_error to header_or_short_response, as it will soon be able to contai...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 15 Aug 2015 22:27:33 +0000 (00:27 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 15 Aug 2015 22:37:35 +0000 (00:37 +0200)
Similarly, rename the state from SENDING_ERROR to SENDING_SHORT_RESPONSE.

client.cpp
client.h
server.cpp
server.h
state.proto

index 786e17825817e9bfa9360042a099c411646254c7..77fad722a6ba9881ad44cc1e3c949beba1a580e9 100644 (file)
@@ -19,7 +19,7 @@ Client::Client(int sock)
        : sock(sock),
          state(Client::READING_REQUEST),
          stream(NULL),
-         header_or_error_bytes_sent(0),
+         header_or_short_response_bytes_sent(0),
          stream_pos(0),
          bytes_sent(0),
          bytes_lost(0),
@@ -70,8 +70,8 @@ Client::Client(const ClientProto &serialized, Stream *stream)
          request(serialized.request()),
          url(serialized.url()),
          stream(stream),
-         header_or_error(serialized.header_or_error()),
-         header_or_error_bytes_sent(serialized.header_or_error_bytes_sent()),
+         header_or_short_response(serialized.header_or_short_response()),
+         header_or_short_response_bytes_sent(serialized.header_or_short_response_bytes_sent()),
          stream_pos(serialized.stream_pos()),
          bytes_sent(serialized.bytes_sent()),
          bytes_lost(serialized.bytes_lost()),
@@ -100,8 +100,8 @@ ClientProto Client::serialize() const
        serialized.set_state(state);
        serialized.set_request(request);
        serialized.set_url(url);
-       serialized.set_header_or_error(header_or_error);
-       serialized.set_header_or_error_bytes_sent(serialized.header_or_error_bytes_sent());
+       serialized.set_header_or_short_response(header_or_short_response);
+       serialized.set_header_or_short_response_bytes_sent(serialized.header_or_short_response_bytes_sent());
        serialized.set_stream_pos(stream_pos);
        serialized.set_bytes_sent(bytes_sent);
        serialized.set_bytes_lost(bytes_lost);
index 954ad41967878b123ea388fe9110f7d6b4069603..2ee478375fd9edcda5da464c90907b0e41f7e0e6 100644 (file)
--- a/client.h
+++ b/client.h
@@ -44,7 +44,7 @@ struct Client {
        std::string referer;
        std::string user_agent;
 
-       enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA, SENDING_ERROR, WAITING_FOR_KEYFRAME, PREBUFFERING };
+       enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA, SENDING_SHORT_RESPONSE, WAITING_FOR_KEYFRAME, PREBUFFERING };
        State state;
 
        // The HTTP request, as sent by the client. If we are in READING_REQUEST,
@@ -56,14 +56,16 @@ struct Client {
        std::string url;
        Stream *stream;
 
-       // The header we want to send. This is nominally a copy of Stream::header,
-       // but since that might change on reconnects etc., we keep a local copy here.
-       // Only relevant for SENDING_HEADER or SENDING_ERROR; blank otherwise.
-       std::string header_or_error;
+       // The header we want to send, or the response with headers if we know
+       // it in its entirety after reading the request (typically an error).
+       // This is nominally a copy of Stream::header, but since that might
+       // change on reconnects etc., we keep a local copy here. Only relevant
+       // for SENDING_HEADER or SENDING_SHORT_RESPONSE; blank otherwise.
+       std::string header_or_short_response;
 
        // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER
-       // or SENDING_ERROR.
-       size_t header_or_error_bytes_sent;
+       // or SENDING_SHORT_RESPONSE.
+       size_t header_or_short_response_bytes_sent;
 
        // Number of bytes we are into the stream (ie., the end of last send).
        // -1 means we want to send from the end of the backlog (the normal case),
index 72664e33f665eda4bd09e49d22789e546b4ee81f..615e8fb31d48b137df3cdcb3acf8caa4cbf00c68 100644 (file)
@@ -423,17 +423,17 @@ read_request_again:
                }
 
                // We've changed states, so fall through.
-               assert(client->state == Client::SENDING_ERROR ||
+               assert(client->state == Client::SENDING_SHORT_RESPONSE ||
                       client->state == Client::SENDING_HEADER);
        }
-       case Client::SENDING_ERROR:
+       case Client::SENDING_SHORT_RESPONSE:
        case Client::SENDING_HEADER: {
-sending_header_or_error_again:
+sending_header_or_short_response_again:
                int ret;
                do {
                        ret = write(client->sock,
-                                   client->header_or_error.data() + client->header_or_error_bytes_sent,
-                                   client->header_or_error.size() - client->header_or_error_bytes_sent);
+                                   client->header_or_short_response.data() + client->header_or_short_response_bytes_sent,
+                                   client->header_or_short_response.size() - client->header_or_short_response_bytes_sent);
                } while (ret == -1 && errno == EINTR);
 
                if (ret == -1 && errno == EAGAIN) {
@@ -451,18 +451,18 @@ sending_header_or_error_again:
                        return;
                }
                
-               client->header_or_error_bytes_sent += ret;
-               assert(client->header_or_error_bytes_sent <= client->header_or_error.size());
+               client->header_or_short_response_bytes_sent += ret;
+               assert(client->header_or_short_response_bytes_sent <= client->header_or_short_response.size());
 
-               if (client->header_or_error_bytes_sent < client->header_or_error.size()) {
+               if (client->header_or_short_response_bytes_sent < client->header_or_short_response.size()) {
                        // We haven't sent all yet. Fine; go another round.
-                       goto sending_header_or_error_again;
+                       goto sending_header_or_short_response_again;
                }
 
                // We're done sending the header or error! Clear it to release some memory.
-               client->header_or_error.clear();
+               client->header_or_short_response.clear();
 
-               if (client->state == Client::SENDING_ERROR) {
+               if (client->state == Client::SENDING_SHORT_RESPONSE) {
                        // We're done sending the error, so now close.  
                        // This is postcondition #1.
                        close_client(client);
@@ -670,11 +670,11 @@ void Server::construct_header(Client *client)
 {
        Stream *stream = client->stream;
        if (stream->encoding == Stream::STREAM_ENCODING_RAW) {
-               client->header_or_error = stream->http_header +
+               client->header_or_short_response = stream->http_header +
                        "\r\n" +
                        stream->stream_header;
        } else if (stream->encoding == Stream::STREAM_ENCODING_METACUBE) {
-               client->header_or_error = stream->http_header +
+               client->header_or_short_response = stream->http_header +
                        "Content-encoding: metacube\r\n" +
                        "\r\n";
                if (!stream->stream_header.empty()) {
@@ -683,10 +683,10 @@ void Server::construct_header(Client *client)
                        hdr.size = htonl(stream->stream_header.size());
                        hdr.flags = htons(METACUBE_FLAGS_HEADER);
                        hdr.csum = htons(metacube2_compute_crc(&hdr));
-                       client->header_or_error.append(
+                       client->header_or_short_response.append(
                                string(reinterpret_cast<char *>(&hdr), sizeof(hdr)));
                }
-               client->header_or_error.append(stream->stream_header);
+               client->header_or_short_response.append(stream->stream_header);
        } else {
                assert(false);
        }
@@ -709,10 +709,10 @@ void Server::construct_error(Client *client, int error_code)
        char error[256];
        snprintf(error, 256, "HTTP/1.0 %d Error\r\nContent-type: text/plain\r\n\r\nSomething went wrong. Sorry.\r\n",
                error_code);
-       client->header_or_error = error;
+       client->header_or_short_response = error;
 
        // Switch states.
-       client->state = Client::SENDING_ERROR;
+       client->state = Client::SENDING_SHORT_RESPONSE;
 
        epoll_event ev;
        ev.events = EPOLLOUT | EPOLLET | EPOLLRDHUP;
index 79c35f82e8bf065a9fe9e7f6bff33ef8eb3b6a23..cfc9d25160413a5ede6408213971a9d6bebed98f 100644 (file)
--- a/server.h
+++ b/server.h
@@ -138,7 +138,7 @@ private:
        void construct_header(Client *client);
 
        // Construct a generic error with the given line, and set the client into
-       // the SENDING_ERROR state.
+       // the SENDING_SHORT_RESPONSE state.
        void construct_error(Client *client, int error_code);
 
        void process_queued_data();
index 942254012ffae5a309ed6bf6f95c1a965e2fe8dc..c7c7e70286eac11e43c87c725cc9d26d26b608cb 100644 (file)
@@ -8,8 +8,8 @@ message ClientProto {
        optional int32 state = 2;
        optional bytes request = 3;
        optional string url = 4;
-       optional bytes header_or_error = 5;
-       optional int64 header_or_error_bytes_sent = 6;
+       optional bytes header_or_short_response = 5;
+       optional int64 header_or_short_response_bytes_sent = 6;
        optional int64 stream_pos = 7;
        optional int64 bytes_sent = 10;
        optional int64 bytes_lost = 11;