diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index d66207a822..b27955ce84 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -61,7 +61,7 @@ CWII_IPC_HLE_Device_net_kd_request::CWII_IPC_HLE_Device_net_kd_request(u32 _Devi CWII_IPC_HLE_Device_net_kd_request::~CWII_IPC_HLE_Device_net_kd_request() { - WiiSockMan::getInstance().clean(); + WiiSockMan::GetInstance().Clean(); } bool CWII_IPC_HLE_Device_net_kd_request::Open(u32 _CommandAddress, u32 _Mode) @@ -660,8 +660,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 type = Memory::Read_U32(BufferIn + 0x04); u32 prot = Memory::Read_U32(BufferIn + 0x08); - WiiSockMan &sm = WiiSockMan::getInstance(); - ReturnValue = sm.newSocket(af, type, prot); + WiiSockMan &sm = WiiSockMan::GetInstance(); + ReturnValue = sm.NewSocket(af, type, prot); INFO_LOG(WII_IPC_NET, "IOCTL_SO_SOCKET " "Socket: %08x (%d,%d,%d), BufferIn: (%08x, %i), BufferOut: (%08x, %i)", ReturnValue, af, type, prot, BufferIn, BufferInSize, BufferOut, BufferOutSize); @@ -671,8 +671,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) { u32 pf = Memory::Read_U32(BufferIn); - WiiSockMan &sm = WiiSockMan::getInstance(); - ReturnValue = sm.newSocket(pf, SOCK_RAW, IPPROTO_ICMP); + WiiSockMan &sm = WiiSockMan::GetInstance(); + ReturnValue = sm.NewSocket(pf, SOCK_RAW, IPPROTO_ICMP); INFO_LOG(WII_IPC_NET, "IOCTL_SO_ICMPSOCKET(%x) %d", pf, ReturnValue); break; } @@ -680,8 +680,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) case IOCTL_SO_ICMPCLOSE: { u32 fd = Memory::Read_U32(BufferIn); - WiiSockMan &sm = WiiSockMan::getInstance(); - ReturnValue = sm.delSocket(fd); + WiiSockMan &sm = WiiSockMan::GetInstance(); + ReturnValue = sm.DeleteSocket(fd); DEBUG_LOG(WII_IPC_NET, "%s(%x) %x", Command == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE", fd, ReturnValue); @@ -693,8 +693,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) case IOCTL_SO_FCNTL: { u32 fd = Memory::Read_U32(BufferIn); - WiiSockMan &sm = WiiSockMan::getInstance(); - sm.doSock(fd, _CommandAddress, (NET_IOCTL)Command); + WiiSockMan &sm = WiiSockMan::GetInstance(); + sm.DoSock(fd, _CommandAddress, (NET_IOCTL)Command); return false; } ///////////////////////////////////////////////////////////// @@ -709,7 +709,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 fd = Memory::Read_U32(BufferIn); u32 how = Memory::Read_U32(BufferIn+4); int ret = shutdown(fd, how); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_SHUTDOWN", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_SHUTDOWN", false); break; } case IOCTL_SO_LISTEN: @@ -718,7 +718,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 fd = Memory::Read_U32(BufferIn); u32 BACKLOG = Memory::Read_U32(BufferIn + 0x04); u32 ret = listen(fd, BACKLOG); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_LISTEN", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_LISTEN", false); INFO_LOG(WII_IPC_NET, "IOCTL_SO_LISTEN = %d " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)", ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize); @@ -750,7 +750,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 optlen = 4; int ret = getsockopt (fd, nat_level, nat_optname, (char *) &optval, (socklen_t*)&optlen); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_GETSOCKOPT", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_GETSOCKOPT", false); Memory::Write_U32(optlen, BufferOut + 0xC); @@ -758,7 +758,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) if (optname == SO_ERROR) { - s32 last_error = WiiSockMan::getInstance().getLastNetError(); + s32 last_error = WiiSockMan::GetInstance().GetLastNetError(); Memory::Write_U32(sizeof(s32), BufferOut + 0xC); Memory::Write_U32(last_error, BufferOut + 0x10); @@ -807,7 +807,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) } int ret = setsockopt(fd, nat_level, nat_optname, (char*)optval, optlen); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_SETSOCKOPT", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_SETSOCKOPT", false); break; } case IOCTL_SO_GETSOCKNAME: @@ -946,7 +946,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) } int ret = poll(ufds, nfds, timeout); - ret = WiiSockMan::getNetErrorCode(ret, "SO_POLL", false); + ret = WiiSockMan::GetNetErrorCode(ret, "SO_POLL", false); for (int i = 0; i= 0) { - WiiSockMan::getInstance().setLastNetError(ret); + WiiSockMan::GetInstance().SetLastNetError(ret); return ret; } INFO_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d", caller.c_str(), errorCode, DecodeError(errorCode), ret); - s32 ReturnValue = translateErrorCode(errorCode, isRW); - WiiSockMan::getInstance().setLastNetError(ReturnValue); + s32 ReturnValue = TranslateErrorCode(errorCode, isRW); + WiiSockMan::GetInstance().SetLastNetError(ReturnValue); return ReturnValue; } @@ -104,14 +104,14 @@ WiiSocket::~WiiSocket() { if (fd >= 0) { - (void)closeFd(); + (void)CloseFd(); } } -void WiiSocket::setFd(s32 s) +void WiiSocket::SetFd(s32 s) { if (fd >= 0) - (void)closeFd(); + (void)CloseFd(); nonBlock = false; fd = s; @@ -128,7 +128,7 @@ void WiiSocket::setFd(s32 s) #endif } -s32 WiiSocket::closeFd() +s32 WiiSocket::CloseFd() { s32 ReturnValue = 0; if (fd >= 0) @@ -138,17 +138,17 @@ s32 WiiSocket::closeFd() #else s32 ret = close(fd); #endif - ReturnValue = WiiSockMan::getNetErrorCode(ret, "delSocket", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "CloseFd", false); } else { - ReturnValue = WiiSockMan::getNetErrorCode(EITHER(WSAENOTSOCK, EBADF), "delSocket", false); + ReturnValue = WiiSockMan::GetNetErrorCode(EITHER(WSAENOTSOCK, EBADF), "CloseFd", false); } fd = -1; return ReturnValue; } -s32 WiiSocket::_fcntl(u32 cmd, u32 arg) +s32 WiiSocket::FCntl(u32 cmd, u32 arg) { #define F_GETFL 3 #define F_SETFL 4 @@ -173,7 +173,7 @@ s32 WiiSocket::_fcntl(u32 cmd, u32 arg) return ret; } -void WiiSocket::update(bool read, bool write, bool except) +void WiiSocket::Update(bool read, bool write, bool except) { auto it = pending_sockops.begin(); while (it != pending_sockops.end()) @@ -194,7 +194,7 @@ void WiiSocket::update(bool read, bool write, bool except) { u32 cmd = Memory::Read_U32(BufferIn + 4); u32 arg = Memory::Read_U32(BufferIn + 8); - ReturnValue = _fcntl(cmd, arg); + ReturnValue = FCntl(cmd, arg); break; } case IOCTL_SO_BIND: @@ -205,7 +205,7 @@ void WiiSocket::update(bool read, bool write, bool except) WiiSockMan::Convert(*wii_name, local_name); int ret = bind(fd, (sockaddr*)&local_name, sizeof(local_name)); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_BIND", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_BIND", false); INFO_LOG(WII_IPC_NET, "IOCTL_SO_BIND (%08X %s:%d) = %d ", fd, inet_ntoa(local_name.sin_addr), Common::swap16(local_name.sin_port), ret); @@ -219,7 +219,7 @@ void WiiSocket::update(bool read, bool write, bool except) WiiSockMan::Convert(*wii_name, local_name); int ret = connect(fd, (sockaddr*)&local_name, sizeof(local_name)); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_CONNECT", false); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_CONNECT", false); INFO_LOG(WII_IPC_NET,"IOCTL_SO_CONNECT (%08x, %s:%d)", fd, inet_ntoa(local_name.sin_addr), Common::swap16(local_name.sin_port)); @@ -227,7 +227,6 @@ void WiiSocket::update(bool read, bool write, bool except) } case IOCTL_SO_ACCEPT: { - if (BufferOutSize > 0) { sockaddr_in local_name; @@ -236,17 +235,17 @@ void WiiSocket::update(bool read, bool write, bool except) socklen_t addrlen = sizeof(sockaddr_in); int ret = (s32)accept(fd, (sockaddr*)&local_name, &addrlen); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_ACCEPT", true); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_ACCEPT", true); WiiSockMan::Convert(local_name, *wii_name, addrlen); } else { int ret = (s32)accept(fd, nullptr, 0); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_ACCEPT", true); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_ACCEPT", true); } - WiiSockMan::getInstance().addSocket(ReturnValue); + WiiSockMan::GetInstance().AddSocket(ReturnValue); INFO_LOG(WII_IPC_NET, "IOCTL_SO_ACCEPT " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)", @@ -442,7 +441,7 @@ void WiiSocket::update(bool read, bool write, bool except) int ret = sendto(fd, data, BufferInSize, flags, has_destaddr ? (struct sockaddr*)&local_name : nullptr, has_destaddr ? sizeof(sockaddr) : 0); - ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_SENDTO", true); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, "SO_SENDTO", true); INFO_LOG(WII_IPC_NET, "%s = %d Socket: %08x, BufferIn: (%08x, %i), BufferIn2: (%08x, %i), %u.%u.%u.%u", @@ -488,7 +487,7 @@ void WiiSocket::update(bool read, bool write, bool except) int ret = recvfrom(fd, data, data_len, flags, BufferOutSize2 ? (struct sockaddr*) &local_name : nullptr, BufferOutSize2 ? &addrlen : nullptr); - ReturnValue = WiiSockMan::getNetErrorCode(ret, BufferOutSize2 ? "SO_RECVFROM" : "SO_RECV", true); + ReturnValue = WiiSockMan::GetNetErrorCode(ret, BufferOutSize2 ? "SO_RECVFROM" : "SO_RECV", true); INFO_LOG(WII_IPC_NET, "%s(%d, %p) Socket: %08X, Flags: %08X, " "BufferIn: (%08x, %i), BufferIn2: (%08x, %i), " @@ -534,30 +533,30 @@ void WiiSocket::update(bool read, bool write, bool except) } } -void WiiSocket::doSock(u32 _CommandAddress, NET_IOCTL type) +void WiiSocket::DoSock(u32 _CommandAddress, NET_IOCTL type) { sockop so = {_CommandAddress, false}; so.net_type = type; pending_sockops.push_back(so); } -void WiiSocket::doSock(u32 _CommandAddress, SSL_IOCTL type) +void WiiSocket::DoSock(u32 _CommandAddress, SSL_IOCTL type) { sockop so = {_CommandAddress, true}; so.ssl_type = type; pending_sockops.push_back(so); } -void WiiSockMan::addSocket(s32 fd) +void WiiSockMan::AddSocket(s32 fd) { if (fd >= 0) { WiiSocket& sock = WiiSockets[fd]; - sock.setFd(fd); + sock.SetFd(fd); } } -s32 WiiSockMan::newSocket(s32 af, s32 type, s32 protocol) +s32 WiiSockMan::NewSocket(s32 af, s32 type, s32 protocol) { if (NetPlay::IsNetPlayRunning() || Movie::IsRecordingInput() || @@ -567,14 +566,14 @@ s32 WiiSockMan::newSocket(s32 af, s32 type, s32 protocol) } s32 fd = (s32)socket(af, type, protocol); - s32 ret = getNetErrorCode(fd, "newSocket", false); - addSocket(ret); + s32 ret = GetNetErrorCode(fd, "NewSocket", false); + AddSocket(ret); return ret; } -s32 WiiSockMan::delSocket(s32 s) +s32 WiiSockMan::DeleteSocket(s32 s) { - s32 ReturnValue = WiiSockets[s].closeFd(); + s32 ReturnValue = WiiSockets[s].CloseFd(); WiiSockets.erase(s); return ReturnValue; } @@ -590,7 +589,7 @@ void WiiSockMan::Update() for (auto& entry : WiiSockets) { WiiSocket& sock = entry.second; - if (sock.valid()) + if (sock.IsValid()) { FD_SET(sock.fd, &read_fds); FD_SET(sock.fd, &write_fds); @@ -610,7 +609,7 @@ void WiiSockMan::Update() for (auto& pair : WiiSockets) { WiiSocket& sock = pair.second; - sock.update( + sock.Update( FD_ISSET(sock.fd, &read_fds) != 0, FD_ISSET(sock.fd, &write_fds) != 0, FD_ISSET(sock.fd, &except_fds) != 0 @@ -621,7 +620,7 @@ void WiiSockMan::Update() { for (auto& elem : WiiSockets) { - elem.second.update(false, false, false); + elem.second.Update(false, false, false); } } } diff --git a/Source/Core/Core/IPC_HLE/WII_Socket.h b/Source/Core/Core/IPC_HLE/WII_Socket.h index cb0a9db37c..375245f7aa 100644 --- a/Source/Core/Core/IPC_HLE/WII_Socket.h +++ b/Source/Core/Core/IPC_HLE/WII_Socket.h @@ -161,7 +161,8 @@ struct WiiSockAddrIn class WiiSocket { - struct sockop{ + struct sockop + { u32 _CommandAddress; bool is_ssl; union @@ -176,14 +177,14 @@ private: std::list pending_sockops; friend class WiiSockMan; - void setFd(s32 s); - s32 closeFd(); - s32 _fcntl(u32 cmd, u32 arg); + void SetFd(s32 s); + s32 CloseFd(); + s32 FCntl(u32 cmd, u32 arg); - void doSock(u32 _CommandAddress, NET_IOCTL type); - void doSock(u32 _CommandAddress, SSL_IOCTL type); - void update(bool read, bool write, bool except); - bool valid() {return fd >= 0;} + void DoSock(u32 _CommandAddress, NET_IOCTL type); + void DoSock(u32 _CommandAddress, SSL_IOCTL type); + void Update(bool read, bool write, bool except); + bool IsValid() {return fd >= 0;} public: WiiSocket() : fd(-1), nonBlock(false) {} ~WiiSocket(); @@ -194,10 +195,10 @@ public: class WiiSockMan { public: - static s32 getNetErrorCode(s32 ret, std::string caller, bool isRW); + static s32 GetNetErrorCode(s32 ret, std::string caller, bool isRW); static char* DecodeError(s32 ErrorCode); - static WiiSockMan& getInstance() + static WiiSockMan& GetInstance() { static WiiSockMan instance; // Guaranteed to be destroyed. return instance; // Instantiated on first use. @@ -207,30 +208,30 @@ public: static void Convert(WiiSockAddrIn const & from, sockaddr_in& to); static void Convert(sockaddr_in const & from, WiiSockAddrIn& to, s32 addrlen=-1); // NON-BLOCKING FUNCTIONS - s32 newSocket(s32 af, s32 type, s32 protocol); - void addSocket(s32 fd); - s32 delSocket(s32 s); - s32 getLastNetError() {return errono_last;} - void setLastNetError(s32 error) {errono_last = error;} + s32 NewSocket(s32 af, s32 type, s32 protocol); + void AddSocket(s32 fd); + s32 DeleteSocket(s32 s); + s32 GetLastNetError() { return errno_last; } + void SetLastNetError(s32 error) { errno_last = error; } - void clean() + void Clean() { WiiSockets.clear(); } template - void doSock(s32 sock, u32 CommandAddress, T type) + void DoSock(s32 sock, u32 CommandAddress, T type) { if (WiiSockets.find(sock) == WiiSockets.end()) { ERROR_LOG(WII_IPC_NET, - "doSock: Error, fd not found (%08x, %08X, %08X)", + "DoSock: Error, fd not found (%08x, %08X, %08X)", sock, CommandAddress, type); EnqueueReply(CommandAddress, -SO_EBADF); } else { - WiiSockets[sock].doSock(CommandAddress, type); + WiiSockets[sock].DoSock(CommandAddress, type); } } @@ -240,5 +241,5 @@ private: void operator=(WiiSockMan const&); // Don't implement std::unordered_map WiiSockets; - s32 errono_last; + s32 errno_last; };