• 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: [NKE]socket_receive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NKE]socket_receive


  • Subject: Re: [NKE]socket_receive
  • From: Quinn <email@hidden>
  • Date: Thu, 13 Mar 2008 13:56:23 +0000

At 6:36 -0400 13/3/08, Terry Simons wrote:
In a normal application this might be handled by attempting to read, and then sleeping for some small amount of time if EWOULDBLOCK is received, then atempting to read again.

That's not a good idea. Effectively this means that you're polling for the data, which wastes CPU (and power) and limits your response time. A better solution is to add the socket to some sort of event that you can block on. Commonly this involves calling <x-man-page://2/select> or creating a <x-man-page://2/kqueue>.


Sleeping is necessary to avoid pegging the CPU, but I'm not sure what the recommendation would be in an NKE.

This is trickier in an NKE context. You have a couple of choices:

o switch the socket to blocking mode -- This is only appropriate if you can guarantee that the thread that you're running on can be blocked.

o use an upcall -- When you create the socket you can supply pointer to a routine that is called when data becomes available. Looking in <sys/kpi_socket.h> for sock_upcall.

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


  • Follow-Ups:
    • Re: [NKE]socket_receive
      • From: James Chan <email@hidden>
References: 
 >[NKE]socket_receive (From: James Chan <email@hidden>)
 >Re: [NKE]socket_receive (From: Terry Simons <email@hidden>)

  • Prev by Date: Re: Kernel Extensions for iPhone
  • Next by Date: Re: [NKE]socket_receive
  • Previous by thread: Re: [NKE]socket_receive
  • Next by thread: Re: [NKE]socket_receive
  • Index(es):
    • Date
    • Thread