anchor.diff:    (make-octet-vector 12))
   
   (defun ach-stream-read (stream &optional buffer)
  -  "read a frame from the stream"
  +  "read a frame from the stream or return nil if closed"
     (declare (type (or null octet-vector) buffer))
  -  (let ((size-buf (make-size-buf)))
  -    (read-sequence size-buf stream)
  -    (assert (= *size-delim*
  -               (decode-uint size-buf :little 0)) ()
  -               "Invalid size delimiter: ~A, ~&buffer: ~A~&msg: ~A"
  -               (subseq size-buf 0 4) size-buf
  -               (map 'string #'code-char size-buf))
  -    (assert (= *data-delim*
  -               (decode-uint size-buf :little 8)) ()
  -               "Invalid data delimiter: ~A, ~&buffer: ~A~&msg: ~A"
  -               (subseq size-buf 8) size-buf
  -               (map 'string #'code-char size-buf))
  -    (let* ((size (decode-uint size-buf :big 4))
  -           (buffer (if (= size (length buffer)) buffer
  -                       (make-octet-vector size))))
  -      (read-sequence buffer stream)
  -      buffer)))
  +  (let* ((size-buf (make-size-buf))
  +         (n-read (read-sequence size-buf stream)))
  +    (unless (zerop n-read)
  +      (assert (= *size-delim*
  +                 (decode-uint size-buf :little 0)) ()
  +                 "Invalid size delimiter: ~A, ~&buffer: ~A~&msg: ~A"
  +                 (subseq size-buf 0 4) size-buf
  +                 (map 'string #'code-char size-buf))
  +      (assert (= *data-delim*
  +                 (decode-uint size-buf :little 8)) ()
  +                 "Invalid data delimiter: ~A, ~&buffer: ~A~&msg: ~A"
  +                 (subseq size-buf 8) size-buf
  +                 (map 'string #'code-char size-buf))
  +      (let* ((size (decode-uint size-buf :big 4))
  +             (buffer (if (= size (length buffer)) buffer
  +                         (make-octet-vector size))))
  +        (read-sequence buffer stream)
  +      buffer))))
   
   
   (defun ach-stream-write (stream buffer)
  
positive.code: (defstruct channel
    mode
    synchronous
    transport)
  
  (defun channel-input (channel)
    (socket-stream (channel-transport channel)))
  
negative.code: (defpackage :ach
    (:use :cl :binio :usocket)
    (:export :ach-connect :ach-close :ach-read :ach-write
             :ach-next :ach-last :ach-put :ach-map
             :make-listener :make-ach-syncpipe))
  
  (in-package :ach)
  