#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <poll.h>
#include <stddef.h>
#include <stdlib.h>
#include "acceptor.h"
#include "log.h"
-#include "mutexlock.h"
#include "serverpool.h"
#include "state.pb.h"
#include "stream.h"
construct_header();
- pthread_mutex_init(&stats_mutex, nullptr);
stats.url = url;
stats.connect_time = time(nullptr);
}
: url(serialized.url()),
sock(serialized.sock())
{
+ // Set back the close-on-exec flag for the socket.
+ // (This can't leak into a child, since we haven't been started yet.)
+ fcntl(sock, F_SETFD, FD_CLOEXEC);
+
// Should be verified by the caller.
string protocol;
bool ok = parse_url(url, &protocol, &user, &host, &port, &path);
construct_header();
- pthread_mutex_init(&stats_mutex, nullptr);
stats.url = url;
stats.bytes_received = serialized.bytes_received();
stats.data_bytes_received = serialized.data_bytes_received();
InputProto UDPInput::serialize() const
{
+ // Unset the close-on-exec flag for the socket.
+ // (This can't leak into a child, since there's only one thread left.)
+ fcntl(sock, F_SETFD, 0);
+
InputProto serialized;
serialized.set_url(url);
serialized.set_sock(sock);
ret = recv(sock, packet_buf, sizeof(packet_buf), 0);
} while (ret == -1 && errno == EINTR);
- if (ret <= 0) {
+ if (ret < 0) { // Note that zero-byte packets are legal.
log_perror("recv");
close_socket();
continue;
}
{
- MutexLock lock(&stats_mutex);
+ lock_guard<mutex> lock(stats_mutex);
stats.bytes_received += ret;
stats.data_bytes_received += ret;
}
for (size_t stream_index : stream_indices) {
- servers->add_data(stream_index, packet_buf, ret, /*metacube_flags=*/0);
+ servers->add_data(stream_index, packet_buf, ret, /*metacube_flags=*/0, /*pts=*/RationalPTS());
}
}
}
InputStats UDPInput::get_stats() const
{
- MutexLock lock(&stats_mutex);
+ lock_guard<mutex> lock(stats_mutex);
return stats;
}