]> git.sesse.net Git - cubemap/blob - client.h
Fix incorrect struct/class in forward declares (found by Clang).
[cubemap] / client.h
1 #ifndef _CLIENT_H
2 #define _CLIENT_H 1
3
4 // A Client represents a single connection from a client (watching a single stream).
5
6 #include <time.h>
7 #include <string>
8
9 class ClientProto;
10 struct Stream;
11
12 // Digested statistics for writing to logs etc.
13 struct ClientStats {
14         std::string stream_id;
15         std::string remote_addr;
16         time_t connect_time;
17         size_t bytes_sent;
18 };
19
20 struct Client {
21         Client() {}
22         Client(int sock);
23
24         // Serialization/deserialization.
25         Client(const ClientProto &serialized, Stream *stream);
26         ClientProto serialize() const;
27
28         ClientStats get_stats() const;
29
30         // The file descriptor associated with this socket.
31         int sock;
32
33         // The fwmark associated with this socket (or 0).
34         int fwmark;
35
36         // Some information only used for logging.
37         std::string remote_addr;
38         time_t connect_time;
39
40         enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA, SENDING_ERROR };
41         State state;
42
43         // The HTTP request, as sent by the client. If we are in READING_REQUEST,
44         // this might not be finished.
45         std::string request;
46
47         // What stream we're connecting to; parsed from <request>.
48         // Not relevant for READING_REQUEST.
49         std::string stream_id;
50         Stream *stream;
51
52         // The header we want to send. This is nominally a copy of Stream::header,
53         // but since that might change on reconnects etc., we keep a local copy here.
54         // Only relevant for SENDING_HEADER or SENDING_ERROR; blank otherwise.
55         std::string header_or_error;
56
57         // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER
58         // or SENDING_ERROR.
59         size_t header_or_error_bytes_sent;
60
61         // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
62         size_t bytes_sent;
63 };
64
65 #endif  // !defined(_CLIENT_H)