Skip to content

Commit

Permalink
Set POLLRDHUP on Linux when polling rtpproxy's socket to drain
Browse files Browse the repository at this point in the history
any unclaimed data. This seems to be necessary on TCP sockets
otherwise poll() appears to hang indefinitely if rtpproxy has been
terminated despite timeout being set to 0 (i.e. don't block).

With this flag set the disconnect is properly detected and socket
is re-connected after configured timeout.
  • Loading branch information
sobomax committed Mar 23, 2023
1 parent 9f6b7fc commit 4097ca5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/rtpproxy/rtpproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
* (osas)
*/

#define _GNU_SOURCE

#include <sys/types.h>
#include <netinet/in.h>
#ifndef __USE_BSD
Expand Down Expand Up @@ -325,6 +327,9 @@ int update_rtpp_proxies();

static inline void raise_rtpproxy_event(struct rtpp_node *node, int status);

#if !defined(POLLRDHUP)
#define POLLRDHUP 0
#endif

static struct {
const char *s;
Expand Down Expand Up @@ -2128,12 +2133,12 @@ send_rtpp_command(struct rtpp_node *node, struct iovec *v, int vcnt)
}
} else {
fds[0].fd = rtpp_socks[node->idx];
fds[0].events = POLLIN;
fds[0].events = POLLIN | POLLRDHUP;
fds[0].revents = 0;
/* Drain input buffer */
while ((poll(fds, 1, 0) == 1) &&
((fds[0].revents & POLLIN) != 0)) {
if (fds[0].revents & (POLLERR|POLLNVAL)) {
if (fds[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) {
LM_ERR("error on rtpproxy socket %d!\n", rtpp_socks[node->idx]);
break;
}
Expand Down

0 comments on commit 4097ca5

Please sign in to comment.