Re: Detecting socket is closed
Re: Detecting socket is closed
- Subject: Re: Detecting socket is closed
- From: Mark Thomas <email@hidden>
- Date: Wed, 05 Jul 2006 18:34:41 +0100
- Organization: Coderus Ltd
There's no error being returned which I see apart from a SIGPIPE within the
write call.
What I mean by closed, is that I have opened a connection with a server, but
it has sent some data, and then closed the connection down (server side),
which I didn't expect to happen as I'm in the middle of my request of
sending data up to the server (2M-3M in size). I presently call write n
times depending on how much data was written when I called write again minus
whatever was written last time until there is nothing left to send.
Thanks
Mark.
>
> Calling write on a disconnected socket should not crash. The function
> will return an error. It is up to your application to handle that
> error properly.
>
> If you really meant close (like the file descriptor was closed) as
> opposed to disconnected, it is the responsibility of your application
> to stop using a file descriptor that you closed. You will usually get
> the EBADF error when using an invalid file descriptor. This isn't
> safe because file descriptors are reused all the time, so if you
> aren't properly tracking when a file descriptor is closed, you can
> end up writing to a file descriptor that is not the one you were
> expecting. Since you are reporting the SIGPIPE error, I'm guessing
> that is not the case.
>
> -josh
>
> On Jul 5, 2006, at 10:16 AM, Mark Thomas wrote:
>
>> Hi,
>> Is there a way to tell that a socket has been closed ?, as I¹m
>> seeing if I
>> try writing to socket which has been closed down it will crash out
>> causing a
>> SIGPIPE. I thought something in ioctl would help for this but
>> nothing seems
>> obvious from looking at man and headers files
>>
>> I using a socket in tcp mode if that helps.
>>
>> Any Idea¹s
>> Thanks
>> Mark.
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Macnetworkprog mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40apple.com
>>
>> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden