11 #define LIBCGLUE_SYS_SOCKET_NO_ALIASES
12 #define LIBCGLUE_ARPA_INET_NO_ALIASES
13 #include <sys/socket.h>
14 #include <ps2sdkapi.h>
17 #include "ps2sdkapi.h"
26 fd_set ready_readfds, ready_writefds, ready_exceptfds;
27 fd_set iop_readfds, iop_writefds, iop_exceptfds;
29 if (_libcglue_fdman_socket_ops == NULL || _libcglue_fdman_socket_ops->select == NULL)
35 FD_ZERO(&ready_readfds);
36 FD_ZERO(&ready_writefds);
37 FD_ZERO(&ready_exceptfds);
39 FD_ZERO(&iop_readfds);
40 FD_ZERO(&iop_writefds);
41 FD_ZERO(&iop_exceptfds);
43 for (fd = 0; fd < n; fd += 1)
45 int in_read = readfds && FD_ISSET(fd, readfds);
46 int in_write = writefds && FD_ISSET(fd, writefds);
47 int in_except = exceptfds && FD_ISSET(fd, exceptfds);
50 if (!in_read && !in_write && !in_except)
55 iop_fd = ps2sdk_get_iop_fd(fd);
61 if (iop_fd > iop_max_fd)
67 FD_SET(iop_fd, &iop_readfds);
71 FD_SET(iop_fd, &iop_writefds);
75 FD_SET(iop_fd, &iop_exceptfds);
83 ret = _libcglue_fdman_socket_ops->select(iop_max_fd + 1, &iop_readfds, &iop_writefds, &iop_exceptfds, timeout);
85 for (fd = 0; fd < n; fd += 1)
87 int in_read = readfds && FD_ISSET(fd, readfds);
88 int in_write = writefds && FD_ISSET(fd, writefds);
89 int in_except = exceptfds && FD_ISSET(fd, exceptfds);
92 if (!in_read && !in_write && !in_except)
97 iop_fd = ps2sdk_get_iop_fd(fd);
102 if (in_read && FD_ISSET(iop_fd, &iop_readfds))
104 FD_SET(fd, &ready_readfds);
106 if (in_write && FD_ISSET(iop_fd, &iop_writefds))
108 FD_SET(fd, &ready_writefds);
110 if (in_except && FD_ISSET(iop_fd, &iop_exceptfds))
112 FD_SET(fd, &ready_exceptfds);
118 *readfds = ready_readfds;
122 *writefds = ready_writefds;
126 *exceptfds = ready_exceptfds;