]> git.sesse.net Git - cubemap/blob - udpinput.h
Store and log connection time for inputs.
[cubemap] / udpinput.h
1 #ifndef _UDPINPUT_H
2 #define _UDPINPUT_H 1
3
4 #include <string>
5 #include <vector>
6
7 #include "input.h"
8
9 class InputProto;
10
11 class UDPInput : public Input {
12 public:
13         UDPInput(const std::string &url);
14
15         // Serialization/deserialization.
16         UDPInput(const InputProto &serialized);
17         virtual InputProto serialize() const;
18
19         virtual std::string get_url() const { return url; }
20         virtual void close_socket();
21
22         virtual void add_destination(int stream_index);
23
24         virtual InputStats get_stats() const;
25
26 private:
27         // Actually gets the packets.
28         virtual void do_work();
29
30         // Create the HTTP header.
31         void construct_header();
32
33         std::vector<int> stream_indices;
34
35         // The URL and its parsed components.
36         std::string url;
37         std::string host, port, path;
38
39         // The HTTP header we're sending to clients.
40         std::string http_header;
41
42         // The socket we are receiving on (or -1).
43         int sock;
44
45         // Temporary buffer, sized for the maximum size of an UDP packet.
46         char packet_buf[65536];
47
48         // Mutex protecting <stats>.
49         mutable pthread_mutex_t stats_mutex;
50
51         // The current statistics for this connection. Protected by <stats_mutex>.
52         InputStats stats;
53 };
54
55 #endif  // !defined(_UDPINPUT_H)