How to execute cleanup code on Ctrl-C (Break)?

Mike Parker aldacron at gmail.com
Sun Jul 8 20:25:08 PDT 2012


On 07/09/2012 11:15 AM, Paul Dufresne wrote:
> Well, I just want to close a socket before quiting if the user press
> Ctrl-C.
>
> That said, looking through the code, I would say that it have no
> implementation for Windows... even if it should have signals.
>
> And even there, I do not really understand how I am suppose to use it.
> I think it should looks like:
>
> import std.stdio;
> import core.sys.posix.signal;
>
> void mybye(int value){
>    writeln("oh... Bye then!");
> }
>
> void main(){
>      sigset(SIGINT, &mybye);
>      while (true) writeln("H1!!");
> }
>
> which gives me:
> C:\Users\Paul\myd>dmd loop2.d
> loop2.d(9): Error: undefined identifier sigset
>
> Which I guess is because there is no Windows implementation... yet.
>
>
>

There *won't* be a Windows implementation. THis is a Posix API, not a D 
one. In Windows, you need to use SetConsoleCtrlHandler.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016(v=vs.85).aspx


More information about the Digitalmars-d-learn mailing list