• 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: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]


  • Subject: Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
  • From: Jim Matthews <email@hidden>
  • Date: Fri, 20 Jun 2008 22:18:23 -0400

At 2:23 AM -0700 6/20/08, Eli Bach wrote:
How can I do an orderly vs a disorderly TCP disconnect using CFWriteStream in my daemon?

I hope that someone from Apple responds, because I've wondered what they recommend. What I've been doing, when I want to gracefully close a connection, is:


- Finish writing any buffered data
- wait for the kCFStreamEventCanAcceptBytes callback
- call CFWriteStreamClose
- call shutdown(sock, SHUT_WR) on the native socket
- after the the paired CFReadStream closes, call close() on the native socket

[I don't set kCFStreamPropertyShouldCloseNativeSocket]

The second thing is whether calling CFWriteStreamClose() forces the write buffer to be flushed [at least, so any data buffered within CF is pushed to the kernel]. Even if I get the native socket, then call shutdown() on it, how can I be sure that the CFWriteStream isn't still holding some buffered data?

If you get a kCFStreamEventCanAcceptBytes I believe that CFNetwork has passed all the data to be written to the kernel, and it should be safe to call CFWriteStreamClose and shutdown().


Third, if an error happens, and I want to tear down the connection in a 'disorderly' fashion [ie, not waiting for the send buffer to be flushed to the client, which could potentially take minutes for TCP to timeout], how do I do this?

Immediately call CFReadStreamClose and CFWriteStreamClose, and close the native socket (if you haven't set kCFStreamPropertyShouldCloseNativeSocket).


Thanks,
--
Jim Matthews
Fetch Softworks
http://fetchsoftworks.com
_______________________________________________
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


  • Follow-Ups:
    • Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
      • From: Eli Bach <email@hidden>
References: 
 >Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here] (From: Eli Bach <email@hidden>)

  • Prev by Date: Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
  • Next by Date: Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
  • Previous by thread: Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
  • Next by thread: Re: Problem closing CFWriteStream [moved from darwin-dev, as it seems more appropriate here]
  • Index(es):
    • Date
    • Thread