PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
select.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#define LIBCGLUE_SYS_SOCKET_NO_ALIASES
12#define LIBCGLUE_ARPA_INET_NO_ALIASES
13#include <sys/socket.h>
14#include <ps2sdkapi.h>
15#include <errno.h>
16
17#include "ps2sdkapi.h"
18
19#ifdef F_select
20/* FIXME: This function currently cannot handle heterogeneous fds */
21int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
22{
23 int fd;
24 int ret;
25 fd_set ready_readfds, ready_writefds, ready_exceptfds;
26 fd_set iop_readfds, iop_writefds, iop_exceptfds;
27
28 if (_libcglue_fdman_socket_ops == NULL || _libcglue_fdman_socket_ops->select == NULL)
29 {
30 errno = ENOSYS;
31 return -1;
32 }
33
34 FD_ZERO(&ready_readfds);
35 FD_ZERO(&ready_writefds);
36 FD_ZERO(&ready_exceptfds);
37
38 FD_ZERO(&iop_readfds);
39 FD_ZERO(&iop_writefds);
40 FD_ZERO(&iop_exceptfds);
41
42 for (fd = 0; fd < n; fd += 1)
43 {
44 int iop_fd;
45 iop_fd = ps2sdk_get_iop_fd(fd);
46 if (iop_fd < 0)
47 {
48 errno = EBADF;
49 return -1;
50 }
51 if (readfds && FD_ISSET(fd, readfds))
52 {
53 FD_SET(iop_fd, &iop_readfds);
54 }
55 if (writefds && FD_ISSET(fd, writefds))
56 {
57 FD_SET(iop_fd, &iop_writefds);
58 }
59 if (exceptfds && FD_ISSET(fd, exceptfds))
60 {
61 FD_SET(iop_fd, &iop_exceptfds);
62 }
63 }
64
65 ret = _libcglue_fdman_socket_ops->select(n, &iop_readfds, &iop_writefds, &iop_exceptfds, timeout);
66
67 for (fd = 0; fd < n; fd += 1)
68 {
69 int iop_fd;
70 iop_fd = ps2sdk_get_iop_fd(fd);
71 if (FD_ISSET(iop_fd, &iop_readfds))
72 {
73 FD_SET(fd, &ready_readfds);
74 }
75 if (FD_ISSET(iop_fd, &iop_writefds))
76 {
77 FD_SET(fd, &ready_writefds);
78 }
79 if (FD_ISSET(iop_fd, &iop_exceptfds))
80 {
81 FD_SET(fd, &ready_exceptfds);
82 }
83 }
84
85 if (readfds)
86 {
87 *readfds = ready_readfds;
88 }
89 if (writefds)
90 {
91 *writefds = ready_writefds;
92 }
93 if (exceptfds)
94 {
95 *exceptfds = ready_exceptfds;
96 }
97
98 return ret;
99}
100#endif
#define ENOSYS
Definition errno.h:185
#define EBADF
Definition errno.h:37
Definition time.h:29