File: client.h

package info (click to toggle)
cubemap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 428 kB
  • sloc: cpp: 4,431; sh: 114; perl: 102; makefile: 60
file content (86 lines) | stat: -rw-r--r-- 2,710 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef _CLIENT_H
#define _CLIENT_H 1

// A Client represents a single connection from a client (watching a single stream).

#include <stddef.h>
#include <time.h>
#include <string>

class ClientProto;
struct Stream;

// Digested statistics for writing to logs etc.
// Note that "referer" and "user_agent" here are already escaped for scary characters.
struct ClientStats {
	std::string url;
	int sock;
	std::string remote_addr;
	std::string referer;
	std::string user_agent;
	timespec connect_time;
	size_t bytes_sent;
	size_t bytes_lost;
	size_t num_loss_events;
};

struct Client {
	Client(int sock);

	// Serialization/deserialization.
	Client(const ClientProto &serialized, Stream *stream);
	ClientProto serialize() const;

	ClientStats get_stats() const;

	// The file descriptor associated with this socket.
	int sock;

	// When the client connected, in terms of CLOCK_MONOTONIC_COARSE.
	timespec connect_time;

	// Some information only used for logging.
	std::string remote_addr;
	std::string referer;
	std::string user_agent;

	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,
	// this might not be finished.
	std::string request;

	// What stream we're connecting to; parsed from <request>.
	// Not relevant for READING_REQUEST.
	std::string url;
	Stream *stream;

	// 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_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),
	// although only at a keyframe.
	// -2 means we want to send from the _beginning_ of the backlog.
	// Once we go into WAITING_FOR_KEYFRAME, PREBUFFERING or SENDING_DATA,
	// these negative values will be translated to real numbers.
	size_t stream_pos;

	// Number of bytes we've sent of data. Only relevant for SENDING_DATA.
	size_t bytes_sent;

	// Number of times we've skipped forward due to the backlog being too big,
	// and how many bytes we've skipped over in all. Only relevant for SENDING_DATA.
	size_t bytes_lost, num_loss_events;
};

#endif  // !defined(_CLIENT_H)