[Redirector] Add DNS timeout

This commit is contained in:
Connection Refused
2021-10-14 19:03:42 +08:00
parent 06f215cedf
commit 1bc80b71b4
3 changed files with 17 additions and 3 deletions

View File

@@ -398,11 +398,22 @@ int SocksHelper::UDP::Send(PSOCKADDR_IN6 target, const char* buffer, int length)
return length;
}
int SocksHelper::UDP::Read(PSOCKADDR_IN6 target, char* buffer, int length)
int SocksHelper::UDP::Read(PSOCKADDR_IN6 target, char* buffer, int length, PTIMEVAL timeout = NULL)
{
if (!this->udpSocket)
return SOCKET_ERROR;
if (timeout != NULL)
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(this->udpSocket, &fds);
int code = select(this->udpSocket, &fds, NULL, NULL, timeout);
if (code == 0 || code == SOCKET_ERROR)
return code;
}
int bufferLength = recvfrom(this->udpSocket, buffer, length, 0, NULL, NULL);
if (bufferLength == 0 || bufferLength == SOCKET_ERROR)
return bufferLength;