Subject: [SWIPL] sockets: interrupting a server

From: Paul Singleton <[email-masked]>
Date: Tue, 26 Jun 2001 17:09:20 +0100

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