How to execute cleanup code on Ctrl-C (Break)?
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jul 8 19:25:09 PDT 2012
On Monday, July 09, 2012 04:15:08 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.
core.sys.posix is for _POSIX_ OSes only. Much as Windows does implement some
POSIX functions, it's is not a POSIX OS (version(Posix) blocks will not
compile for it). If you want Windows stuff, you need to look in
core.sys.windows, which unfortunately is currently rather sparse overall, so I
very much doubt that there's any kind of signal handling in it right now. If
you want additional Win32 functions, take at look at this 3rd party project:
http://dsource.org/projects/bindings/wiki/WindowsApi
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list