From: gmcm at hypernet.com (Gordon McMillan)
Date: Thu, 27 May 1999 10:15:38 -0500
Subject: Stupid Windows Question
In-Reply-To: <927772969.756087@meusis3>
Message-ID: <1284304128-4799717@hypernet.com>
Content-Length: 1277
X-UID: 1872                                                 

Mark Nottingham writes:

> What's the equivalent of an alarm() on Windows? I need to time out a
> httplib fetch of a URL...

Hee hee. I love signals on WIndows.

The following signals are defined (MSVC docs):
--------------------------------------
SIGABRT
 Abnormal termination

SIGFPE
 Floating-point error

SIGILL
 Illegal instruction

SIGINT
 CTRL+C signal

SIGSEGV
 Illegal storage access

SIGTERM
 Termination request
--------------------------------------------
but you'll never get a SIGINT, because WIndows spawns a new thread to 
handle it. However:
----------------------------------------
The SIGILL, SIGSEGV, and SIGTERM signals are not generated under
Windows NT. They are included for ANSI compatibility [editor's note: 
har de har har har]. Thus you can set signal handlers for these 
signals with signal, and you can also explicitly generate these 
signals by calling raise.
----------------------------------------

So, on NT at least (who knows about the others) you could emulate 
SIGALRM with a windows timer and a raise(). Snort.

More straightforward would be to use select with a timeout on the 
socket, but that's more hackery of a different sort... Or use 
threads, and just kiss off the thread if it doesn't respond within 
your timeout.

- Gordon




