Use SO_RCVTIMEO to avoid the overhead of an extra syscall per packet

This commit is contained in:
Cameron Gutman
2018-07-16 00:42:55 -07:00
parent a9438d1f5e
commit 6e7965f013
5 changed files with 71 additions and 21 deletions

View File

@@ -65,12 +65,22 @@ static void ReceiveThreadProc(void* context) {
int bufferSize, receiveSize;
char* buffer;
int queueStatus;
int useSelect;
PRTPFEC_QUEUE_ENTRY queueEntry;
receiveSize = StreamConfig.packetSize + MAX_RTP_HEADER_SIZE;
bufferSize = receiveSize + sizeof(RTPFEC_QUEUE_ENTRY);
buffer = NULL;
if (setNonFatalRecvTimeoutMs(rtpSocket, UDP_RECV_POLL_TIMEOUT_MS) < 0) {
// SO_RCVTIMEO failed, so use select() to wait
useSelect = 1;
}
else {
// SO_RCVTIMEO timeout set for recv()
useSelect = 0;
}
while (!PltIsThreadInterrupted(&receiveThread)) {
PRTP_PACKET packet;
@@ -83,7 +93,7 @@ static void ReceiveThreadProc(void* context) {
}
}
err = recvUdpSocket(rtpSocket, buffer, receiveSize);
err = recvUdpSocket(rtpSocket, buffer, receiveSize, useSelect);
if (err < 0) {
Limelog("Video Receive: recvUdpSocket() failed: %d\n", (int)LastSocketError());
ListenerCallbacks.connectionTerminated(LastSocketError());