Operating System - HP-UX
1834140 Members
2700 Online
110064 Solutions
New Discussion

Re: Trouble with 'socket' system call

 
Vadim Yezhakov
Advisor

Trouble with 'socket' system call

Hi.
I have server application, wich listen for socket, accepted connections and forks childs.
This app work properly many time, but something unknown occured yestoday.
After this 'accept' system call return error: 'Bad file descriptor'. I trace my application and see, that 'socket' system call return '0' value. After this my server can accept only one connection, and after this 'accept' return error.
Help me please.
3 REPLIES 3
rick jones
Honored Contributor

Re: Trouble with 'socket' system call

When your server forks the child process, does it remember to call close() on the descriptor returned by the accept() call? (This is in the server, not the child) If it does not, eventually, your server process will hit the ceiling for maximum number of open file descriptors - the maxfiles system tunable.

Also, is the socket() call returning 0, or is it actually returning -1 and setting errno to something?
there is no rest for the wicked yet the virtuous have no pillows
Vadim Yezhakov
Advisor

Re: Trouble with 'socket' system call

Hi Rick.
I'am close socket in parent after fork, of course. At the begin i also think that limit of opened descriptors are riched.
But i restart server, run application and problem don't go away.
Socket function not return -1 and not set errno.
It return 0. After this application can accept only first connection (this connection is work properly). But after first accept all another accept calls returns -1 and set errno = 'Bad file descriptor'.
rick jones
Honored Contributor

Re: Trouble with 'socket' system call

use tusc to trace the system/socket calls and make sure the subsequent calls have the fd's you expect them to.
there is no rest for the wicked yet the virtuous have no pillows