caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christopher A. Watford" <christopher.watford@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Keyboard interrupt in Windows
Date: Wed, 29 Jun 2005 12:13:46 -0400	[thread overview]
Message-ID: <8008871f0506290913518bba6b@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0506291051570.11222@cslab10f>

On 6/29/05, Nathaniel J. Gaylinn <ngaylinn@cs.brown.edu> wrote:
> 
> In Linux, OCaml uses signals to break out of the current evaluation (when
> you press Ctrl+C to cut out of an infinite loop). However, Windows doesn't
> support signals. What does OCaml do differently under Windows to make this
> work?
> 
>  -- Nate Gaylinn

Win32 DOES support signals, it just does not send any signal on
CTRL+C. A second thread opens that posts a message to WinMain. The
OCaml Windows IDE has an example of using this to send the interrupt
to the toplevel.

In the following file at the very bottom:
http://dorm.tunkeymicket.com/OCamlWinPlus/Release/src/startocaml.c

// The following sends a CTRL+C/CTRL+BREAK to the console.
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)

Note you MUST write to the Win32 Pipe Handle AFTER you call the break,
otherwise your application will have no idea the pipe was interrupted.

As far as how the toplevel itself handles the CTRL_BREAK_EVENT:

// PHANDLER_ROUTINE looks like: BOOL WINAPI HandlerRoutine(DWORD dwCtrlType);
// Add - TRUE to add a handler, FALSE to remove the handler
BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add);

And the CTRL_*_EVENTs you can handle are:
CTRL_C_EVENT
CTRL_BREAK_EVENT
CTRL_CLOSE_EVENT - [X] clicked
CTRL_LOGOFF_EVENT - user logoff
CTRL_SHUTDOWN_EVENT - machine shutdown or service shutdown

Hope that helps.

-- 
Christopher A. Watford
christopher.watford@gmail.com
http://dorm.tunkeymicket.com


      reply	other threads:[~2005-06-29 16:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 20:08 OCaml IDE (Camlp4 for code formatting) Nathaniel J. Gaylinn
2005-06-21 10:33 ` [Caml-list] " Hendrik Tews
2005-06-21 13:47   ` Nathaniel J. Gaylinn
2005-06-21 15:18     ` Hendrik Tews
2005-06-21 18:11       ` David Brown
2005-06-29 14:54         ` [Caml-list] Keyboard interrupt in Windows Nathaniel J. Gaylinn
2005-06-29 16:13           ` Christopher A. Watford [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8008871f0506290913518bba6b@mail.gmail.com \
    --to=christopher.watford@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).