Go Back   UNIX Socket FAQ > UNIX Platforms > Networking

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2006, 09:39 AM
miles_christian miles_christian is offline
 
Join Date: Aug 2006
Posts: 2
Question not receiving POLL_HUP on socket disconnect

Hi,

I'm trying out RT signals for socket event notification. I am able to get POLL_IN events just fine, but when a remote socket connection disconnects I do not receive any POLL_HUP events. Instead I receive a POLL_IN event(actually two POLL_IN events), then I have to call recv() just to check for disconnection.

I'm using sigwaitinfo() to get the events, and I set all sockets to non-blocking and asynchronous, and set them to send an RT signal on i/o events, using F_SETSIG. I'm running on linux RedHat enterprise 3.

I'm wondering why I don't recv POLL_HUP events on disconnect. If anyone can help, i'd appreciate it :)
Reply With Quote
  #2  
Old 08-17-2006, 11:23 AM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Getting POLL_IN and recv() returning 0 is the expected behaviour, you need to check for that anyway, so I don't know why you'd prefer getting a POLL_HUP too.

Looking at the Linux kernel code, POLL_HUP is only send when the connection is fully closed. ipv4/tcp_input.c:

Code:
		/* Do not send POLL_HUP for half duplex close. */
		if (sk->sk_shutdown == SHUTDOWN_MASK ||
		    sk->sk_state == TCP_CLOSE)
			sk_wake_async(sk, 1, POLL_HUP);
		else
			sk_wake_async(sk, 1, POLL_IN);
I don't know how old RedHat enterprise 3 is, but if it uses a 2.6 kernel you can use epoll(2) instead of that signal cruft (signal buffers can overrun, so you need to have a fallback to something else anyway. Epoll has a nicer API and is faster too).
Reply With Quote
  #3  
Old 08-18-2006, 10:24 PM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

Just curious...

Are you ONLY using the signals or do you have an external looping call to the normal poll?

The 'normal' ( though not only ) way of implementing this is to have an outer poll loop... when poll returns you handle all the 'ready' descriptors... then use a call to sigwaitinfo to capture when the read / write ops you just performed have completed... and to get things like the hup when that occurs...

You may be doing this and still have issues... the only reason I am inquiring is that I have seen folks try to impl using JUST the signals... which is a nightmare for too many reasons to list here... ;-)


Michael


PS On a side note - if someone wants to get a tag / name in the linux kernel maybe a silly submission in net/sock.h like:

Code:
#define RCV_SHUTDOWN    1
#define SEND_SHUTDOWN   2
#define SHUTDOWN_MASK   RCV_SHUTDOWN | SEND_SHUTDOWN
would work... since from what I have seen hard coding SHUTDOWN_MASK to 3 is just a bit silly...
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #4  
Old 08-18-2006, 10:52 PM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Well, if you go for it then at least add parentheses around it. ;-)
Reply With Quote
  #5  
Old 08-18-2006, 11:02 PM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

Real men don't use parentheses when they aren't needed... that would like putting on pants before getting the morning newspaper from the front steps...

:-P


Michael
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #6  
Old 08-18-2006, 11:36 PM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Code:
#include <stdio.h>

#define RCV_SHUTDOWN    1
#define SEND_SHUTDOWN   2
#define SHUTDOWN_MASK   RCV_SHUTDOWN | SEND_SHUTDOWN

int main(void)
{
    int flags = SEND_SHUTDOWN;
    int test;

    test = ~SHUTDOWN_MASK & flags;
    printf("flags = %.2X, should be zero\n", test);
    return 0;
}
I'd rather get the paper without pants than miss those parentheses.
Reply With Quote
  #7  
Old 08-18-2006, 11:44 PM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

I was just joking with you... :-P

You are correct... the parentheses should be their to make sure its not screwed up due to precedence ordering when its used...


Michael


P.S. If you still don't get it... hint - ref to 'real men' and the fact that I have made comments that I am the only ... on the board... hahah
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #8  
Old 08-19-2006, 12:00 AM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Well, putting on pants to get the newspaper is common to do, even though it's unnecessary and doesn't make much sense. I just extrapolated that to parentheses. So I might slightly be confused, or even totally confused, as long as I'm not confusing I'm happy.
Reply With Quote
  #9  
Old 08-19-2006, 12:24 AM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

Argh!

Ok... ignore the newspaper part cause that was just 'filler'... lol

I guess my 'joke' was just too convoluted... let me try to explain... and it still may not make any sense but:

"Real men don't use parentheses when they aren't needed..."

So 'real men'... for most in the US that would be a heterosexual... probably the kind that likes to chew and spit tobacco at people... is married... beats on the wife and children when he gets drunk... which he does every night... so on and so forth...

Now... and I know this has been mentioned somewhere before... I am gay... therefore by that definition I would not a 'real man'... though I guess I could spit tobacco juice at people - but rest assured I do not...

This is where it gets complicated... a 'real man' would NOT use parentheses... since I am not a 'real man'... then I would / should have used parentheses... therefore you are correct...

Sry - I was just bored and trying to be funny... I didn't mean to cause any confusion... lol

Michael
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #10  
Old 08-19-2006, 06:13 PM
RobSeace RobSeace is offline
Administrator
 
Join Date: Jun 2002
Location: Boston, MA
Posts: 3,382
Default

[And, I thought it was just a play on the old "Real Programmers don't ..." series of
jokes (eg: "Real programmers don't use comments; if the code was hard to write, it
should be hard to read, and damn near impossible to modify!" ;-))... Which still
makes the joke work, because most of those things were just satarical bad coding
practices that no programmer worth a damn would actually follow... Your intended
interpretation never even occurred to me... As Vroomfondel said, "I guess our minds must
be TOO highly trained, Majikthise!"... ;-)]
Reply With Quote
  #11  
Old 08-19-2006, 11:18 PM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

Off topic but a truly bizarre twist to this thread and my last post...

I do consulting and the fact that my current job was finishing up was fairly common knowledge... so over the past few weeks I have been pestered by a number of companies... especially those in the US who have subsidiaries etc. overseas and who want someone who is familiar with / has experience working in Asian countries...

One company in particular was offering a management position... which I really wasn't interested in but they kept raising their offer amount and adding on perks... so I was starting to seriously consider accepting but... yesterday I received an email stating that I did not meet the "moral" standards for the company... AND the example they provided was a link to THIS THREAD...

Now if this was all in the US they could get in trouble... so their msg insisted it was the decision of the management of the subsidiary... and that they were just the messenger... that since I would have been working overseas... paid directly by their subsidiary... so on and so forth... that ( of course ) it was all justified since they were following the practices AND the legal policies of the subsidiary and country ( or registration )...

Where the bizarre part comes in... a couple hours ago I received an email from one of the guys at the subsidiary ( a person I know and who would have been one of my peers )... expressing regret that I decided to turn down the position and stop the negotiation process... so THATs what happened... lol

Ah well... welcome to America boys and girls...

We now return you to your regularly scheduled programming... :-/


Michael
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #12  
Old 08-20-2006, 12:18 AM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Eh, well, I live in Amsterdam, so we're slightly more relaxed about gay people here it seems. I don't consider it to be anything special, it's like mentioning the colour of your hair as far as I'm concerned. Maybe that's one of the reasons I didn't get it at all...

Look at it from the bright side: If they're that narrow minded then they don't deserve to have you working for them, and you can lend your talents to some competitor. Doesn't make it less annoying and absurd, but still, it's something.
Reply With Quote
  #13  
Old 08-20-2006, 01:23 AM
mlampkin's Avatar
mlampkin mlampkin is offline
Administrative Lurker
 
Join Date: Jun 2002
Location: Sol 3
Posts: 910
Default

Yeah... well...

People in the U.S. like to pretend tolerance and such... but the reality is ( in most areas of the country ) quite the opposite... and its easy to see if people actually look...

I mean - as an example - in many states if you are gay and say had a family member ( or friend ) die and in their will assign you to be the guardian of their children... it wouldn't be allowed... you cannot adopt... can forget about teaching at anything except the university level... so on and so forth... the funny thing is that things such as my property taxes support the local schools and the education of everyone else's children... and since I'm not allowed children you would think they would at least give me a discount of some type ! ;-)

Back on topic...

Miles - did you figure out the problem with your code... was it wrapped in a normal outer poll loop or similar... or were you attempting to do a direct signal driven system?


Michael
__________________
"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)
Reply With Quote
  #14  
Old 08-20-2006, 02:16 PM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

That's more or less how paedophiles are treated here, seem they're confusing some things there overseas...

But to go back on-topic:

I don't he has any real problem, only wondering abouw why he doesn't get a POLL_HUP. Maybe the POLL_IN is send first, and if you don't close the socket after recv returned 0, it will send the POLL_HUP, or something.
Reply With Quote
  #15  
Old 08-20-2006, 04:37 PM
RobSeace RobSeace is offline
Administrator
 
Join Date: Jun 2002
Location: Boston, MA
Posts: 3,382
Default

Move to Mass., Michael: we'll even let you get married here! ;-) (Though they keep
making noises in the legislature about changing the constitution to prevent it, they
don't seem to be getting anywhere... But, even here in the most liberal state in the
US, there still exist idiots who feel they have a right to tell others what they can and
can't do in their personal lives... So, yeah, on the whole, you're definitely right about
America and its pseudo-tolerance...)
Reply With Quote
  #16  
Old 08-22-2006, 03:04 AM
miles_christian miles_christian is offline
 
Join Date: Aug 2006
Posts: 2
Default thanks

Hi,

Sorry just replied now, had a long weekend with a holiday just after, so only got to post now. Anyway thanks for all the help. I've been reading around too and found that different linux implementations do not send POLL_HUP and some do, so it's better to just read() 0 to get the disconnect. Not using epoll also coz am not using 2.6 kernel.

I'm just using signal without a outer poll. Tell me, but I thought you use RT signals as an alternate to poll, and signals notify you when i/o is ready and not when i/o is done (like asynchronous i/o interface does), so why would I use poll before signal?

real men will only use parenthesis when told they are not needed! Will put on pants only if no one's lookin...

sucks what happend with that company, mlampkin, hope things go well. There shouldn't even be need for tolerance if we embrace our differences. Humanity needs more parentheses our moral precedence is ambiguous.
Reply With Quote
  #17  
Old 08-22-2006, 10:56 AM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Problem of RT signals is that if many of those are sent, the signal queue can fill up and signals will be dropped, or so I understood. If you detect that then you need to use something like poll to get the info from the dropped signals. So the poll is only as a backup. Anyway, it's something you'd need to look into and double check if it's true.
Reply With Quote
  #18  
Old 11-19-2006, 08:18 PM
Uzume Uzume is offline
Administrator
 
Join Date: Aug 2002
Posts: 186
Default

Quote:
Originally Posted by mlampkin
PS On a side note - if someone wants to get a tag / name in the linux kernel maybe a silly submission in net/sock.h like:

Code:
#define RCV_SHUTDOWN    1
#define SEND_SHUTDOWN   2
#define SHUTDOWN_MASK   RCV_SHUTDOWN | SEND_SHUTDOWN
would work... since from what I have seen hard coding SHUTDOWN_MASK to 3 is just a bit silly...
Why not just use the standard symbols from sys/socket.h: SHUT_RD, SHUT_WR, SHUT_RDWR?

Oh, nevermind. You meant in kernel space--boggles.
Reply With Quote
  #19  
Old 11-23-2006, 11:21 PM
Loco Loco is offline
Old administrator
 
Join Date: Jun 2002
Location: Colombia
Posts: 351
Unhappy

Michael,

I'm sorry to hear what this company did. Probably it's worse for them than for you, as they won't have you on board. I guess you'll have lots of offers soon, and much better than theirs.

Regards

Hector
Reply With Quote
  #20  
Old 11-24-2006, 03:19 PM
biologz biologz is offline
Drunk Administrator
 
Join Date: Nov 2005
Location: Puking on the pavement
Posts: 391
Default

Lol michael are you really gay??

if yes i'm a genious because one day i told you that you and i3839 were my gay parents (i'll try to find the thread one day) :-)

so i3839 when will you admitt that you're gay so everyone here call me the oracle ;-)
__________________
gethostbyintuition() is still a dream of mine

-- quoted from bash
Reply With Quote
  #21  
Old 11-24-2006, 04:39 PM
i3839 i3839 is offline
Oddministrator
 
Join Date: Jun 2003
Location: Amsterdam
Posts: 2,002
Default

Even if I would be gay, there would still be an ocean between me and Michael, not sure if we ever were on the same continent at all (ever been in Europe?). If the little hurdle of actually having met eachother is taken, there's a small chance we'd fall for eachother, all things considered, not least the age difference (the chance that I'm your brother is significantly higher than me being one of your fathers).

Besided, if I remember correctly, you said that Rob and I were your gay parents, not Michael. ;-)
Reply With Quote
  #22  
Old 11-24-2006, 04:58 PM
biologz biologz is offline
Drunk Administrator
 
Join Date: Nov 2005
Location: Puking on the pavement
Posts: 391
Default

Hmmm well i've found the thread and yes you're right it was you and Rob :-) i was so drunk that night lol...

ok so i'm not the oracle but one day i'll show you that michael is not the only one to have psychic powers ;-)

well and since i'm always posting things that have no relation with the initial post i'd like to say that if you want to answer to my post about tunnels detection you're welcome :-) i still need advices brother.
__________________
gethostbyintuition() is still a dream of mine

-- quoted from bash
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:31 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.