DEV9: Merge _DEV9open into InitNet, and check ethEnable before calling

This commit is contained in:
TheLastRar 2021-02-07 00:49:58 +00:00 committed by refractionpcsx2
parent 7187b883b0
commit 0800cdbbc2
6 changed files with 38 additions and 76 deletions

View File

@ -219,7 +219,10 @@ s32 DEV9open(void* pDsp)
config.hddEnable = false;
}
return _DEV9open();
if (config.ethEnable)
InitNet();
return 0;
}
void DEV9close()
@ -227,7 +230,7 @@ void DEV9close()
DevCon.WriteLn("DEV9close");
dev9.ata->Close();
_DEV9close();
TermNet();
}
int DEV9irqHandler(void)

View File

@ -135,10 +135,6 @@ EXTERN dev9Struct dev9;
EXTERN int ThreadRun;
s32 _DEV9open();
void _DEV9close();
//void DEV9thread();
//Yes these are meant to be a lowercase extern
extern std::string s_strIniPath;
extern std::string s_strLogPath;

View File

@ -219,35 +219,3 @@ void DEV9configure()
gtk_widget_hide(GTK_WIDGET(dlg));
paused_core.AllowResume();
}
NetAdapter* GetNetAdapter()
{
NetAdapter* na;
na = new PCAPAdapter();
if (!na->isInitialised())
{
delete na;
return 0;
}
return na;
}
s32 _DEV9open()
{
NetAdapter* na = GetNetAdapter();
if (!na)
{
Console.Error("Failed to GetNetAdapter()");
config.ethEnable = false;
}
else
{
InitNet(na);
}
return 0;
}
void _DEV9close()
{
TermNet();
}

View File

@ -372,38 +372,3 @@ UINT DEV9ThreadProc() {
return 0;
}*/
NetAdapter* GetNetAdapter()
{
NetAdapter* na = static_cast<NetAdapter*>(new TAPAdapter());
if (!na->isInitialised())
{
delete na;
return 0;
}
return na;
}
s32 _DEV9open()
{
//handleDEV9Thread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) DEV9ThreadProc, &dwThrdParam, CREATE_SUSPENDED, &dwThreadId);
//SetThreadPriority(handleDEV9Thread,THREAD_PRIORITY_HIGHEST);
//ResumeThread (handleDEV9Thread);
NetAdapter* na = GetNetAdapter();
if (!na)
{
Console.Error("Failed to GetNetAdapter()");
config.ethEnable = false;
}
else
{
InitNet(na);
}
return 0;
}
void _DEV9close()
{
//TerminateThread(handleDEV9Thread,0);
//handleDEV9Thread = NULL;
TermNet();
}

View File

@ -23,6 +23,11 @@
#include "net.h"
#include "DEV9.h"
#ifdef _WIN32
#include "Win32\tap.h"
#endif
#include "pcap_io.h"
NetAdapter* nif;
std::thread rx_thread;
@ -48,9 +53,34 @@ void tx_put(NetPacket* pkt)
//pkt must be copied if its not processed by here, since it can be allocated on the callers stack
}
void InitNet(NetAdapter* ad)
NetAdapter* GetNetAdapter()
{
nif = ad;
#ifdef _WIN32
NetAdapter* na = static_cast<NetAdapter*>(new TAPAdapter());
#else
NetAdapter* na = static_cast<NetAdapter*>(new PCAPAdapter());
#endif
if (!na->isInitialised())
{
delete na;
return nullptr;
}
return na;
}
void InitNet()
{
NetAdapter* na = GetNetAdapter();
if (!na)
{
Console.Error("Failed to GetNetAdapter()");
config.ethEnable = false;
return;
}
nif = na;
RxRunning = true;
rx_thread = std::thread(NetRxThread);

View File

@ -56,5 +56,5 @@ protected:
};
void tx_put(NetPacket* ptr);
void InitNet(NetAdapter* adapter);
void InitNet();
void TermNet();