[erlang-questions] Erlang and sleep mode under Windows

zxq9 zxq9@REDACTED
Thu Sep 7 08:03:09 CEST 2017


On 2017年09月07日 木曜日 04:49:07 Frank Muller wrote:
> 1. Can I detect the sleep mode and recover from it programmatically?

No idea. This is an interesting question, though. I imagine Windows provides some way of figuring this out -- perhaps through a registry query.

That said, since Linux, OSX and Windows all have power states it would certainly be useful if the EVM provided some way to subscribe to OS power state changes.

-spec os:subscribe(pid(), power_state) -> ok | {error, term()}.

(Looking at the spec of that function I am obviously envisioning more uses for that than just power states...)

> 2. To avoid restarting the app, is it possible to restart only the
> networking part of the VM (not even sure if such a thing exits/feasible)?

I don't think there is a way right now to detect sleep mode or "I've just woken back up!" without writing a native Windows service to notify you, but it IS possible to check whether your socket is still connected and programmatically recover from this. Provide a check and reconnect for when a connection goes down and it should handle your network failures for you. Incidentally, that will also make moving between networks work more smoothly.

Losing connectivity between sleep intervals or between network transitions and IP reassignments is just a reality of modern client-side coding.

-Craig



More information about the erlang-questions mailing list