Hi,
> IIRC we were waiting for andyjpb and company to fix the breakage introduced
> by the buffering patch so we could pull in current upstream and then push
> the patches or something ...
Please find attached a patch to v1.6.4 of the openssl egg.
This patch:
+ Ensures that startup is called once, with the correct
"called-from-close" flag in each of the write, close and flush
procedures. I think "flush" is always called when the port is
supposed to be open.
+ Introduces a dependency on srfi-13 for the string-copy! and
substring/shared procedures. This is so that we can do buffer
management with the minimal of excess copying and garbage
collection.
+ Reworks the buffered write logic to ensure that we always flush the
buffer in full chunks apart from during the close and flush
procedures where we just write whatever is left.
I've done a minimal amount of testing and it seems to work. It seems to
produce files with the same md5sum as the version without the patch so I
don't think it corrupts the data. i.e. I think the buffer handling is
correct.
On my local machine I can't measure a speedup when downloading a static,
178MiB file or a 3.9MiB file generated with SXML / waffle, both via spiffy..
Regards,
@ndy
--
[email protected]
http://www.ashurst.eu.org/
0x7EBA75FF
diff -upr v1.6.4/openssl.import.scm v1.6.4-andyjpb-fix/openssl.import.scm
--- v1.6.4/openssl.import.scm 2014-11-23 02:37:31.235897645 +0000
+++ v1.6.4-andyjpb-fix/openssl.import.scm 2014-11-23 02:13:16.085352751 +0000
@@ -1,6 +1,6 @@
;;;; openssl.import.scm - GENERATED BY CHICKEN 4.9.0rc1 -*- Scheme -*-
-(eval '(import scheme chicken foreign ports srfi-18 tcp))
+(eval '(import scheme chicken foreign ports srfi-13 srfi-18 tcp))
(##sys#register-compiled-module
'openssl
(list)
Binary files v1.6.4/openssl.import.so and v1.6.4-andyjpb-fix/openssl.import.so differ
diff -upr v1.6.4/openssl.scm v1.6.4-andyjpb-fix/openssl.scm
--- v1.6.4/openssl.scm 2014-11-23 00:07:52.324097414 +0000
+++ v1.6.4-andyjpb-fix/openssl.scm 2014-11-23 02:31:54.004264327 +0000
@@ -45,7 +45,7 @@
##sys#check-string
##sys#expand-home-path))
-(use srfi-18 tcp)
+(use srfi-13 srfi-18 tcp)
#>
#include <errno.h>
@@ -442,11 +442,11 @@ EOF
"SSL read timed out")))
buffer))))
(out
- (let* ((outbufsize (tcp-buffer-size))
- (outbuf (and outbufsize (fx> outbufsize 0) ""))
- (output
+ (let* ((outbufmax (tcp-buffer-size))
+ (outbuf (and outbufmax (fx> outbufmax 0) (make-string outbufmax)))
+ (outbufsize 0)
+ (unbuffered-write
(lambda (buffer)
- (startup)
(when (> (##sys#size buffer) 0) ; Undefined behaviour for 0 bytes!
(let loop ((offset 0) (size (##sys#size buffer)))
(let ((ret (ssl-call/timeout
@@ -455,30 +455,45 @@ EOF
fd (tcp-write-timeout) "SSL write timed out")))
(when (fx< ret size) ; Partial write
(loop (fx+ offset ret) (fx- size ret)))))))))
+
+ (define (buffered-write data #!optional (start 0))
+ (let* ((size (- (##sys#size data) start))
+ (to-copy (min (- outbufmax outbufsize) size))
+ (left-over (- size to-copy)))
+
+ (string-copy! outbuf outbufsize data start (+ start to-copy))
+ (set! outbufsize (+ outbufsize to-copy))
+
+ (if (= outbufsize outbufmax)
+ (begin
+ (unbuffered-write outbuf)
+ (set! outbufsize 0)))
+
+ (if (> left-over 0)
+ (buffered-write data (+ start to-copy)))))
+
(make-output-port
;; write
(lambda (buffer)
+ (startup)
(if outbuf
- (begin
- (set! outbuf (string-append outbuf buffer))
- (when (fx>= (string-length outbuf) outbufsize)
- (output outbuf)
- (set! outbuf "")))
- (output buffer)))
+ (buffered-write buffer)
+ (unbuffered-write buffer)))
;; close
(lambda ()
(when (startup #t)
(if outbuf
- (begin
- (output outbuf)
- (set! outbuf "")))
+ (begin
+ (unbuffered-write (substring/shared outbuf 0 outbufsize))
+ (set! outbufsize 0)))
(set! out-open? #f)
(shutdown)))
;; flush
(lambda ()
(when outbuf
- (output outbuf)
- (set! outbuf "")))))))
+ (startup)
+ (unbuffered-write (substring/shared outbuf 0 outbufsize))
+ (set! outbufsize 0)))))))
(##sys#setslot in 3 "(ssl)")
(##sys#setslot out 3 "(ssl)")
;; first "reserved" slot
Only in v1.6.4-andyjpb-fix/: openssl.scm~
Only in v1.6.4-andyjpb-fix/: .openssl.scm.swp
Binary files v1.6.4/openssl.so and v1.6.4-andyjpb-fix/openssl.so differ
Binary files v1.6.4/openssl-static.o and v1.6.4-andyjpb-fix/openssl-static.o differ
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users