equal
deleted
inserted
replaced
22 /* |
22 /* |
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. |
24 * Use is subject to license terms. |
25 */ |
25 */ |
26 |
26 |
27 #pragma ident "%Z%%M% %I% %E% SMI" |
|
28 |
|
29 /* Copyright (c) 1988 AT&T */ |
27 /* Copyright (c) 1988 AT&T */ |
30 /* All Rights Reserved */ |
28 /* All Rights Reserved */ |
|
29 |
|
30 #pragma ident "%Z%%M% %I% %E% SMI" |
31 |
31 |
32 /* |
32 /* |
33 * Emulation of select() system call using _pollsys() system call. |
33 * Emulation of select() system call using _pollsys() system call. |
34 * |
34 * |
35 * Assumptions: |
35 * Assumptions: |
50 #ifdef FD_SETSIZE |
50 #ifdef FD_SETSIZE |
51 #undef FD_SETSIZE |
51 #undef FD_SETSIZE |
52 #endif |
52 #endif |
53 #define FD_SETSIZE 65536 |
53 #define FD_SETSIZE 65536 |
54 |
54 |
55 /* |
55 #include "lint.h" |
56 * We do not #redefine the name since the only users of this |
|
57 * are external to the libraries and commands. |
|
58 * |
|
59 * #pragma weak pselect_large_fdset = _pselect_large_fdset |
|
60 * #pragma weak select_large_fdset = _select_large_fdset |
|
61 */ |
|
62 |
|
63 #include "synonyms.h" |
|
64 #include <values.h> |
56 #include <values.h> |
65 #include <stdlib.h> |
57 #include <stdlib.h> |
66 #include <string.h> |
58 #include <string.h> |
67 #include <pthread.h> |
59 #include <pthread.h> |
68 #include <errno.h> |
60 #include <errno.h> |
168 p++; |
160 p++; |
169 } else if ((p = realloc_fds( |
161 } else if ((p = realloc_fds( |
170 &nfds_on_list, &pfd_list, pfd)) |
162 &nfds_on_list, &pfd_list, pfd)) |
171 == NULL) { |
163 == NULL) { |
172 if (pfd_list != pfd) |
164 if (pfd_list != pfd) |
173 (void) free(pfd_list); |
165 free(pfd_list); |
174 pthread_testcancel(); |
166 pthread_testcancel(); |
175 return (-1); |
167 return (-1); |
176 } |
168 } |
177 nused++; |
169 nused++; |
178 } else |
170 } else |
191 rv = _pollsys(pfd_list, (nfds_t)nused, tsp, sigmask); |
183 rv = _pollsys(pfd_list, (nfds_t)nused, tsp, sigmask); |
192 } while (rv < 0 && errno == EAGAIN); |
184 } while (rv < 0 && errno == EAGAIN); |
193 |
185 |
194 if (rv < 0) { /* no need to set bit masks */ |
186 if (rv < 0) { /* no need to set bit masks */ |
195 if (pfd_list != pfd) |
187 if (pfd_list != pfd) |
196 (void) free(pfd_list); |
188 free(pfd_list); |
197 return (rv); |
189 return (rv); |
198 } else if (rv == 0) { |
190 } else if (rv == 0) { |
199 /* |
191 /* |
200 * Clear out bit masks, just in case. |
192 * Clear out bit masks, just in case. |
201 * On the assumption that usually only |
193 * On the assumption that usually only |
215 ex = (long *)ex0->fds_bits; |
207 ex = (long *)ex0->fds_bits; |
216 for (n = 0; n < nfds; n += NFDBITS) |
208 for (n = 0; n < nfds; n += NFDBITS) |
217 *ex++ = 0; |
209 *ex++ = 0; |
218 } |
210 } |
219 if (pfd_list != pfd) |
211 if (pfd_list != pfd) |
220 (void) free(pfd_list); |
212 free(pfd_list); |
221 return (0); |
213 return (0); |
222 } |
214 } |
223 |
215 |
224 /* |
216 /* |
225 * Check for EINVAL error case first to avoid changing any bits |
217 * Check for EINVAL error case first to avoid changing any bits |
235 * doing more work than select would've done. |
227 * doing more work than select would've done. |
236 */ |
228 */ |
237 if (p->revents & POLLNVAL) { |
229 if (p->revents & POLLNVAL) { |
238 errno = EBADF; |
230 errno = EBADF; |
239 if (pfd_list != pfd) |
231 if (pfd_list != pfd) |
240 (void) free(pfd_list); |
232 free(pfd_list); |
241 return (-1); |
233 return (-1); |
242 } |
234 } |
243 /* |
235 /* |
244 * We would like to make POLLHUP available to select, |
236 * We would like to make POLLHUP available to select, |
245 * checking to see if we have pending data to be read. |
237 * checking to see if we have pending data to be read. |
334 *ex |= m; |
326 *ex |= m; |
335 } |
327 } |
336 } |
328 } |
337 } |
329 } |
338 if (pfd_list != pfd) |
330 if (pfd_list != pfd) |
339 (void) free(pfd_list); |
331 free(pfd_list); |
340 return (rv); |
332 return (rv); |
341 } |
333 } |
342 |
334 |
343 int |
335 int |
344 select_large_fdset(int nfds, fd_set *in0, fd_set *out0, fd_set *ex0, |
336 select_large_fdset(int nfds, fd_set *in0, fd_set *out0, fd_set *ex0, |
389 b = malloc(nta); |
381 b = malloc(nta); |
390 if (b) { |
382 if (b) { |
391 (void) memset(b, 0, (size_t)nta); |
383 (void) memset(b, 0, (size_t)nta); |
392 (void) memcpy(b, *list_head, nta / 2); |
384 (void) memcpy(b, *list_head, nta / 2); |
393 if (*list_head != orig) |
385 if (*list_head != orig) |
394 (void) free(*list_head); |
386 free(*list_head); |
395 *list_head = b; |
387 *list_head = b; |
396 b += *num; |
388 b += *num; |
397 *num = n2; |
389 *num = n2; |
398 } |
390 } |
399 return (b); |
391 return (b); |