Skip to content

Commit

Permalink
udp_set_{recv,send}_buf: print newly set bufsz
Browse files Browse the repository at this point in the history
improved debug print:
- print in any case (if it succeeded and also failed)
- if set to value more of same, print in debug, if the set value is less
than requested print in verbose mode

\+ factor out common handling to common function
  • Loading branch information
MartinPulec committed Sep 20, 2023
1 parent fca6833 commit 97b956f
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions src/rtp/net_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,56 +1433,42 @@ static int resolve_address(socket_udp *s, const char *addr, uint16_t tx_port)
return ret;
}

bool udp_set_recv_buf(socket_udp *s, int size)
static bool
udp_set_buf(socket_udp *s, int sockopt, int size)
{
int opt = 0;
socklen_t opt_size;
if (SETSOCKOPT(s->local->rx_fd, SOL_SOCKET, SO_RCVBUF, (sockopt_t) &size,
if (SETSOCKOPT(s->local->tx_fd, SOL_SOCKET, sockopt, (sockopt_t) &size,
sizeof(size)) != 0) {
socket_error("Unable to set socket buffer size");
return false;
}

opt_size = sizeof(opt);
if(GETSOCKOPT (s->local->rx_fd, SOL_SOCKET, SO_RCVBUF, (sockopt_t)&opt,
if(GETSOCKOPT (s->local->tx_fd, SOL_SOCKET, sockopt, (sockopt_t)&opt,
&opt_size) != 0) {
socket_error("Unable to get socket buffer size");
return false;
}

if(opt < size) {
return false;
}

verbose_msg("Socket recv buffer size set to %d B.\n", opt);

return true;
const bool ret = opt >= size;
log_msg(ret ? LOG_LEVEL_DEBUG : LOG_LEVEL_VERBOSE,
"Socket %s buffer size set to %d B%srequested %d B%s\n",
sockopt == SO_RCVBUF ? "recv" : "send", opt,
ret ? " (" : ", ", size, ret ? "" : "!");
return ret;
}

bool udp_set_send_buf(socket_udp *s, int size)
bool
udp_set_recv_buf(socket_udp *s, int size)
{
int opt = 0;
socklen_t opt_size;
if (SETSOCKOPT(s->local->tx_fd, SOL_SOCKET, SO_SNDBUF, (sockopt_t) &size,
sizeof(size)) != 0) {
socket_error("Unable to set socket buffer size");
return false;
}

opt_size = sizeof(opt);
if(GETSOCKOPT (s->local->tx_fd, SOL_SOCKET, SO_SNDBUF, (sockopt_t)&opt,
&opt_size) != 0) {
socket_error("Unable to get socket buffer size");
return false;
}

if(opt < size) {
return false;
}

verbose_msg("Socket send buffer size set to %d B.\n", opt);
return udp_set_buf(s, SO_RCVBUF, size);
}

return true;
bool
udp_set_send_buf(socket_udp *s, int size)
{
return udp_set_buf(s, SO_SNDBUF, size);
}

/*
Expand Down

0 comments on commit 97b956f

Please sign in to comment.