mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Add a 10 second read timeout to the RTSP connection
This commit is contained in:
parent
8b6ca3d89b
commit
42af179770
@ -27,6 +27,20 @@ void shutdownTcpSocket(SOCKET s) {
|
||||
shutdown(s, SHUT_RDWR);
|
||||
}
|
||||
|
||||
void setRecvTimeout(SOCKET s, int timeoutSec) {
|
||||
#if defined(LC_WINDOWS)
|
||||
int val = timeoutSec * 1000;
|
||||
#else
|
||||
struct timeval val;
|
||||
val.tv_sec = timeoutSec;
|
||||
val.tv_usec = 0;
|
||||
#endif
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&val, sizeof(val)) < 0) {
|
||||
Limelog("setsockopt(SO_RCVTIMEO) failed: %d\n", (int)LastSocketError());
|
||||
}
|
||||
}
|
||||
|
||||
int recvUdpSocket(SOCKET s, char* buffer, int size) {
|
||||
fd_set readfds;
|
||||
int err;
|
||||
@ -50,7 +64,7 @@ int recvUdpSocket(SOCKET s, char* buffer, int size) {
|
||||
}
|
||||
|
||||
void closeSocket(SOCKET s) {
|
||||
#ifdef _WIN32
|
||||
#if defined(LC_WINDOWS)
|
||||
closesocket(s);
|
||||
#else
|
||||
close(s);
|
||||
|
@ -46,4 +46,5 @@ SOCKET bindUdpSocket(int addrfamily, int bufferSize);
|
||||
int enableNoDelay(SOCKET s);
|
||||
int recvUdpSocket(SOCKET s, char* buffer, int size);
|
||||
void shutdownTcpSocket(SOCKET s);
|
||||
void setRecvTimeout(SOCKET s, int timeoutSec);
|
||||
void closeSocket(SOCKET s);
|
@ -2,6 +2,7 @@
|
||||
#include "Rtsp.h"
|
||||
|
||||
#define RTSP_MAX_RESP_SIZE 32768
|
||||
#define RTSP_READ_TIMEOUT_SEC 10
|
||||
|
||||
static SOCKET sock = INVALID_SOCKET;
|
||||
static int currentSeqNumber;
|
||||
@ -93,6 +94,7 @@ static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, in
|
||||
return ret;
|
||||
}
|
||||
enableNoDelay(sock);
|
||||
setRecvTimeout(sock, RTSP_READ_TIMEOUT_SEC);
|
||||
|
||||
serializedMessage = serializeRtspMessage(request, &messageLen);
|
||||
if (serializedMessage == NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user