websocket: Support for sending fragmented frames.
[8sync.git] / 8sync / systems / websocket / frame.scm
index 7a71dba9ff56483b44c222edef00b58e4d439280..35dc5511aec13da172bdb637be1337b6f466b20b 100644 (file)
@@ -1,5 +1,6 @@
 ;;; guile-websocket --- WebSocket client/server
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
+;;; Copyright © 2019 Rutger van Beusekom <rutger.van.beusekom@gmail.com>
 ;;;
 ;;; This file is part of guile-websocket.
 ;;;
@@ -105,16 +106,16 @@ bytevector BV, masked with MASKING-KEY.  By default, the data is
 unmasked."
   (make-frame #t 'close masking-key bv))
 
-(define* (make-text-frame text #:optional masking-key)
+(define* (make-text-frame text #:optional masking-key #:key (final? #t) (continuation? #f)) ;; bah: optional
   "Return a text data frame containing the string TEXT, masked with MASKING-KEY.
 By default, the text is unmasked."
-  (make-frame #t 'text masking-key (string->utf8 text)))
+  (make-frame final? (if continuation? 'continuation 'text) masking-key (string->utf8 text)))
 
-(define* (make-binary-frame bv #:optional masking-key)
+(define* (make-binary-frame bv #:optional masking-key #:key (final? #t) (continuation? #f))
   "Return a binary data frame containing the contents of the
 bytevector BV, masked with MASKING-KEY.  By default, the data is
 unmasked."
-  (make-frame #t 'binary masking-key bv))
+  (make-frame final? (if continuation? 'continuation 'binary) masking-key bv))
 
 (define (continuation-frame? frame)
   "Return #t if FRAME is a continuation frame."
@@ -309,7 +310,8 @@ MASKING-KEY."
 
     (let ((bv (get-bytevector-n port length)))
       (when masking-key
-        (mask-bytevector! bv masking-key))
+        (unless (eof-object? bv)
+          (mask-bytevector! bv masking-key)))
       bv))
 
   (let* ((type-byte (get-u8 port))