Retry connection after EOF count exceeded

This commit is contained in:
EnderIce2 2024-05-07 22:09:04 +03:00
parent 418e53e7f7
commit 5d0e6c4026
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -299,11 +299,13 @@ void ConnectToSocket(int fd)
} }
} }
HANDLE hOut = NULL;
void PipeBufferInThread(LPVOID lpParam) void PipeBufferInThread(LPVOID lpParam)
{ {
bridge_thread *bt = (bridge_thread *)lpParam; bridge_thread *bt = (bridge_thread *)lpParam;
print("In thread started using fd %d and pipe %#x\n", print("In thread started using fd %d and pipe %#x\n",
bt->fd, bt->hPipe); bt->fd, bt->hPipe);
int EOFCount = 0;
while (TRUE) while (TRUE)
{ {
char buffer[1024]; char buffer[1024];
@ -317,12 +319,22 @@ void PipeBufferInThread(LPVOID lpParam)
continue; continue;
} }
if (EOFCount > 4)
{
print("EOF count exceeded\n");
RetryNewConnection = TRUE;
TerminateThread(hOut, 0);
break;
}
if (unlikely(read == 0)) if (unlikely(read == 0))
{ {
print("EOF\n"); print("EOF\n");
Sleep(1000); Sleep(1000);
EOFCount++;
continue; continue;
} }
EOFCount = 0;
print("Reading %d bytes from unix pipe: \"", read); print("Reading %d bytes from unix pipe: \"", read);
for (int i = 0; i < read; i++) for (int i = 0; i < read; i++)
@ -523,7 +535,7 @@ NewConnection:
(LPVOID)&bt, (LPVOID)&bt,
0, NULL); 0, NULL);
HANDLE hOut = CreateThread(NULL, 0, hOut = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)PipeBufferOutThread, (LPTHREAD_START_ROUTINE)PipeBufferOutThread,
(LPVOID)&bt, (LPVOID)&bt,
0, NULL); 0, NULL);