[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is wron
From: |
Andrew Evdokimov |
Subject: |
[gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is wrong with my understanding of code? |
Date: |
Fri, 09 Mar 2012 15:11:28 +0400 |
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!
WBR,
Andrew
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gpsd-dev] Implementing pselect() in gpsctl (bug #35765) - what is wrong with my understanding of code?,
Andrew Evdokimov <=