Re: [PATCH v2 13/14] daemon: use select() instead of poll()
- From
Erik Faye-Lund <kusmabite@googlemail.com>
- Date
- Jan 15, 2010, 23:23 UTC
- Message-ID
- <40aa078e1001151523o538b44c7x95def3447650eea4@mail.gmail.com>
- In-Reply-To
- <40aa078e1001151508j208fa50boc5565a3be6bef893@mail.gmail.com>
On Sat, Jan 16, 2010 at 12:08 AM, Erik Faye-Lund <kusmabite@googlemail.com> wrote:
Show 24 quoted lines
> On Fri, Jan 15, 2010 at 11:49 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>> On Freitag, 15. Januar 2010, Erik Faye-Lund wrote:
>>> +#undef FD_SET
>>> +#define FD_SET(fd, set) do { \
>>> + ((fd_set*)(set))->fd_array[((fd_set *)(set))->fd_count++] =
>>> _get_osfhandle(fd); \ + } while(0)
>>> +#undef FD_ISSET
>>> +#define FD_ISSET(fd, set) __WSAFDIsSet(_get_osfhandle(fd), (fd_set
>>> *)(set)) +
>>
>> I'm worried about the internals that you have to use here. Isn't it possible
>> save the original macro text and use it in the new definition, like (this is
>> for exposition only):
>>
>> #define ORIG_FD_SET(fd, set) FD_SET(fd, set)
>> #undef FD_SET
>> #define FD_SET(fd, set) ORIG_FD_SET(_get_osfhandle(fd), set)
>>
>
> Redefining it is indeed fishy - I guess I should also have noted that
> I even stripped the code down slightly (compared to the original).
>
> I'm no preprocessor wizard, but I'll give it a stab.
>The following worked for me:
diff --git a/compat/mingw.h b/compat/mingw.h index e515726..ea15967 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -269,10 +269,13 @@ int mingw_accept(int sockfd, struct sockaddr *sa, socklen_t *sz); int mingw_rename(const char*, const char*); #define rename mingw_rename +static inline void mingw_fd_set(int fd, fd_set *set) +{ + FD_SET(_get_osfhandle(fd), set); +} #undef FD_SET -#define FD_SET(fd, set) do { \ - ((fd_set*)(set))->fd_array[((fd_set *)(set))->fd_count++] = _get_osfhandle(fd); \ - } while(0) +#define FD_SET(a,b) mingw_fd_set(a,b) + #undef FD_ISSET #define FD_ISSET(fd, set) __WSAFDIsSet(_get_osfhandle(fd), (fd_set *)(set))
-- Erik "kusma" Faye-Lund