Re: An attempt to create NON-BLOCKING sockets

From: Erik Ostrom <eostrom_at_ccs.neu.edu>
Date: Mon, 24 Jul 1995 13:39:22 -0400

> The one I am interested to is the capability to make non blocking server sock
> ets
> to avoid the socket-accept-connection to stop the STk execution if there are
> no
> sockets to satisfy.
> This is a real problem when creating servers with GUI, that can be blocked
> waiting for a connection.

I don't have any advice to offer, but this seems like as good a time
as any to offer up some code Dave Kormann and I wrote to solve roughly
the same problem. Rather than provide non-blocking versions of socket
and port creation, we hooked into Tk's event loop to create a callback
mechanism. So, in our system, your example would be something like

(let ((s (make-server-socket 1234)))
  (set-connection-callback! s
                            (lambda ()
                              (let ((c (get-connection s)))
                                (format #t "Read: ~s\n"
                                        (read-line (socket-input c)))
                                (socket-shutdown c #f)))))

... and then the lambda would be called each time a connection comes
in. We also have callbacks for input ports, so you can read input from
multiple sources as it arrives.

This is all implemented as a dynamically loadable (or statically
linkable) extension to STk, plus one change is required to socket.c
(to make tc_socket visible outside that file). I've put the code
along with documentation in

  ftp://kaolin.unice.fr/pub/Incoming/callbacks-0.1.tar.gz

--I hope this was the right place for it.

If anybody ends up using this, please let us know.

Thanks
--Erik
Received on Mon Jul 24 1995 - 19:47:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST