Jump to content
Toggle sidebar
JookWiki
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Navigation
Main page
Recent changes
Random page
All pages
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information
Editing
POLLHUP polling
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
More
Read
Edit
Edit source
View history
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Test code == I wrote this quick program that tests what happens when you poll a closed socket with or without data with various event flags. /* compile and run with gcc test.c -oTEST && ./TEST */ #include <stdio.h> #include <errno.h> #include <poll.h> #include <sys/socket.h> #include <unistd.h> #include <string.h> int do_test(short events, const char *data) { /* create a socket pair, one end for parent, one end for child */ int sockets[2]; int rc; rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets); if(rc == -1) { printf("socket err %i\n", errno); return 1; } if(data) { rc = write(sockets[1], data, strlen(data)); if(rc == -1) { printf("write err %i\n", errno); return 1; } } rc = close(sockets[1]); /* close one end */ if(rc == -1) { printf("close err %i\n", errno); return 1; } /* poll for events */ struct pollfd fd; fd.fd = sockets[0]; /* watch other end */ fd.events = events; fd.revents = 0; rc = poll(&fd, 1, 10000); if(rc < 1) { printf("poll err %i\n", errno); return 1; } printf("do_test events %x data %p: %0x\n", events, data, fd.revents); return 0; } void do_multitest(const char* str) { do_test(0, str); do_test(POLLIN, str); do_test(POLLOUT, str); do_test(POLLIN|POLLOUT, str); do_test(POLLIN|POLLOUT|POLLPRI|POLLHUP|POLLERR|POLLNVAL, str); } int main(void) { printf("POLLIN: %x POLLOUT: %x POLLHUP: %x\n", POLLIN, POLLOUT, POLLHUP); do_multitest(NULL); do_multitest("hello world"); return 0; } It's a bit nasty but it seems to get the job done to verify behaviour.
Summary:
Please note that all contributions to JookWiki are considered to be released under the Creative Commons Zero (Public Domain) (see
JookWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To edit this page, please answer the question that appears below (
more info
):
Who owns this wiki?
Cancel
Editing help
(opens in new window)