Add a 10 second read timeout to the RTSP connection

This commit is contained in:
Cameron Gutman 2016-02-16 09:31:33 -05:00
parent 8b6ca3d89b
commit 42af179770
3 changed files with 18 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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) {