Skip to content
Snippets Groups Projects
Commit 549fd8fc authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Eloi Bail
Browse files

socket_pair: fix system socket

This patch tries to fix read errors on system socket when
no data available.

Issue: #80094
Change-Id: I7306bb32402983a939e9eca6cc4dbcc4d854685c
parent fefe9316
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,8 @@ namespace ring { ...@@ -71,6 +71,8 @@ namespace ring {
static constexpr int NET_POLL_TIMEOUT = 100; /* poll() timeout in ms */ static constexpr int NET_POLL_TIMEOUT = 100; /* poll() timeout in ms */
static constexpr int RTP_MAX_PACKET_LENGTH = 2048; static constexpr int RTP_MAX_PACKET_LENGTH = 2048;
enum class DataType : unsigned { RTP=1<<0, RTCP=1<<1 };
class SRTPProtoContext { class SRTPProtoContext {
public: public:
SRTPProtoContext(const char* out_suite, const char* out_key, SRTPProtoContext(const char* out_suite, const char* out_key,
...@@ -293,8 +295,8 @@ SocketPair::openSockets(const char* uri, int local_rtp_port) ...@@ -293,8 +295,8 @@ SocketPair::openSockets(const char* uri, int local_rtp_port)
throw std::runtime_error("Socket creation failed"); throw std::runtime_error("Socket creation failed");
} }
RING_WARN("SocketPair: local{%d,%d}, remote{%d,%d}", RING_WARN("SocketPair: local{%d,%d} / %s{%d,%d}",
local_rtp_port, local_rtcp_port, rtp_port, rtcp_port); local_rtp_port, local_rtcp_port, hostname, rtp_port, rtcp_port);
} }
MediaIOHandle* MediaIOHandle*
...@@ -322,9 +324,17 @@ SocketPair::waitForData() ...@@ -322,9 +324,17 @@ SocketPair::waitForData()
struct pollfd p[2] = { {rtpHandle_, POLLIN, 0}, struct pollfd p[2] = { {rtpHandle_, POLLIN, 0},
{rtcpHandle_, POLLIN, 0} }; {rtcpHandle_, POLLIN, 0} };
ret = poll(p, 2, NET_POLL_TIMEOUT); ret = poll(p, 2, NET_POLL_TIMEOUT);
} while (ret < 0 and errno == EAGAIN); if (ret > 0) {
ret = 0;
if (p[0].revents & POLLIN)
ret |= static_cast<int>(DataType::RTP);
if (p[1].revents & POLLIN)
ret |= static_cast<int>(DataType::RTCP);
}
} while (!ret or (ret < 0 and errno == EAGAIN));
return ret; return ret;
} }
// work with IceSocket // work with IceSocket
...@@ -338,7 +348,7 @@ SocketPair::waitForData() ...@@ -338,7 +348,7 @@ SocketPair::waitForData()
return -1; return -1;
} }
return 0; return static_cast<int>(DataType::RTP) | static_cast<int>(DataType::RTCP);
} }
int int
...@@ -396,22 +406,26 @@ SocketPair::readRtcpData(void* buf, int buf_size) ...@@ -396,22 +406,26 @@ SocketPair::readRtcpData(void* buf, int buf_size)
int int
SocketPair::readCallback(uint8_t* buf, int buf_size) SocketPair::readCallback(uint8_t* buf, int buf_size)
{ {
while (1) { auto datatype = waitForData();
auto ret = waitForData(); if (datatype < 0)
if (ret < 0) return datatype;
return ret;
int len = 0;
bool fromRTCP = false;
// Priority to RTCP as its less invasive in bandwidth // Priority to RTCP as its less invasive in bandwidth
auto len = readRtcpData(buf, buf_size); if (datatype & static_cast<int>(DataType::RTCP)) {
bool fromRTCP = true; len = readRtcpData(buf, buf_size);
fromRTCP = true;
}
// No RTCP... try RTP // No RTCP... try RTP
if (len == 0) { if (!len and (datatype & static_cast<int>(DataType::RTP))) {
len = readRtpData(buf, buf_size); len = readRtpData(buf, buf_size);
fromRTCP = false; fromRTCP = false;
} }
if (len < 0) if (len <= 0)
return len; return len;
// SRTP decrypt // SRTP decrypt
...@@ -423,7 +437,6 @@ SocketPair::readCallback(uint8_t* buf, int buf_size) ...@@ -423,7 +437,6 @@ SocketPair::readCallback(uint8_t* buf, int buf_size)
return len; return len;
} }
}
int int
SocketPair::writeData(uint8_t* buf, int buf_size) SocketPair::writeData(uint8_t* buf, int buf_size)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment