mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-19 22:50:11 +00:00
Use SO_RCVTIMEO to avoid the overhead of an extra syscall per packet
This commit is contained in:
@@ -151,9 +151,19 @@ static void ReceiveThreadProc(void* context) {
|
||||
PRTP_PACKET rtp;
|
||||
PQUEUED_AUDIO_PACKET packet;
|
||||
int queueStatus;
|
||||
int useSelect;
|
||||
|
||||
packet = 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)) {
|
||||
if (packet == NULL) {
|
||||
packet = (PQUEUED_AUDIO_PACKET)malloc(sizeof(*packet));
|
||||
@@ -164,7 +174,7 @@ static void ReceiveThreadProc(void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
packet->size = recvUdpSocket(rtpSocket, &packet->data[0], MAX_PACKET_SIZE);
|
||||
packet->size = recvUdpSocket(rtpSocket, &packet->data[0], MAX_PACKET_SIZE, useSelect);
|
||||
if (packet->size < 0) {
|
||||
Limelog("Audio Receive: recvUdpSocket() failed: %d\n", (int)LastSocketError());
|
||||
ListenerCallbacks.connectionTerminated(LastSocketError());
|
||||
|
||||
Reference in New Issue
Block a user