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 |
… | |
… | |
138 | #endif |
132 | #endif |
139 | |
133 | |
140 | tv.tv_sec = (long)timeout; |
134 | tv.tv_sec = (long)timeout; |
141 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
135 | tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); |
142 | |
136 | |
|
|
137 | #ifdef _WIN32 |
|
|
138 | /* pass in the write set as except set. |
|
|
139 | * the idea behind this is to work around a windows bug that causes |
|
|
140 | * errors to be reported as an exception and not by setting |
|
|
141 | * the writable bit. this is so uncontrollably lame. |
|
|
142 | */ |
|
|
143 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, (fd_set *)vec_wo, &tv); |
|
|
144 | #else |
143 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
145 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); |
|
|
146 | #endif |
144 | |
147 | |
145 | if (expect_false (res < 0)) |
148 | if (expect_false (res < 0)) |
146 | { |
149 | { |
147 | #if EV_SELECT_IS_WINSOCKET |
150 | #if EV_SELECT_IS_WINSOCKET |
148 | errno = WSAGetLastError (); |
151 | errno = WSAGetLastError (); |