Re: Sleep, NSWorkspaceWillSleepNotification, 30 seconds and the run loop
Re: Sleep, NSWorkspaceWillSleepNotification, 30 seconds and the run loop
- Subject: Re: Sleep, NSWorkspaceWillSleepNotification, 30 seconds and the run loop
- From: "email@hidden" <email@hidden>
- Date: Wed, 30 Sep 2009 21:32:11 +0100
On 30 Sep 2009, at 20:57, Jens Alfke wrote:
On Sep 30, 2009, at 9:59 AM, email@hidden wrote:
Before entering sleep I would like to send small amounts of data
via async instances of CFSocket to the local and some remote hosts.
It's usually best to close open sockets entirely before going to
sleep. The socket might not work anymore when the system wakes
(especially on a laptop). Also, it tells the peer on the other end
you won't be able to receive any data.
I intend to send off my bit of data, hang around ( <= 30 secs) to get
notification and then close everything.
I can take action at the remote end based on observing the socket
closing rather than sending the pre-sleep data.
But I get a cleaner shutdown. A deliberate stop rather than an
unexpected socket disconnection error.
Now I presume that the 30 second sleep delay referred to in the
docs for NSWorkspaceWillSleepNotification means that my app can
dawdle in -appWillSleep for 30 seconds.
Is this correct?
If so then it seems likely that when this method returns the
machine may sleep before all the network data requests complete.
It shouldn't take 30 seconds to send a few packets to servers. And
the user really doesn't want a forced-sleep to be delayed — it's
frustrating when you shut your MacBook because you have to take it
to a meeting, and it sits and sits and sits before the sleep
indicator starts pulsing.
I intend to observe the requests and hopefully sleep ASAP.
Not sure though that having called IOCancelPowerChange(,) wether it
can be revoked before the 30 secs are up.
Perhaps a call to IOAllowPowerChange() will be effective.
Other options might be:
According to http://developer.apple.com/mac/library/qa/qa2001/qa1134.html
I can send the kAESleep event to the loginwindow process.
Don't know yet if trying to initiate sleep again so will prove useless/
effective/disatrous.
call IODeregisterForSystemPower() to see if that has any effect.
—Jens
Jonathan Mitchell
Developer
http://www.mugginsoft.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden