]> git.sesse.net Git - cubemap/blob - client.h
Release Cubemap 1.0.2.
[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 url;
16         int sock;
17         int fwmark;
18         std::string remote_addr;
19         time_t connect_time;
20         size_t bytes_sent;
21         size_t bytes_lost;
22         size_t num_loss_events;
23 };
24
25 struct Client {
26         Client(int sock);
27
28         // Serialization/deserialization.
29         Client(const ClientProto &serialized, Stream *stream);
30         ClientProto serialize() const;
31
32         ClientStats get_stats() const;
33
34         // The file descriptor associated with this socket.
35         int sock;
36
37         // The fwmark associated with this socket (or 0).
38         int fwmark;
39
40         // Some information only used for logging.
41         std::string remote_addr;
42         time_t connect_time;
43
44         enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA, SENDING_ERROR, WAITING_FOR_KEYFRAME };
45         State state;
46
47         // The HTTP request, as sent by the client. If we are in READING_REQUEST,
48         // this might not be finished.
49         std::string request;
50
51         // What stream we're connecting to; parsed from <request>.
52         // Not relevant for READING_REQUEST.
53         std::string url;
54         Stream *stream;
55
56         // The header we want to send. This is nominally a copy of Stream::header,
57         // but since that might change on reconnects etc., we keep a local copy here.
58         // Only relevant for SENDING_HEADER or SENDING_ERROR; blank otherwise.
59         std::string header_or_error;
60
61         // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER
62         // or SENDING_ERROR.
63         size_t header_or_error_bytes_sent;
64
65         // Number of bytes we are into the stream (ie., the end of last send).
66         // -1 means we want to send from the end of the backlog (the normal case),
67         // although only at a keyframe.
68         // -2 means we want to send from the _beginning_ of the backlog.
69         // Once we go into WAITING_FOR_KEYFRAME or SENDING_DATA, these negative
70         // values will be translated to real numbers.
71         size_t stream_pos;
72
73         // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
74         size_t bytes_sent;
75
76         // Number of times we've skipped forward due to the backlog being too big,
77         // and how many bytes we've skipped over in all. Only relevant for SENDING_DATA.
78         size_t bytes_lost, num_loss_events;
79 };
80
81 #endif  // !defined(_CLIENT_H)