mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add Close method to socket manager
This commit is contained in:
parent
a1744a6989
commit
b97b0e4cf6
3 changed files with 19 additions and 16 deletions
|
@ -42,6 +42,17 @@ InetSocket *SocketManager::CreateSocket(int *index, SocketState state, int domai
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool SocketManager::Close(InetSocket *inetSocket) {
|
||||
_dbg_assert_(inetSocket->state != SocketState::Unused);
|
||||
if (closesocket(inetSocket->sock) != 0) {
|
||||
ERROR_LOG(Log::sceNet, "closesocket(%d) failed", inetSocket->sock);
|
||||
return false;
|
||||
}
|
||||
inetSocket->state = SocketState::Unused;
|
||||
inetSocket->sock = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SocketManager::GetInetSocket(int sock, InetSocket **inetSocket) {
|
||||
std::lock_guard<std::mutex> guard(g_socketMutex);
|
||||
if (sock < MIN_VALID_INET_SOCKET || sock >= ARRAY_SIZE(inetSockets_) || inetSockets_[sock].state == SocketState::Unused) {
|
||||
|
|
|
@ -19,6 +19,8 @@ struct InetSocket {
|
|||
int protocol;
|
||||
};
|
||||
|
||||
// Only use this for sockets whose ID are exposed to the game.
|
||||
// Don't really need to bother with the others, as the game doesn't know about them.
|
||||
class SocketManager {
|
||||
public:
|
||||
enum {
|
||||
|
@ -29,6 +31,7 @@ public:
|
|||
InetSocket *CreateSocket(int *index, SocketState state, int domain, int type, int protocol);
|
||||
bool GetInetSocket(int sock, InetSocket **inetSocket);
|
||||
SOCKET GetHostSocketFromInetSocket(int sock);
|
||||
bool Close(InetSocket *inetSocket);
|
||||
void CloseAll();
|
||||
|
||||
// For debugger
|
||||
|
|
|
@ -720,14 +720,9 @@ static int sceNetInetClose(int socket) {
|
|||
return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket);
|
||||
}
|
||||
|
||||
int retVal = closesocket(inetSock->sock);
|
||||
if (retVal == 0) {
|
||||
inetSock->sock = 0;
|
||||
inetSock->state = SocketState::Unused;
|
||||
} else {
|
||||
ERROR_LOG(Log::sceNet, "closesocket(%d) failed (socket=%d)", inetSock->sock, socket);
|
||||
}
|
||||
return hleLogSuccessI(Log::sceNet, retVal);
|
||||
g_socketManager.Close(inetSock);
|
||||
|
||||
return hleLogSuccessI(Log::sceNet, 0);
|
||||
}
|
||||
|
||||
// TODO: How is this different than just sceNetInetClose?
|
||||
|
@ -744,14 +739,8 @@ static int sceNetInetCloseWithRST(int socket) {
|
|||
sl.l_onoff = 1; // non-zero value enables linger option in kernel
|
||||
sl.l_linger = 0; // timeout interval in seconds
|
||||
setsockopt(inetSock->sock, SOL_SOCKET, SO_LINGER, (const char*)&sl, sizeof(sl));
|
||||
int retVal = closesocket(inetSock->sock);
|
||||
if (retVal == 0) {
|
||||
inetSock->sock = 0;
|
||||
inetSock->state = SocketState::Unused;
|
||||
} else {
|
||||
ERROR_LOG(Log::sceNet, "closesocket(%d) failed (socket=%d)", inetSock->sock, socket);
|
||||
}
|
||||
return hleLogSuccessI(Log::sceNet, retVal);
|
||||
g_socketManager.Close(inetSock);
|
||||
return hleLogSuccessI(Log::sceNet, 0);
|
||||
}
|
||||
|
||||
static int sceNetInetRecvfrom(int socket, u32 bufferPtr, int len, int flags, u32 fromPtr, u32 fromlenPtr) {
|
||||
|
|
Loading…
Add table
Reference in a new issue