Re: [NKE]socket_receive
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