Subject: Re: [SWIPL] sockets: interrupting a server

From: Jan Wielemaker <[email-masked]>
Date: Tue, 26 Jun 2001 22:27:09 +0200

Paul,

> Summary: how can I make my library(socket) application interruptible?
> 
> I'm using library(socket) (on Windows NT4) to implement a simple Prolog
> server: it runs in blocking mode, waits for a connection request, then
> elaborates (determinate) queries until the connection is closed by the
> client, whereupon it listens again ad infinitem.
> 
> Unfortunately it's very hard to kill!
> 
>   Waiting for Prolog.  Close again to force termination ..
> 
>   Main task is not responding.  Click "OK" to terminate it
> 
> Eventually it goes, but there's still a 'plwin.exe' process lurking,
> which continues to hog the port.  I have to "End Process" from Task
> Manager.  I haven't tried it, but I guess a Windows shutdown would hang.
> 
> Is this a problem with Windows and blocking mode?

Certainly.  In the Unix version you just do Control-C and abort or
exit, but Windows doesn't know about signals (= software interrupts).

> I've had a peek at socket.c, and am willing to hack it (but I only have
> documentation, and test capability, for Win32).

If you find something that works I'll be glad to integrate it.

> NB is the IO-stream stuff a model for implementing QP's with_output_to_chars
> and vice versa?  It looks straightforward...

In good old SWI-Prolog you can use '$write_on_string'/2.  See for example
sformat.  Version 4.0.7 contains `memory_file', which allows for creating
an abstract object, opening it as a stream for reading and writing and
get the content as an atom or list of character codes.  Check the clib
package documentation.

	Cheers --- Jan