Operating System - HP-UX
1849279 Members
5901 Online
104042 Solutions
New Discussion

Problem on poll(2) system call

 
Blade Doyle
New Member

Problem on poll(2) system call

I am seeing problem with ‘poll’ system call on “HP-UX 11i v3” but not on earlier versions.

count = poll(fds, MAXFDS, timeout);

fds[n].revents is set to POLLERR on a closed file descriptor but on other UNIX and earlier HP operating system fds[n].revents is set to POLLIN. Is this a bug on HP v3 system?

Aziz Ahmad


#include
..........
#define MAXFDS 1000

int main(int argc, char** argv)
{
int count;
bool terminate = false;
struct pollfd fds[MAXFDS];

// fds.fd[n] are either -1 or a valid file descriptor
// fds.events[n] = POLLIN for valif fds
// fds.revents[n] = 0

while(!terminate)
{
do
{
count = poll(fds, MAXFDS, 30);
} while ((count == -1) && (errno == EINTR));
if (count == -1) {
// clear bad file descriptor from poll array fds
// print error message
continue;
}
for int i=0; i {
// on v3 revents is set to POLLERR for a closed socket
// on v2 and earlier revents is set to POLLIN for a closed socket
if (fds[i].revents & POLLIN) // works fine on UNIX and HP except v3
// read fds[i].fd and do something
;
// recv on a closed socket returns 0 on hp v2 but 4 on v3
//
if (fds[i].revents & POLLIN | POLLERR) // POLLERR needed in v3 to work properly
// remove fd with POLLERR from fds array
// read fds[i].fd and do something
;
}
}
}
1 REPLY 1
rick jones
Honored Contributor

Re: Problem on poll(2) system call

In the code you have provided is the commented-out stuff before while(!terminate) supposed to imply that fds has been initialized before the while loop?

Apart from wondering if folks using poll should always be checking for POLLERR anyway, regardless of past HP-UX behaviour, you might check for current patches to 11iv3. If you haven't already done so, checking the 11iv3 manpage for poll might be a good idea.

When you say closed socket, closed how exactly? And by that you mean a socket closed on the remote, or do you mean a local socket closed by another thread in the same appliction?

Is there any chance that data could have been in flight to this remote socket being closed and so triggering an RST?

Can you expand a bit on the comment "recv on a closed socket returns 0 on hp v2 but 4 on hpv3?

When/if you do go to the response center with this, they'll probably want a complete test case.
there is no rest for the wicked yet the virtuous have no pillows