mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add socket mapping for accept(). Don't know if games use it...
This commit is contained in:
parent
d4ad8c9639
commit
0cec39d11f
3 changed files with 41 additions and 6 deletions
|
@ -46,6 +46,29 @@ InetSocket *SocketManager::CreateSocket(int *index, int *returned_errno, SocketS
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
InetSocket *SocketManager::AdoptSocket(int *index, SOCKET hostSocket, const InetSocket *derive) {
|
||||
std::lock_guard<std::mutex> guard(g_socketMutex);
|
||||
|
||||
for (int i = MIN_VALID_INET_SOCKET; i < ARRAY_SIZE(inetSockets_); i++) {
|
||||
if (inetSockets_[i].state == SocketState::Unused) {
|
||||
*index = i;
|
||||
|
||||
InetSocket *inetSock = inetSockets_ + i;
|
||||
inetSock->sock = hostSocket;
|
||||
inetSock->state = derive->state;
|
||||
inetSock->domain = derive->domain;
|
||||
inetSock->type = derive->type;
|
||||
inetSock->protocol = derive->protocol;
|
||||
inetSock->nonblocking = derive->nonblocking; // should we inherit blocking state?
|
||||
return inetSock;
|
||||
}
|
||||
}
|
||||
|
||||
// No space? Return nullptr and let the caller handle it. Shouldn't ever happen.
|
||||
*index = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SocketManager::Close(InetSocket *inetSocket) {
|
||||
_dbg_assert_(inetSocket->state != SocketState::Unused);
|
||||
if (closesocket(inetSocket->sock) != 0) {
|
||||
|
|
|
@ -32,6 +32,9 @@ public:
|
|||
};
|
||||
|
||||
InetSocket *CreateSocket(int *index, int *returned_errno, SocketState state, int domain, int type, int protocol);
|
||||
// for accept()
|
||||
InetSocket *AdoptSocket(int *index, SOCKET hostSocket, const InetSocket *derive);
|
||||
|
||||
bool GetInetSocket(int sock, InetSocket **inetSocket);
|
||||
SOCKET GetHostSocketFromInetSocket(int sock);
|
||||
bool Close(InetSocket *inetSocket);
|
||||
|
|
|
@ -691,14 +691,23 @@ static int sceNetInetAccept(int socket, u32 addrPtr, u32 addrLenPtr) {
|
|||
SockAddrIN4 saddr{};
|
||||
if (srclen)
|
||||
*srclen = std::min((*srclen) > 0 ? *srclen : 0, static_cast<socklen_t>(sizeof(saddr)));
|
||||
int retval = accept(inetSock->sock, (struct sockaddr*)&saddr.addr, srclen);
|
||||
if (retval < 0) {
|
||||
|
||||
int newHostSocket = accept(inetSock->sock, (struct sockaddr*)&saddr.addr, srclen);
|
||||
if (newHostSocket < 0) {
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
hleLogDebug(Log::sceNet, newHostSocket, "errno = %d", inetLastErrno);
|
||||
else
|
||||
hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
return retval;
|
||||
hleLogError(Log::sceNet, newHostSocket, "errno = %d", inetLastErrno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int newSocketId;
|
||||
InetSocket *newInetSocket = g_socketManager.AdoptSocket(&newSocketId, newHostSocket, inetSock);
|
||||
if (!newInetSocket) {
|
||||
// Ran out of space. Shouldn't really happen.
|
||||
inetLastErrno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src) {
|
||||
|
@ -708,7 +717,7 @@ static int sceNetInetAccept(int socket, u32 addrPtr, u32 addrLenPtr) {
|
|||
}
|
||||
DEBUG_LOG(Log::sceNet, "Accept: Address = %s, Port = %d", ip2str(saddr.in.sin_addr).c_str(), ntohs(saddr.in.sin_port));
|
||||
|
||||
return hleLogSuccessI(Log::sceNet, retval);
|
||||
return hleLogSuccessI(Log::sceNet, newSocketId);
|
||||
}
|
||||
|
||||
static int sceNetInetShutdown(int socket, int how) {
|
||||
|
|
Loading…
Add table
Reference in a new issue