EXI: Use unique_ptr in CEXIEthernet
This commit is contained in:
parent
e75d37ec36
commit
98e5270b3c
|
@ -75,14 +75,14 @@ static void ReadThreadHandler(CEXIETHERNET* self)
|
|||
if (select(self->fd + 1, &rfds, nullptr, nullptr, &timeout) <= 0)
|
||||
continue;
|
||||
|
||||
int readBytes = read(self->fd, self->mRecvBuffer, BBA_RECV_SIZE);
|
||||
int readBytes = read(self->fd, self->mRecvBuffer.get(), BBA_RECV_SIZE);
|
||||
if (readBytes < 0)
|
||||
{
|
||||
ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes);
|
||||
}
|
||||
else if (self->readEnabled.IsSet())
|
||||
{
|
||||
INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str());
|
||||
INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer.get(), readBytes, 0x10).c_str());
|
||||
self->mRecvBufferLength = readBytes;
|
||||
self->RecvHandlePacket();
|
||||
}
|
||||
|
|
|
@ -137,14 +137,14 @@ static void ReadThreadHandler(CEXIETHERNET* self)
|
|||
if (select(self->fd + 1, &rfds, nullptr, nullptr, &timeout) <= 0)
|
||||
continue;
|
||||
|
||||
int readBytes = read(self->fd, self->mRecvBuffer, BBA_RECV_SIZE);
|
||||
int readBytes = read(self->fd, self->mRecvBuffer.get(), BBA_RECV_SIZE);
|
||||
if (readBytes < 0)
|
||||
{
|
||||
ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes);
|
||||
}
|
||||
else if (self->readEnabled.IsSet())
|
||||
{
|
||||
INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str());
|
||||
INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer.get(), readBytes, 0x10).c_str());
|
||||
self->mRecvBufferLength = readBytes;
|
||||
self->RecvHandlePacket();
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ static void ReadThreadHandler(CEXIETHERNET* self)
|
|||
DWORD transferred;
|
||||
|
||||
// Read from TAP into internal buffer.
|
||||
if (ReadFile(self->mHAdapter, self->mRecvBuffer, BBA_RECV_SIZE, &transferred, &self->mReadOverlapped))
|
||||
if (ReadFile(self->mHAdapter, self->mRecvBuffer.get(), BBA_RECV_SIZE, &transferred, &self->mReadOverlapped))
|
||||
{
|
||||
// Returning immediately is not likely to happen, but if so, reset the event state manually.
|
||||
ResetEvent(self->mReadOverlapped.hEvent);
|
||||
|
@ -298,7 +298,7 @@ static void ReadThreadHandler(CEXIETHERNET* self)
|
|||
}
|
||||
|
||||
// Copy to BBA buffer, and fire interrupt if enabled.
|
||||
DEBUG_LOG(SP1, "Received %u bytes\n: %s", transferred, ArrayToString(self->mRecvBuffer, transferred, 0x10).c_str());
|
||||
DEBUG_LOG(SP1, "Received %u bytes\n: %s", transferred, ArrayToString(self->mRecvBuffer.get(), transferred, 0x10).c_str());
|
||||
if (self->readEnabled.IsSet())
|
||||
{
|
||||
self->mRecvBufferLength = transferred;
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
CEXIETHERNET::CEXIETHERNET()
|
||||
{
|
||||
tx_fifo = new u8[BBA_TXFIFO_SIZE];
|
||||
mBbaMem = new u8[BBA_MEM_SIZE];
|
||||
tx_fifo = std::make_unique<u8[]>(BBA_TXFIFO_SIZE);
|
||||
mBbaMem = std::make_unique<u8[]>(BBA_MEM_SIZE);
|
||||
|
||||
mRecvBuffer = new u8[BBA_RECV_SIZE];
|
||||
mRecvBuffer = std::make_unique<u8[]>(BBA_RECV_SIZE);
|
||||
mRecvBufferLength = 0;
|
||||
|
||||
MXHardReset();
|
||||
|
@ -58,10 +58,6 @@ CEXIETHERNET::CEXIETHERNET()
|
|||
CEXIETHERNET::~CEXIETHERNET()
|
||||
{
|
||||
Deactivate();
|
||||
|
||||
delete[] tx_fifo;
|
||||
delete[] mBbaMem;
|
||||
delete[] mRecvBuffer;
|
||||
}
|
||||
|
||||
void CEXIETHERNET::SetCS(int cs)
|
||||
|
@ -206,8 +202,8 @@ void CEXIETHERNET::DMARead(u32 addr, u32 size)
|
|||
|
||||
void CEXIETHERNET::DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(tx_fifo, BBA_TXFIFO_SIZE);
|
||||
p.DoArray(mBbaMem, BBA_MEM_SIZE);
|
||||
p.DoArray(tx_fifo.get(), BBA_TXFIFO_SIZE);
|
||||
p.DoArray(mBbaMem.get(), BBA_MEM_SIZE);
|
||||
}
|
||||
|
||||
bool CEXIETHERNET::IsMXCommand(u32 const data)
|
||||
|
@ -298,7 +294,7 @@ const char* CEXIETHERNET::GetRegisterName() const
|
|||
|
||||
void CEXIETHERNET::MXHardReset()
|
||||
{
|
||||
memset(mBbaMem, 0, BBA_MEM_SIZE);
|
||||
memset(mBbaMem.get(), 0, BBA_MEM_SIZE);
|
||||
|
||||
mBbaMem[BBA_NCRB] = NCRB_PR;
|
||||
mBbaMem[BBA_NWAYC] = NWAYC_LTE | NWAYC_ANE;
|
||||
|
@ -384,7 +380,7 @@ void CEXIETHERNET::DirectFIFOWrite(u8 *data, u32 size)
|
|||
|
||||
u16 *tx_fifo_count = (u16 *)&mBbaMem[BBA_TXFIFOCNT];
|
||||
|
||||
memcpy(tx_fifo + *tx_fifo_count, data, size);
|
||||
memcpy(tx_fifo.get() + *tx_fifo_count, data, size);
|
||||
|
||||
*tx_fifo_count += size;
|
||||
// TODO: not sure this mask is correct.
|
||||
|
@ -395,7 +391,7 @@ void CEXIETHERNET::DirectFIFOWrite(u8 *data, u32 size)
|
|||
|
||||
void CEXIETHERNET::SendFromDirectFIFO()
|
||||
{
|
||||
SendFrame(tx_fifo, *(u16 *)&mBbaMem[BBA_TXFIFOCNT]);
|
||||
SendFrame(tx_fifo.get(), *(u16 *)&mBbaMem[BBA_TXFIFOCNT]);
|
||||
}
|
||||
|
||||
void CEXIETHERNET::SendFromPacketBuffer()
|
||||
|
@ -452,9 +448,9 @@ inline bool CEXIETHERNET::RecvMACFilter()
|
|||
// Unicast?
|
||||
if ((mRecvBuffer[0] & 0x01) == 0)
|
||||
{
|
||||
return memcmp(mRecvBuffer, &mBbaMem[BBA_NAFR_PAR0], 6) == 0;
|
||||
return memcmp(mRecvBuffer.get(), &mBbaMem[BBA_NAFR_PAR0], 6) == 0;
|
||||
}
|
||||
else if (memcmp(mRecvBuffer, broadcast, 6) == 0)
|
||||
else if (memcmp(mRecvBuffer.get(), broadcast, 6) == 0)
|
||||
{
|
||||
// Accept broadcast?
|
||||
return !!(mBbaMem[BBA_NCRB] & NCRB_AB);
|
||||
|
@ -467,7 +463,7 @@ inline bool CEXIETHERNET::RecvMACFilter()
|
|||
else
|
||||
{
|
||||
// Lookup the dest eth address in the hashmap
|
||||
u16 index = HashIndex(mRecvBuffer);
|
||||
u16 index = HashIndex(mRecvBuffer.get());
|
||||
return !!(mBbaMem[BBA_NAFR_MAR0 + index / 8] & (1 << (index % 8)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,8 +310,8 @@ public:
|
|||
void inc_rwp();
|
||||
bool RecvHandlePacket();
|
||||
|
||||
u8 *tx_fifo;
|
||||
u8 *mBbaMem;
|
||||
std::unique_ptr<u8[]> mBbaMem;
|
||||
std::unique_ptr<u8[]> tx_fifo;
|
||||
|
||||
// TAP interface
|
||||
bool Activate();
|
||||
|
@ -322,7 +322,7 @@ public:
|
|||
void RecvStart();
|
||||
void RecvStop();
|
||||
|
||||
u8 *mRecvBuffer;
|
||||
std::unique_ptr<u8[]> mRecvBuffer;
|
||||
u32 mRecvBufferLength;
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
|
Loading…
Reference in New Issue