[ prog / sol / mona ]

prog


Running SchemeBBS using MIT Scheme 11.2

14 2022-05-30 04:50

>>13
Add that fix to the beginning of bbs.scm:

(ge '(runtime http-i/o))

(define (write-http-response response port)
  (if (http-response-version response)
    (begin
      (write-http-version (http-response-version response) port)
      (write-u8 (char->integer #\space) port)
      (write-ascii (write-to-string (http-response-status response)) port)
      (write-u8 (char->integer #\space) port)
      (write-ascii (http-response-reason response) port)
      (write-u8 (char->integer #\return) port)
      (write-u8 (char->integer #\newline) port)
      (write-http-headers (http-response-headers response) port)))
  (write-bytevector (http-response-body response) port)
  (flush-output-port port))

(ge '(user))

At this point, localhost:8080 should successfully display "site root"!

One more thing: I should have closed the port after serving each request.

--- a/deps/server.scm
+++ b/deps/server.scm
@@ -43,11 +43,9 @@ Initializes our web server.
         (lambda () unspecific)
         (lambda ()
           (do () ((channel-closed? socket))
-            (let ((port (tcp-server-connection-accept socket #t #f)))
-              (dynamic-wind
-                (lambda () unspecific)
-                (lambda () (ignore-errors (lambda () (serve-request port))))
-                (lambda () (ignore-errors (lambda () (close-port port))))))))
+            (let ((port (tcp-server-binary-connection-accept socket #t #f)))
+              (serve-request port)
+              (close-port port))))  ;; <- CLOSE PORT!
         (lambda () (channel-close socket)))))

Now that we have successfully displayed the site root, it's time to fix the board indexes, board lists, new thread creation, etc.

56


VIP:

do not edit these