svn: r8813

This commit is contained in:
Eli Barzilay 2008-02-27 14:04:03 +00:00
parent 36b05ee127
commit 7a1aaadf8d

View File

@ -1,14 +1,16 @@
(module check mzscheme
#lang scheme/base
(define version-url "http://download.plt-scheme.org/version")
(define timeout 30)
(define version-url "http://download.plt-scheme.org/version")
(define timeout 30)
;; This file is invoked from the installer, without using zo files -- so
;; using net/url.ss is extremely slow. Instead, do things directly.
;; (require net/url)
;; (define (url->port url)
;; (get-pure-port (string->url url)))
(define (url->port url)
;; This file can be invoked from an installer, and in case it's
;; without zo files using net/url.ss is extremely slow. Instead, do
;; things directly.
;; (require net/url)
;; (define (url->port url) (get-pure-port (string->url url)))
(require scheme/tcp)
(define (url->port url)
(define-values (host path)
(apply values (cdr (regexp-match #rx"^http://([^/:@]+)(/.*)$" url))))
(define-values (i o) (tcp-connect host 80))
@ -19,7 +21,7 @@
(error 'url->port "bad reply from server: ~a" (read-line)))
i)
(define error-value
(define error-value
(case-lambda
[(what) `(error ,what)]
[(what more)
@ -28,7 +30,7 @@
[(exn? more) (format "(~a)" (exn-message more))]
[else (format "(~a)" more)]))]))
(define (with-timeout timeout thunk)
(define (with-timeout timeout thunk)
(define result #f)
(let ([r (sync/timeout timeout
(thread (lambda ()
@ -39,7 +41,7 @@
(thunk))))))])
(if r result (error-value "timeout"))))
(define (check-version/timeout)
(define (check-version-raw)
(let/ec escape
(define (err . args) (escape (apply error-value args)))
(define-syntax try
@ -86,22 +88,20 @@
;; stable)
[else `(newer ,stable ,recent)]))))
;; Check the version on the server and compare to our version.
;; Possible return values (message is always a string):
;; * `ok
;; You're fine.
;; * `(ok-but ,version)
;; You have a fine stable version, but note that there is a newer alpha
;; * `(newer ,version)
;; You have an old version, please upgrade to `version'
;; * `(newer ,version ,alpha)
;; You have an old version, please upgrade to `version' you may consider
;; also the alpha version
;; * `(error ,message [,additional-info])
;; An error occured, the third (optional) value can be shown as the system
;; error that happened or the value that caused an error.
(provide check-version)
(define (check-version)
(with-timeout timeout check-version/timeout))
)
;; Check the version on the server and compare to our version. Possible return
;; values (message is always a string):
;; * `ok
;; You're fine.
;; * `(ok-but ,version)
;; You have a fine stable version, but note that there is a newer alpha
;; * `(newer ,version)
;; You have an old version, please upgrade to `version'
;; * `(newer ,version ,alpha)
;; You have an old version, please upgrade to `version' you may consider also
;; the alpha version
;; * `(error ,message [,additional-info])
;; An error occured, the third (optional) value can be shown as the system
;; error that happened or the value that caused an error.
(provide check-version)
(define (check-version)
(with-timeout timeout check-version-raw))