• 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: CFSocketSendData timeout?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFSocketSendData timeout?


  • Subject: Re: CFSocketSendData timeout?
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 16 May 2002 17:24:21 -0700

On Thursday, May 16, 2002, at 11:30 AM, Avi Drissman wrote:

From the appearance of this call, this seems to be a synchronous blocking call. I call CFSocketSendData with a timeout of 30 seconds, and if the destination is unreachable, this call returns in 30 seconds. Is that so?

The sample code that I've been seeing uses a timeout of 0. Is that no timeout in the sense of "waiting forever" or in the synchronous, nonblocking Yoda sense? ("Send, or do not. There is no try.")

This is a synchronous blocking call; it returns when the send succeeds, when the send times out, or when an error occurs. Note that the send succeeds when the data is sent, not when it is received; you are unlikely to see a send time out unless you are sending lots of data. A timeout <= 0 means that the send won't time out--the data will eventually be sent, or an error will occur.

Keep in mind: the purpose of CFSocket is to provide a way for sockets to act as run loop sources, not to wrap various pieces of socket functionality. You will often want to do most of the non-notification socket functions (e.g., reads and writes) yourself, or via something else like CFStream. CFSocketSendData() is not part of the main purpose of CFSocket; it is a convenience API, handy at times, but if you are stressing the write side of the socket--for example, if you are sending lots of data--you will probably want to use something else, e.g. CFStream.

The CFSocket example I posted used CFSocketSendData() because that helped it fit on four slides. The example isn't terribly realistic in any of its read and write handling--it ignores the read data, for example. For a more elaborate and more realistic example, take a look at the CFStream-based echo server, discussed in the second half of the WWDC talk--which doesn't fit on slides at all. It's in /Developer/Examples/Networking on the CDs. It uses CFSocket more or less like my example did, except that it then uses CFStream for the read and write part.

In Jaguar, CFSocket will also provide the option of notifications when a socket is ready for writing. That is another option for high-volume writes.

Douglas Davidson
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >CFSocketSendData timeout? (From: Avi Drissman <email@hidden>)

  • Prev by Date: Re: Modified AuthSample and Focus
  • Next by Date: Re: Rendevous/Zeroconfig with Carbon CFM
  • Previous by thread: CFSocketSendData timeout?
  • Next by thread: Network Device Naming OS9
  • Index(es):
    • Date
    • Thread