Commit | Line | Data |
---|---|---|
d7c6e9aa RS |
1 | /* |
2 | Copyright (C) 2013 by Ronnie Sahlberg <ronniesahlberg@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU Lesser General Public License as published by | |
6 | the Free Software Foundation; either version 2.1 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public License | |
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | #ifdef AROS | |
19 | ||
20 | #include <sys/types.h> | |
21 | #include <sys/time.h> | |
22 | #include "aros_compat.h" | |
23 | ||
24 | #undef poll | |
25 | ||
e77d093c RS |
26 | /* unix device major/minor numbers dont make much sense on amiga */ |
27 | int major(int i) | |
28 | { | |
29 | return 1; | |
30 | } | |
31 | int minor(int i) | |
32 | { | |
33 | return 2; | |
34 | } | |
d7c6e9aa RS |
35 | |
36 | int aros_poll(struct pollfd *fds, unsigned int nfds, int timo) | |
37 | { | |
38 | struct timeval timeout, *toptr; | |
39 | fd_set ifds, ofds, efds, *ip, *op; | |
40 | unsigned int i; | |
41 | int rc; | |
42 | ||
43 | // Set up the file-descriptor sets in ifds, ofds and efds. | |
44 | FD_ZERO(&ifds); | |
45 | FD_ZERO(&ofds); | |
46 | FD_ZERO(&efds); | |
47 | for (i = 0, op = ip = 0; i < nfds; ++i) | |
48 | { | |
49 | fds[i].revents = 0; | |
50 | if(fds[i].events & (POLLIN|POLLPRI)) | |
51 | { | |
52 | ip = &ifds; | |
53 | FD_SET(fds[i].fd, ip); | |
54 | } | |
55 | if(fds[i].events & POLLOUT) | |
56 | { | |
57 | op = &ofds; | |
58 | FD_SET(fds[i].fd, op); | |
59 | } | |
60 | FD_SET(fds[i].fd, &efds); | |
61 | } | |
62 | ||
63 | // Set up the timeval structure for the timeout parameter | |
64 | if(timo < 0) | |
65 | { | |
66 | toptr = 0; | |
67 | } | |
68 | else | |
69 | { | |
70 | toptr = &timeout; | |
71 | timeout.tv_sec = timo / 1000; | |
72 | timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; | |
73 | } | |
74 | ||
75 | rc = select(0, ip, op, &efds, toptr); | |
76 | ||
77 | if(rc <= 0) | |
78 | return rc; | |
79 | ||
80 | if(rc > 0) | |
81 | { | |
82 | for (i = 0; i < nfds; ++i) | |
83 | { | |
84 | int fd = fds[i].fd; | |
85 | if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) | |
86 | fds[i].revents |= POLLIN; | |
87 | if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) | |
88 | fds[i].revents |= POLLOUT; | |
89 | if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know. | |
90 | fds[i].revents |= POLLHUP; | |
91 | } | |
92 | } | |
93 | return rc; | |
94 | } | |
95 | ||
96 | #endif |