11#define LIBCGLUE_SYS_SOCKET_NO_ALIASES
12#define LIBCGLUE_ARPA_INET_NO_ALIASES
13#include <sys/socket.h>
25 fd_set ready_readfds, ready_writefds, ready_exceptfds;
26 fd_set iop_readfds, iop_writefds, iop_exceptfds;
28 if (_libcglue_fdman_socket_ops == NULL || _libcglue_fdman_socket_ops->select == NULL)
34 FD_ZERO(&ready_readfds);
35 FD_ZERO(&ready_writefds);
36 FD_ZERO(&ready_exceptfds);
38 FD_ZERO(&iop_readfds);
39 FD_ZERO(&iop_writefds);
40 FD_ZERO(&iop_exceptfds);
42 for (fd = 0; fd < n; fd += 1)
44 int in_read = readfds && FD_ISSET(fd, readfds);
45 int in_write = writefds && FD_ISSET(fd, writefds);
46 int in_except = exceptfds && FD_ISSET(fd, exceptfds);
49 if (!in_read && !in_write && !in_except)
54 iop_fd = ps2sdk_get_iop_fd(fd);
60 if (iop_fd > iop_max_fd)
66 FD_SET(iop_fd, &iop_readfds);
70 FD_SET(iop_fd, &iop_writefds);
74 FD_SET(iop_fd, &iop_exceptfds);
82 ret = _libcglue_fdman_socket_ops->select(iop_max_fd + 1, &iop_readfds, &iop_writefds, &iop_exceptfds, timeout);
84 for (fd = 0; fd < n; fd += 1)
86 int in_read = readfds && FD_ISSET(fd, readfds);
87 int in_write = writefds && FD_ISSET(fd, writefds);
88 int in_except = exceptfds && FD_ISSET(fd, exceptfds);
91 if (!in_read && !in_write && !in_except)
96 iop_fd = ps2sdk_get_iop_fd(fd);
101 if (in_read && FD_ISSET(iop_fd, &iop_readfds))
103 FD_SET(fd, &ready_readfds);
105 if (in_write && FD_ISSET(iop_fd, &iop_writefds))
107 FD_SET(fd, &ready_writefds);
109 if (in_except && FD_ISSET(iop_fd, &iop_exceptfds))
111 FD_SET(fd, &ready_exceptfds);
117 *readfds = ready_readfds;
121 *writefds = ready_writefds;
125 *exceptfds = ready_exceptfds;