From p.singleton@keele.ac.uk Tue Jun 26 18:54:45 2001
Received: from cmailg5.svr.pol.co.uk (cmailg5.svr.pol.co.uk [195.92.195.175])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f5QGsjc20883
	for <prolog@swi.psy.uva.nl>; Tue, 26 Jun 2001 18:54:45 +0200 (MET DST)
Received: from modem-127.boron.dialup.pol.co.uk ([62.136.4.127] helo=keele.ac.uk)
	by cmailg5.svr.pol.co.uk with esmtp (Exim 3.13 #0)
	id 15Ew6t-0007pP-00
	for prolog@swi.psy.uva.nl; Tue, 26 Jun 2001 17:54:44 +0100
Message-ID: <3B38B3B0.93EF07C0@keele.ac.uk>
Date: Tue, 26 Jun 2001 17:09:20 +0100
From: Paul Singleton <p.singleton@keele.ac.uk>
Organization: SmartArts Computing Consultancy
X-Mailer: Mozilla 4.74 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
To: SWI Prolog <prolog@swi.psy.uva.nl>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: [SWIPL] sockets: interrupting a server

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?

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

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

NB2 my server code is something like this:

  rpc_serve :-
      tcp_socket( Socket),
      tcp_bind( Socket, 8998),
      tcp_listen( Socket, 1),
      tcp_open_socket( Socket, Accept, _),
      tcp_accept( Accept, S2, _ClientIP),
      tcp_open_socket( S2, In, Out),
      ...
      close( In),
      close( Out),
      close( Accept).
 
  rpc_server :-
      rpc_serve,
      rpc_server.

Paul Singleton


