use ffi/unsafe/atomic
This commit is contained in:
parent
85fba029a5
commit
b377976ba5
|
@ -233,8 +233,6 @@
|
||||||
(define NID_commonName 13)
|
(define NID_commonName 13)
|
||||||
(define GEN_DNS 2)
|
(define GEN_DNS 2)
|
||||||
|
|
||||||
(define-mzscheme scheme_start_atomic (_fun -> _void))
|
|
||||||
(define-mzscheme scheme_end_atomic (_fun -> _void))
|
|
||||||
(define-mzscheme scheme_make_custodian (_fun _pointer -> _scheme))
|
(define-mzscheme scheme_make_custodian (_fun _pointer -> _scheme))
|
||||||
|
|
||||||
;; Make this bigger than 4096 to accommodate at least
|
;; Make this bigger than 4096 to accommodate at least
|
||||||
|
@ -289,9 +287,7 @@
|
||||||
(define (check-valid v who what)
|
(define (check-valid v who what)
|
||||||
(when (ptr-equal? v #f)
|
(when (ptr-equal? v #f)
|
||||||
(let ([id (ERR_get_error)])
|
(let ([id (ERR_get_error)])
|
||||||
(escape-atomic
|
(error who "~a failed ~a" what (get-error-message id)))))
|
||||||
(lambda ()
|
|
||||||
(error who "~a failed ~a" what (get-error-message id)))))))
|
|
||||||
|
|
||||||
(define (error/network who fmt . args)
|
(define (error/network who fmt . args)
|
||||||
(raise (make-exn:fail:network
|
(raise (make-exn:fail:network
|
||||||
|
@ -301,36 +297,8 @@
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Atomic blocks
|
;; Atomic blocks
|
||||||
|
|
||||||
;; Obviously, be careful in an atomic block. In particular,
|
(define-syntax-rule (atomically body ...)
|
||||||
;; DO NOT CONSTRUCT AN ERROR DIRECTLY IN AN ATOMIC BLOCK,
|
(call-as-atomic (lambda () body ...)))
|
||||||
;; because the error message almost certainly involves things
|
|
||||||
;; like a ~a or ~e format, which can trigger all sorts of
|
|
||||||
;; printing extensions. Instead, send a thunk that
|
|
||||||
;; constructs and raises the exception to `escape-atomic'.
|
|
||||||
|
|
||||||
(define in-atomic? (make-parameter #f))
|
|
||||||
(define-struct (exn:atomic exn) (thunk))
|
|
||||||
|
|
||||||
(define-syntax atomically
|
|
||||||
(syntax-rules ()
|
|
||||||
[(_ body ...)
|
|
||||||
(parameterize-break
|
|
||||||
#f
|
|
||||||
(with-handlers ([exn:atomic? (lambda (exn)
|
|
||||||
((exn:atomic-thunk exn)))])
|
|
||||||
(parameterize ([in-atomic? #t])
|
|
||||||
(dynamic-wind
|
|
||||||
(lambda () (scheme_start_atomic))
|
|
||||||
(lambda () body ...)
|
|
||||||
(lambda () (scheme_end_atomic))))))]))
|
|
||||||
|
|
||||||
(define (escape-atomic thunk)
|
|
||||||
(if (in-atomic?)
|
|
||||||
(raise (make-exn:atomic
|
|
||||||
"error during atomic..."
|
|
||||||
(current-continuation-marks)
|
|
||||||
thunk))
|
|
||||||
(thunk)))
|
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Structs
|
;; Structs
|
||||||
|
@ -411,12 +379,10 @@
|
||||||
[(tls) (if client?
|
[(tls) (if client?
|
||||||
TLSv1_client_method
|
TLSv1_client_method
|
||||||
TLSv1_server_method)]
|
TLSv1_server_method)]
|
||||||
[else (escape-atomic
|
[else
|
||||||
(lambda ()
|
(raise-argument-error who
|
||||||
(raise-argument-error
|
(format "(or/c ~a'sslv2-or-v3 'sslv2 'sslv3 'tls)" also-expect)
|
||||||
who
|
e)])))
|
||||||
(format "(or/c ~a'sslv2-or-v3 'sslv2 'sslv3 'tls)" also-expect)
|
|
||||||
e)))])))
|
|
||||||
|
|
||||||
(define (make-context who protocol-symbol also-expected client?)
|
(define (make-context who protocol-symbol also-expected client?)
|
||||||
(let ([meth (encrypt->method who also-expected protocol-symbol client?)])
|
(let ([meth (encrypt->method who also-expected protocol-symbol client?)])
|
||||||
|
@ -1107,10 +1073,8 @@
|
||||||
[(connect) #t]
|
[(connect) #t]
|
||||||
[(accept) #f]
|
[(accept) #f]
|
||||||
[else
|
[else
|
||||||
(escape-atomic
|
(raise-argument-error who "(or/c 'connect 'accept)"
|
||||||
(lambda ()
|
connect/accept)])]
|
||||||
(raise-argument-error who "(or/c 'connect 'accept)"
|
|
||||||
connect/accept)))])]
|
|
||||||
[r-bio (BIO_new (BIO_s_mem))]
|
[r-bio (BIO_new (BIO_s_mem))]
|
||||||
[w-bio (BIO_new (BIO_s_mem))]
|
[w-bio (BIO_new (BIO_s_mem))]
|
||||||
[free-bio? #t])
|
[free-bio? #t])
|
||||||
|
@ -1122,13 +1086,11 @@
|
||||||
(if connect?
|
(if connect?
|
||||||
(ssl-client-context? context-or-encrypt-method)
|
(ssl-client-context? context-or-encrypt-method)
|
||||||
(ssl-server-context? context-or-encrypt-method)))
|
(ssl-server-context? context-or-encrypt-method)))
|
||||||
(escape-atomic
|
(error who
|
||||||
(lambda ()
|
"'~a mode requires a ~a context, given: ~e"
|
||||||
(error who
|
(if connect? 'connect 'accept)
|
||||||
"'~a mode requires a ~a context, given: ~e"
|
(if connect? "client" "server")
|
||||||
(if connect? 'connect 'accept)
|
context-or-encrypt-method))
|
||||||
(if connect? "client" "server")
|
|
||||||
context-or-encrypt-method))))
|
|
||||||
(let ([ssl (SSL_new ctx)]
|
(let ([ssl (SSL_new ctx)]
|
||||||
[cancel (box #t)])
|
[cancel (box #t)])
|
||||||
(check-valid ssl who "ssl setup")
|
(check-valid ssl who "ssl setup")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user