LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2012, 09:44 AM   #1
alphy
LQ Newbie
 
Registered: Nov 2006
Posts: 16

Rep: Reputation: 0
Question Questions on epoll_wait()


Hi Folks,

Based on online tutorials and examples for epoll,

EPOLLIN - indicate available data.
EPOLLHUP - indicates a remote connection close.

Now in the below mentioned scenario, what would be the behavior of epoll_wait?

(1) epoll_wait returns for FD_X with EPOLLIN.
(2) In a while loop, I start reading the data.
(3) At the same time while I am executing read(Step 2), if remote end closes the connection for FD_X, Would I get a separate EPOLLHUP event, if I go back to wait on epoll_wait()? How do I detect this otherwise?

Based on written examples, I get an EIO error on read, if the remote end has closed the connection.

Is it possible to differenitate between an EIO error that occurs due to
(1) A remote connection close.
(2) Legitimate error in read.

Thanks for the help.

-Alphonse
 
Old 07-20-2012, 12:10 PM   #2
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by alphy View Post
Hi Folks,

Based on online tutorials and examples for epoll,

EPOLLIN - indicate available data.
EPOLLHUP - indicates a remote connection close.

Now in the below mentioned scenario, what would be the behavior of epoll_wait?

(1) epoll_wait returns for FD_X with EPOLLIN.
(2) In a while loop, I start reading the data.
(3) At the same time while I am executing read(Step 2), if remote end closes the connection for FD_X, Would I get a separate EPOLLHUP event, if I go back to wait on epoll_wait()? How do I detect this otherwise?

Based on written examples, I get an EIO error on read, if the remote end has closed the connection.

Is it possible to differenitate between an EIO error that occurs due to
(1) A remote connection close.
(2) Legitimate error in read.

Thanks for the help.

-Alphonse
Hey Alphonse,

to get more accurate error distinction, you can also set the EPOLLRDHUP flag using epoll_ctl().

When epoll_wait() returns, check for EPOLLRDHUP (peer disconnected), EPOLLHUP (unexpected close of socket), EPOLLERR (fd error condition), EPOLLIN (data available).

In the last case (only EPOLLIN set), invoke read().
If read() returns -1, check errno for specifics.
If read() returns 0, this would be quite a surprise.

Do you have a test program available to play with?

Kind regards
dmdeb
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New Linux user with a few questions - Networking and Drivers questions Techsniffer Linux - Newbie 9 04-04-2012 12:21 PM
Make questions and ARCH questions for gentoo/calculate linus72 Calculate 5 04-09-2010 12:53 AM
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
LXer: Questions Answered, Questions Posed - What Happened? LXer Syndicated Linux News 0 05-14-2007 02:46 PM
window manager questions and/or theme questions t3gah Linux - Software 2 02-27-2005 04:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration