ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_select.c
(Generate patch)

Comparing libev/ev_select.c (file contents):
Revision 1.27 by root, Tue Dec 25 07:05:45 2007 UTC vs.
Revision 1.31 by root, Fri May 23 16:37:38 2008 UTC

1/* 1/*
2 * libev select fd activity backend 2 * libev select fd activity backend
3 * 3 *
4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
52#endif 52#endif
53 53
54#if EV_SELECT_IS_WINSOCKET 54#if EV_SELECT_IS_WINSOCKET
55# undef EV_SELECT_USE_FD_SET 55# undef EV_SELECT_USE_FD_SET
56# define EV_SELECT_USE_FD_SET 1 56# define EV_SELECT_USE_FD_SET 1
57# undef EINTR
58# define EINTR WSAEINTR
59# undef EBADF
60# define EBADF WSAENOTSOCK
61# undef ENOMEM
62# define ENOMEM (errno + 1)
63#endif 57#endif
64 58
65#if !EV_SELECT_USE_FD_SET 59#if !EV_SELECT_USE_FD_SET
66# define NFDBYTES (NFDBITS / 8) 60# define NFDBYTES (NFDBITS / 8)
67#endif 61#endif
93 else 87 else
94 FD_CLR (handle, (fd_set *)vec_wi); 88 FD_CLR (handle, (fd_set *)vec_wi);
95 89
96#else 90#else
97 91
98 int word = fd / NFDBITS; 92 int word = fd / NFDBITS;
99 int mask = 1UL << (fd % NFDBITS); 93 fd_mask mask = 1UL << (fd % NFDBITS);
100 94
101 if (expect_false (vec_max < word + 1)) 95 if (expect_false (vec_max <= word))
102 { 96 {
103 int new_max = word + 1; 97 int new_max = word + 1;
104 98
105 vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); 99 vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES);
106 vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ 100 vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */
107 vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); 101 vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES);
108 vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ 102 vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */
109 103
110 for (; vec_max < new_max; ++vec_max) 104 for (; vec_max < new_max; ++vec_max)
111 ((fd_mask *)vec_ri)[vec_max] = 105 ((fd_mask *)vec_ri) [vec_max] =
112 ((fd_mask *)vec_wi)[vec_max] = 0; 106 ((fd_mask *)vec_wi) [vec_max] = 0;
113 } 107 }
114 108
115 ((fd_mask *)vec_ri) [word] |= mask; 109 ((fd_mask *)vec_ri) [word] |= mask;
116 if (!(nev & EV_READ)) 110 if (!(nev & EV_READ))
117 ((fd_mask *)vec_ri) [word] &= ~mask; 111 ((fd_mask *)vec_ri) [word] &= ~mask;
144 138
145 if (expect_false (res < 0)) 139 if (expect_false (res < 0))
146 { 140 {
147 #if EV_SELECT_IS_WINSOCKET 141 #if EV_SELECT_IS_WINSOCKET
148 errno = WSAGetLastError (); 142 errno = WSAGetLastError ();
143 #endif
144 #ifdef WSABASEERR
145 /* on windows, select returns incompatible error codes, fix this */
146 if (errno >= WSABASEERR && errno < WSABASEERR + 1000)
147 if (errno == WSAENOTSOCK)
148 errno = EBADF;
149 else
150 errno -= WSABASEERR;
151 #endif
152
153 #ifdef _WIN32
154 /* select on windows errornously returns EINVAL when no fd sets have been
155 * provided (this is documented). what microsoft doesn't tell you that this bug
156 * exists even when the fd sets are provided, so we have to check for this bug
157 * here and emulate by sleeping manually.
158 * we also get EINVAL when the timeout is invalid, but we ignore this case here
159 * and assume that EINVAL always means: you have to wait manually.
160 */
161 if (errno == EINVAL)
162 {
163 ev_sleep (timeout);
164 return;
165 }
149 #endif 166 #endif
150 167
151 if (errno == EBADF) 168 if (errno == EBADF)
152 fd_ebadf (EV_A); 169 fd_ebadf (EV_A);
153 else if (errno == ENOMEM && !syserr_cb) 170 else if (errno == ENOMEM && !syserr_cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines