1 #include <sys/socket.h>
9 #ifndef SO_MAX_PACING_RATE
10 #define SO_MAX_PACING_RATE 47
13 UDPStream::UDPStream(const sockaddr_in6 &dst, MarkPool *mark_pool, uint32_t pacing_rate)
17 pacing_rate(pacing_rate)
19 sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
21 // Oops. Ignore this output, then.
26 if (mark_pool != NULL) {
27 fwmark = mark_pool->get_mark();
28 if (setsockopt(sock, SOL_SOCKET, SO_MARK, &fwmark, sizeof(fwmark)) == -1) {
30 log_perror("setsockopt(SO_MARK)");
34 if (setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, &pacing_rate, sizeof(pacing_rate)) == -1) {
35 if (pacing_rate != ~0U) {
36 log_perror("setsockopt(SO_MAX_PACING_RATE)");
41 UDPStream::~UDPStream()
46 if (mark_pool != NULL) {
47 mark_pool->release_mark(fwmark);
51 void UDPStream::send(const char *data, size_t bytes)
56 ssize_t err = sendto(sock, data, bytes, 0, reinterpret_cast<sockaddr *>(&dst), sizeof(dst));