6 #include <sys/socket.h>
12 #include "serverpool.h"
20 extern ServerPool *servers;
22 UDPInput::UDPInput(const string &url)
26 // Should be verified by the caller.
28 bool ok = parse_url(url, &protocol, &host, &port, &path);
34 UDPInput::UDPInput(const InputProto &serialized)
35 : url(serialized.url()),
36 sock(serialized.sock())
38 // Should be verified by the caller.
40 bool ok = parse_url(url, &protocol, &host, &port, &path);
46 InputProto UDPInput::serialize() const
48 InputProto serialized;
49 serialized.set_url(url);
50 serialized.set_sock(sock);
54 void UDPInput::close_socket()
60 void UDPInput::construct_header()
64 "Content-type: application/octet-stream\r\n"
65 "Cache-control: no-cache\r\n"
66 "Server: " SERVER_IDENTIFICATION "\r\n"
67 "Connection: close\r\n";
70 void UDPInput::add_destination(int stream_index)
72 stream_indices.push_back(stream_index);
73 servers->set_header(stream_index, http_header, "");
76 void UDPInput::do_work()
78 while (!should_stop()) {
80 int port_num = atoi(port.c_str());
81 sock = create_server_socket(port_num, UDP_SOCKET);
83 log(WARNING, "[%s] UDP socket creation failed. Waiting 0.2 seconds and trying again...",
90 // Wait for a packet, or a wakeup.
91 bool activity = wait_for_activity(sock, POLLIN, NULL);
93 // Most likely, should_stop was set.
100 ret = recv(sock, buf, sizeof(buf), 0);
101 } while (ret == -1 && errno == EINTR);
109 for (size_t i = 0; i < stream_indices.size(); ++i) {
110 servers->add_data(stream_indices[i], buf, ret);