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