mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Cancel read of TAP device on suspend/shutdown
CancelIo() must be performed on the thread that started the IO operation, hence the use of an event.
This commit is contained in:
parent
f19985c410
commit
54651731f9
|
@ -271,6 +271,9 @@ TAPAdapter::TAPAdapter()
|
|||
write.Offset = 0;
|
||||
write.OffsetHigh = 0;
|
||||
write.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
|
||||
cancel = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
|
@ -298,9 +301,20 @@ bool TAPAdapter::recv(NetPacket* pkt)
|
|||
DWORD dwError = GetLastError();
|
||||
if (dwError == ERROR_IO_PENDING)
|
||||
{
|
||||
WaitForSingleObject(read.hEvent, INFINITE);
|
||||
result = GetOverlappedResult(htap, &read,
|
||||
&read_size, FALSE);
|
||||
HANDLE readHandles[]{read.hEvent, cancel};
|
||||
const DWORD waitResult = WaitForMultipleObjects(2, readHandles, FALSE, INFINITE);
|
||||
|
||||
if (waitResult == WAIT_OBJECT_0 + 1)
|
||||
{
|
||||
CancelIo(htap);
|
||||
//Wait for the I/O subsystem to acknowledge our cancellation
|
||||
result = GetOverlappedResult(htap, &read,
|
||||
&read_size, TRUE);
|
||||
}
|
||||
else
|
||||
result = GetOverlappedResult(htap, &read,
|
||||
&read_size, FALSE);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
}
|
||||
|
@ -367,12 +381,17 @@ bool TAPAdapter::send(NetPacket* pkt)
|
|||
else
|
||||
return false;
|
||||
}
|
||||
void TAPAdapter::close()
|
||||
{
|
||||
SetEvent(cancel);
|
||||
}
|
||||
TAPAdapter::~TAPAdapter()
|
||||
{
|
||||
if (!isActive)
|
||||
return;
|
||||
CloseHandle(read.hEvent);
|
||||
CloseHandle(write.hEvent);
|
||||
CloseHandle(cancel);
|
||||
TAPSetStatus(htap, FALSE);
|
||||
CloseHandle(htap);
|
||||
isActive = false;
|
||||
|
|
|
@ -29,6 +29,7 @@ class TAPAdapter : public NetAdapter
|
|||
{
|
||||
HANDLE htap;
|
||||
OVERLAPPED read, write;
|
||||
HANDLE cancel;
|
||||
bool isActive = false;
|
||||
|
||||
public:
|
||||
|
@ -39,5 +40,6 @@ public:
|
|||
virtual bool recv(NetPacket* pkt);
|
||||
//sends the packet and deletes it when done (if successful).rv :true success
|
||||
virtual bool send(NetPacket* pkt);
|
||||
virtual void close();
|
||||
virtual ~TAPAdapter();
|
||||
};
|
||||
|
|
|
@ -73,6 +73,7 @@ void TermNet()
|
|||
if (RxRunning)
|
||||
{
|
||||
RxRunning = false;
|
||||
nif->close();
|
||||
emu_printf("Waiting for RX-net thread to terminate..");
|
||||
rx_thread.join();
|
||||
emu_printf(".done\n");
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
virtual bool isInitialised() = 0;
|
||||
virtual bool recv(NetPacket* pkt) = 0; //gets a packet
|
||||
virtual bool send(NetPacket* pkt) = 0; //sends the packet and deletes it when done
|
||||
virtual void close() {}
|
||||
virtual ~NetAdapter() {}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue