• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting socket is closed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting socket is closed


  • Subject: Re: Detecting socket is closed
  • From: Josh Graessley <email@hidden>
  • Date: Wed, 5 Jul 2006 10:51:33 -0700


SIGPIPE on the write call is the error indicating that the remote side has closed.


If you were to read on the socket, you would get the same error. In addition, if you were to add the socket to select or a kqueue for reading or writing, the select/kqueue would fire when the connection was disconnected.

There is a good book called Unix Network Programming by Stevens that covers how sockets work.

-josh

On Jul 5, 2006, at 10:34 AM, Mark Thomas wrote:

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




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >Re: Detecting socket is closed (From: Mark Thomas <email@hidden>)

  • Prev by Date: Re: Detecting socket is closed
  • Next by Date: Re: Detecting socket is closed
  • Previous by thread: Re: Detecting socket is closed
  • Next by thread: Re: Detecting socket is closed
  • Index(es):
    • Date
    • Thread