• 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: CFSocket questions.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFSocket questions.


  • Subject: Re: CFSocket questions.
  • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Date: Wed, 23 Oct 2013 17:06:22 +0100

On 23 Oct 2013, at 16:29, Jeremy Thompson <email@hidden> wrote:

> I have successfully set up a CFSocket based server model in the carbon based
> project that can receive data and echo it back to me.

Is this a TCP server?  If so, you should use CFSocket for the listening socket but CFStream for each TCP connection (create the stream pair using CFStreamCreatePairWithSocket).  CFStream is your best abstraction for TCP streams.

Once you have a stream pair you can write data using CFWriteStreamWrite.  This is a direct analogue of the classic BSD write() system call, down to the requirement to handle EINTR (-:

If you have a traditional Mac OS handle, you can get the buffer size with GetHandleSize and access the buffer by dereferencing the handle.  For example:

static CFIndex WriteHandle(CFWriteStreamRef writeStream, Handle h)
{
    CFIndex bytesWritten;

    bytesWritten =  CFWriteStreamWrite(
        writeStream,
        *h,
        GetHandleSize(h)
    );
    return bytesWritten;
}

[Traditional Mac OS veterans will tell you that you should lock the handle around the CFWriteStreamWrite, make sure it's not purged, and call GetHandleSize first, but none of that should be necessary on OS X.]

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware



 _______________________________________________
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: 
 >CFSocket questions. (From: Jeremy Thompson <email@hidden>)

  • Prev by Date: CFSocket questions.
  • Next by Date: OpenTransport...
  • Previous by thread: CFSocket questions.
  • Next by thread: OpenTransport...
  • Index(es):
    • Date
    • Thread