Operating System - HP-UX
1819804 Members
3109 Online
109607 Solutions
New Discussion юеВ

connect() fails with EBADF

 
Vaibhav_5
Occasional Contributor

connect() fails with EBADF

Hi

i follow this sequence in my client program

-- snip ---

socketFD = socket(AF_UNIX, SOCK_STREAM, 0);

if (socketFD < 0) {
// return error
}
struct sockaddr_un servAddr;

servAddr.sun_family = AF_UNIX;
.
.
.
while(1)
{
if (connect(socketFD, &servAddr,servLen) {
if (errno == EINTR)
{
// Interrupted, try again
continue;
}

// Other errors are fatal
// return
}
else
{
// Connect succesful
break;
}
}
--- snap ---

The sockect call is all fine ,however i get intermittent errors on connect() saying "Bad file number".

The server program at that time is running fine.

can you please suggest what could be wrong ?

Thanks in advance.

-vaibhav
5 REPLIES 5
Peter Godron
Honored Contributor

Re: connect() fails with EBADF

Hi,
according to various sites:
"Either a file descriptor refers to no open file, or a read (or
write) request is made to a file that is open only for writing
(or reading).
The symbolic name for this error is EBADF, errno=9."

I would check the socket parameters for correctness.
Regards
harry d brown jr
Honored Contributor

Re: connect() fails with EBADF

Shouldn't

if (connect(socketFD, &servAddr,servLen) {

read

if (connect(socketFD, &servAddr,servLen)) {

??

live free or die
harry d brown jr
Live Free or Die
Vaibhav_5
Occasional Contributor

Re: connect() fails with EBADF

Hi Harry ,

Sorry , that was a typo error

---
if (connect(socketFD, &servAddr, servLen) < 0){
---
still not clear why the connect() call would fail.

Regards,
-vaibhav
Peter Godron
Honored Contributor

Re: connect() fails with EBADF

Hi,
according to man connect :
"The connect() system call may complete if remote program has a pending listen() even though remote program had not yet issued an accept() system call."
AND
"[EBADF] s is not a valid file descriptor."

Please check the parameters,length and returned status codes.
Regards
rick jones
Honored Contributor

Re: connect() fails with EBADF

You can use tusc to trace the socket calls and see the actual parameters being passed. Might want to make it a verbose trace.

I think tusc is on the DSPP somewhere. It is also at ftp://ftp.cup.hp.com/dist/networking/tools/

there is no rest for the wicked yet the virtuous have no pillows