[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is w
From: |
Eric S. Raymond |
Subject: |
Re: [gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is wrong with my understanding of code? |
Date: |
Thu, 5 Apr 2012 17:14:05 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Andrew Evdokimov <address@hidden>:
> Hi all,
>
> I'm currently working on implementing pselect() for gpsctl (see bug #35765)
> but have faced some difficulties understanding how this program currently
> works. gpsctl has the get_packet() function that is supposed to return a
> packet mask when gpsd_poll() will return one with ONLINE_SET set. Current
> code is as follows (only significant lines are left):
>
> {
> static fd_set rfds;
> gps_mask_t fieldmask;
> struct timeval tv;
>
> FD_ZERO(&rfds);
> for (;;) {
> FD_CLR(session->gpsdata.gps_fd, &rfds);
> ...
> tv.tv_sec = 2;
> tv.tv_usec = 0;
> errno = 0;
> if (select(session->gpsdata.gps_fd + 1, &rfds, NULL, NULL, &tv) == -1) {
> if (errno == EINTR || !FD_ISSET(session->gpsdata.gps_fd, &rfds))
> continue;
> gpsd_report(LOG_ERROR, "select %s\n", strerror(errno));
> exit(2);
> }
>
> fieldmask = gpsd_poll(session);
> ...
> if ((fieldmask &~ ONLINE_SET)!=0)
> return fieldmask;
> }
> }
>
> So before entering a for-loop we're zeroing fd_set rfds (OK with
> this), then in a loop we're removing 'session->gpsdata.gps_fd' file
> descriptor from already-empty fd_set and then calling select() with
> 2-seconds timeout that will wait until some of our file descriptors
> will become ready for IO. As soon as rfds does not contain any file
> descriptors the select() call will timeout in 2 seconds passing
> control to gpsd_poll() etc. In other words, select() here is just a
> 2-second sleep. gpsd_poll() does not use our rfds thus at the end of
> a loop we have an empty fd_set which will be cleared of
> session->gpsdata.gps_fd at next iteration etc...
>
> Where am I wrong? I'm new to this project and may not fully
> understand some internal logic, so please help. Thanks in advance!
Sorry about the belated response. I think I see what confused you.
The FD_ISSET macro doesn't mutate rfds, just tests to see if
session->gpsdata.gps_fd is in it.
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is wrong with my understanding of code?,
Eric S. Raymond <=