Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HLE/SocketManager.h
3186 views
1
#pragma once
2
3
#include "Common/Net/SocketCompat.h"
4
5
// Keep track of who's using a socket.
6
enum class SocketState {
7
Unused = 0,
8
UsedNetInet,
9
UsedProAdhoc,
10
};
11
12
const char *SocketStateToString(SocketState state);
13
14
// Internal socket state tracking
15
struct InetSocket {
16
SOCKET sock; // native socket
17
SocketState state;
18
// NOTE: These are the PSP types. Can be converted to the host types if needed.
19
int domain;
20
int type;
21
int protocol;
22
bool nonblocking;
23
// Metadata for debug use only.
24
std::string addr;
25
int port;
26
};
27
28
// Only use this for sockets whose ID are exposed to the game.
29
// Don't really need to bother with the others, as the game doesn't know about them.
30
class SocketManager {
31
public:
32
enum {
33
VALID_INET_SOCKET_COUNT = 256,
34
MIN_VALID_INET_SOCKET = 1,
35
};
36
37
InetSocket *CreateSocket(int *index, int *returned_errno, SocketState state, int domain, int type, int protocol);
38
// for accept()
39
InetSocket *AdoptSocket(int *index, SOCKET hostSocket, const InetSocket *derive);
40
41
bool GetInetSocket(int sock, InetSocket **inetSocket);
42
SOCKET GetHostSocketFromInetSocket(int sock);
43
bool Close(InetSocket *inetSocket);
44
void CloseAll();
45
46
// For debugger
47
const InetSocket *Sockets() {
48
return inetSockets_;
49
}
50
51
private:
52
// We use this array from MIN_VALID_INET_SOCKET and forward. It's probably not a good idea to return 0 as a socket.
53
InetSocket inetSockets_[VALID_INET_SOCKET_COUNT];
54
};
55
56
extern SocketManager g_socketManager;
57
58