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