PDA

View Full Version : accept returns 0


PTR
05-21-2003, 11:54 AM
I'm trying to create a super-simple client-server. When I call 'accept' in the server it returns a zero. Formally it isn't an error, but when I later calls 'recv' with the accept return value as it's first parametr, it returns -1 and errno=38, which means 'not a socket descriptor'. What is the problem and how can I fix it??

Loco
05-21-2003, 10:41 PM
More input... need more input

Please post more details, the problematic parts of your code, the OS and other information you might find important would be enough to help you out with this

PTR
05-22-2003, 08:02 AM
:lol: I found the bug :). It was, as always, very simple and had nothing to do with what I thought it was. Thanks.

remance
07-21-2006, 09:51 PM
HELP!!!
I know that this posting is very, very old...but I am having the same exact problem: accept() returning a zero.

What was the bug? (cause it's here now)

Thanks.

Bob

mlampkin
07-22-2006, 08:55 AM
By any chance are you closing stdin...?

Its just a thought but... if you are then that means file handle ( number ) 0 becomes available for use... so um... it would be perfectly legitimate for a call to accept to return a value of 0...

If that isn't what is occurring... then I would put forth that your computer is possessed by evil spirits and the appropriate action(s) should be taken immediately...

Darn - it seems part of my message was cut off somehow... continuing... lol

Ok... so that is a likely cause and though its something simple its easy to miss...

If it isn't that...

Are you doing anything strange like creating a listening socket... then forking off children and having more than one of the children doing accept calls on it? Now, that shouldn't be returning you a 0 on error and in fact on the systems that don't like it, it should cause a fault of some sort... but if you have that fault handled ( unintentionally ) by a custom signal handler that doesn't do anything the 'result' of accept could appear to be 0...

Hope that helps... ;-)


Michael

remance
07-24-2006, 01:41 PM
Michael,

Thanks for your timely and creative reply. Turns out that that pesky "missing parens problem" inside a rather deep "if" question is still lurking. A careful inspection of the expression (after about four hours of being sure that I messed something up with the sockets interface) found the problem. Basic stuff.

I'm all set, thanks.

Bob