|
Home > Archive > Unix Programming > April 2005 > tcp socket problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
tcp socket problems
|
|
|
| What can I say, I thought I used due dilligence. I wrote a client in C
that is having difficulty when the server does bad things. The symptom
manifests itself with EBADF on close(sock); I should have never reached
this point, but some guy named Murphy just loves poking his nose into
socket programming.
When we reach close(sock) and it sets the errno to EBADF, the program
is still okay. The problem is, I reuse that socket descriptor. It's at
that point, that bad things happen. (Usually it gets stuck in close).
What are some good strategies for recovering from a bad file descriptor
or never getting in that situation in the first place?
Here's my socket functions if anybody cares to peruse them:
ftp://ftp.joedog.org/pub/siege/beta/sock.c
ftp://ftp.joedog.org/pub/siege/beta/sock.h
Jeff
| |
| David Schwartz 2005-04-15, 5:57 pm |
|
"Jeff" <joesiege@gmail.com> wrote in message
news:1113597738.222816.131660@z14g2000cwz.googlegroups.com...
> What can I say, I thought I used due dilligence. I wrote a client in C
> that is having difficulty when the server does bad things. The symptom
> manifests itself with EBADF on close(sock); I should have never reached
> this point, but some guy named Murphy just loves poking his nose into
> socket programming.
This must mean that you are either passing a value to 'close' that does
not refer to a socket or you are closing the same socket twice. There is
pretty much no other possibility.
> When we reach close(sock) and it sets the errno to EBADF, the program
> is still okay. The problem is, I reuse that socket descriptor. It's at
> that point, that bad things happen. (Usually it gets stuck in close).
> What are some good strategies for recovering from a bad file descriptor
> or never getting in that situation in the first place?
There's a lot of places in your code where you close a socket but don't
set your internal socket value to '-1'. As a result, it's easy to not
realize that the function you called closed the socket.
DS
|
|
|
|
|