On 30 Sep 2009, at 20:57, Jens Alfke wrote:


On Sep 30, 2009, at 9:59 AM, jonat...@mugginsoft.com 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to