TAPServer_Apple: Use fmt logging

This commit is contained in:
Pokechu22 2022-05-19 12:41:45 -07:00
parent a86fb9b475
commit 0faf0b80ad
1 changed files with 12 additions and 11 deletions

View File

@ -8,6 +8,7 @@
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
#include "Common/CommonFuncs.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/HW/EXI/EXI_Device.h" #include "Core/HW/EXI/EXI_Device.h"
@ -29,7 +30,7 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate()
sockaddr_un sun = {}; sockaddr_un sun = {};
if (sizeof(socket_path) > sizeof(sun.sun_path)) if (sizeof(socket_path) > sizeof(sun.sun_path))
{ {
ERROR_LOG(SP1, "Socket path is too long, unable to init BBA"); ERROR_LOG_FMT(SP1, "Socket path is too long, unable to init BBA");
return false; return false;
} }
sun.sun_family = AF_UNIX; sun.sun_family = AF_UNIX;
@ -38,19 +39,19 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate()
fd = socket(AF_UNIX, SOCK_STREAM, 0); fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) if (fd == -1)
{ {
ERROR_LOG(SP1, "Couldn't create socket, unable to init BBA"); ERROR_LOG_FMT(SP1, "Couldn't create socket, unable to init BBA");
return false; return false;
} }
if (connect(fd, reinterpret_cast<sockaddr*>(&sun), sizeof(sun)) == -1) if (connect(fd, reinterpret_cast<sockaddr*>(&sun), sizeof(sun)) == -1)
{ {
ERROR_LOG(SP1, "Couldn't connect socket (%d), unable to init BBA", errno); ERROR_LOG_FMT(SP1, "Couldn't connect socket ({}), unable to init BBA", LastStrerrorString());
close(fd); close(fd);
fd = -1; fd = -1;
return false; return false;
} }
INFO_LOG(SP1, "BBA initialized.\n"); INFO_LOG_FMT(SP1, "BBA initialized.");
return RecvInit(); return RecvInit();
} }
@ -58,19 +59,19 @@ bool CEXIETHERNET::TAPServerNetworkInterface::SendFrame(const u8* frame, u32 siz
{ {
{ {
const std::string s = ArrayToString(frame, size, 0x10); const std::string s = ArrayToString(frame, size, 0x10);
INFO_LOG(SP1, "SendFrame %x\n%s\n", size, s.c_str()); INFO_LOG_FMT(SP1, "SendFrame {}\n{}", size, s);
} }
auto size16 = u16(size); auto size16 = u16(size);
if (write(fd, &size16, 2) != 2) if (write(fd, &size16, 2) != 2)
{ {
ERROR_LOG(SP1, "SendFrame(): could not write size field\n"); ERROR_LOG_FMT(SP1, "SendFrame(): could not write size field");
return false; return false;
} }
int written_bytes = write(fd, frame, size); int written_bytes = write(fd, frame, size);
if (u32(written_bytes) != size) if (u32(written_bytes) != size)
{ {
ERROR_LOG(SP1, "SendFrame(): expected to write %d bytes, instead wrote %d", size, ERROR_LOG_FMT(SP1, "SendFrame(): expected to write {} bytes, instead wrote {}", size,
written_bytes); written_bytes);
return false; return false;
} }
@ -98,19 +99,19 @@ void CEXIETHERNET::TAPServerNetworkInterface::ReadThreadHandler()
u16 size; u16 size;
if (read(fd, &size, 2) != 2) if (read(fd, &size, 2) != 2)
{ {
ERROR_LOG(SP1, "Failed to read size field from BBA, err=%d", errno); ERROR_LOG_FMT(SP1, "Failed to read size field from BBA: {}", LastStrerrorString());
} }
else else
{ {
int read_bytes = read(fd, m_eth_ref->mRecvBuffer.get(), size); int read_bytes = read(fd, m_eth_ref->mRecvBuffer.get(), size);
if (read_bytes < 0) if (read_bytes < 0)
{ {
ERROR_LOG(SP1, "Failed to read packet data from BBA, err=%d", errno); ERROR_LOG_FMT(SP1, "Failed to read packet data from BBA: {}", LastStrerrorString());
} }
else if (readEnabled.IsSet()) else if (readEnabled.IsSet())
{ {
std::string data_string = ArrayToString(m_eth_ref->mRecvBuffer.get(), read_bytes, 0x10); std::string data_string = ArrayToString(m_eth_ref->mRecvBuffer.get(), read_bytes, 0x10);
INFO_LOG(SP1, "Read data: %s", data_string.c_str()); INFO_LOG_FMT(SP1, "Read data: {}", data_string);
m_eth_ref->mRecvBufferLength = read_bytes; m_eth_ref->mRecvBufferLength = read_bytes;
m_eth_ref->RecvHandlePacket(); m_eth_ref->RecvHandlePacket();
} }