mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-20 17:59:08 +02:00
- sceNet kept the current session's "inited" flags across a load, while sceNetAdhoc takes them from the state. A state saved after sceNetApctlInit loaded into a fresh boot had no apctl, and an earlier state loaded mid-session found apctl already inited with no thread to deliver its events. They now come from the state, and sceNetInet's host sockets are closed on load instead of leaking ports. - Adhoc matching contexts aren't saved, but survived a load while their sockets were deleted under their host threads. They're deleted first now, leaving their fake PSP threads (ids from before the load) alone. - sceHttp had no state at all. Its inited flags are saved now, and its objects, which hold host connections, are dropped on load. - The achievements data size from the file was skipped unchecked, which can wrap the pointer on 32-bit, and a MemSlabMap slab count could size a huge allocation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "Common/Net/SocketCompat.h"
|
|
|
|
// Keep track of who's using a socket.
|
|
enum class SocketState {
|
|
Unused = 0,
|
|
UsedNetInet,
|
|
UsedProAdhoc,
|
|
};
|
|
|
|
const char *SocketStateToString(SocketState state);
|
|
|
|
// Internal socket state tracking
|
|
struct InetSocket {
|
|
SOCKET sock; // native socket
|
|
SocketState state;
|
|
// NOTE: These are the PSP types. Can be converted to the host types if needed.
|
|
int domain;
|
|
int type;
|
|
int protocol;
|
|
bool nonblocking;
|
|
// Metadata for debug use only.
|
|
std::string addr;
|
|
int port;
|
|
};
|
|
|
|
// 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 {
|
|
VALID_INET_SOCKET_COUNT = 256,
|
|
MIN_VALID_INET_SOCKET = 1,
|
|
};
|
|
|
|
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);
|
|
void CloseAll();
|
|
// Only the sockets in this state (sceNetInet's, or proAdhoc's).
|
|
void CloseAll(SocketState state);
|
|
|
|
// For debugger
|
|
const InetSocket *Sockets() {
|
|
return inetSockets_;
|
|
}
|
|
|
|
private:
|
|
// We use this array from MIN_VALID_INET_SOCKET and forward. It's probably not a good idea to return 0 as a socket.
|
|
InetSocket inetSockets_[VALID_INET_SOCKET_COUNT];
|
|
};
|
|
|
|
extern SocketManager g_socketManager;
|