I'm trying to write an application server in Scheme with Bigloo implementation. The code:
(module server
(library fthread)
(main main))
(define *port-num* 8080)
(define (main argv)
(let* ((socket0 (make-server-socket *port-num*))
(ts (thread-start! (make-thread (lambda () (start-server socket0))))))
(scheduler-start!)
(fprint (current-error-port) "Shutting down...")))
(define (start-server socket0)
(lambda ()
(print "Starting server...")
(let loop ()
(let ((s (socket-accept socket0)))
(print "New connection: " s)
(thread-start! (make-thread (lambda () (handle-request s))))
(thread-yield!)
(loop)))))
(define (handle-request s)
(print "new request")
(socket-shutdown s #f))
It compiles OK, but program terminates immediately after starting:
$ bigloo -o server server.scm
$ ./server
Shutting down...
Where I'm wrong?
Thanks a lot.
I don't know Bigloo's fthread library, but might it be that you immediately return lambda from
start-server
instead of doing work?Like I said, I don't know fthread, so maybe this is how you're supposed to use it. Except that in
handle-request
you don't have this lambda wrapper, and you callmake-thread
exactly the same way:If this is the problem, you can fix it either by getting rid of the lambda inside
start-server
, or by changing your firstmake-thread
call to