25
25
#define MSG_NOSIGNAL 0x00
26
26
#endif
27
27
28
+ #define MIN_VALID_SOCKET 20
29
+
28
30
int inetLastErrno = 0 ; // TODO: since errno can only be read once, we should keep track the value to be used on sceNetInetGetErrno
29
31
30
32
bool netInetInited = false ;
@@ -33,7 +35,7 @@ bool netInetInited = false;
33
35
InetSocket g_inetSockets[256 ];
34
36
35
37
static int AllocInetSocket () {
36
- for (int i = 1 ; i < ARRAY_SIZE (g_inetSockets); i++) {
38
+ for (int i = MIN_VALID_SOCKET ; i < ARRAY_SIZE (g_inetSockets); i++) {
37
39
if (g_inetSockets[i].state == SocketState::Unused) {
38
40
return i;
39
41
}
@@ -44,7 +46,7 @@ static int AllocInetSocket() {
44
46
}
45
47
46
48
static bool GetInetSocket (int sock, InetSocket **inetSocket) {
47
- if (sock < 1 || sock >= ARRAY_SIZE (g_inetSockets) || g_inetSockets[sock].state == SocketState::Unused) {
49
+ if (sock < MIN_VALID_SOCKET || sock >= ARRAY_SIZE (g_inetSockets) || g_inetSockets[sock].state == SocketState::Unused) {
48
50
*inetSocket = nullptr ;
49
51
return false ;
50
52
}
@@ -53,22 +55,8 @@ static bool GetInetSocket(int sock, InetSocket **inetSocket) {
53
55
}
54
56
55
57
// Simplified mappers, only really useful in select/poll
56
- static int GetInetSocketFromHostSocket (SOCKET hostSock) {
57
- for (int i = 1 ; i < ARRAY_SIZE (g_inetSockets); i++) {
58
- if (g_inetSockets[i].state == SocketState::Used && g_inetSockets[i].sock == hostSock) {
59
- return i;
60
- }
61
- }
62
- if (hostSock == 0 ) {
63
- // Map 0 to 0, special case.
64
- return 0 ;
65
- }
66
- _dbg_assert_ (false );
67
- return -1 ;
68
- }
69
-
70
58
static SOCKET GetHostSocketFromInetSocket (int sock) {
71
- if (sock < 1 || sock >= ARRAY_SIZE (g_inetSockets) || g_inetSockets[sock].state == SocketState::Unused) {
59
+ if (sock < MIN_VALID_SOCKET || sock >= ARRAY_SIZE (g_inetSockets) || g_inetSockets[sock].state == SocketState::Unused) {
72
60
_dbg_assert_ (false );
73
61
return -1 ;
74
62
}
@@ -265,7 +253,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
265
253
// Save the mapping during setup.
266
254
SOCKET hostSockets[256 ]{};
267
255
268
- for (int i = 0 ; i < nfds; i++) {
256
+ for (int i = MIN_VALID_SOCKET ; i < nfds; i++) {
269
257
if (readfds && (NetInetFD_ISSET (i, readfds))) {
270
258
SOCKET sock = GetHostSocketFromInetSocket (i);
271
259
hostSockets[i] = sock;
@@ -314,7 +302,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
314
302
if (readfds != NULL ) NetInetFD_ZERO (readfds);
315
303
if (writefds != NULL ) NetInetFD_ZERO (writefds);
316
304
if (exceptfds != NULL ) NetInetFD_ZERO (exceptfds);
317
- for (int i = 0 ; i < nfds; i++) {
305
+ for (int i = MIN_VALID_SOCKET ; i < nfds; i++) {
318
306
if (readfds && hostSockets[i] != 0 && FD_ISSET (hostSockets[i], &rdfds)) {
319
307
NetInetFD_SET (i, readfds);
320
308
}
0 commit comments