anchor.diff:  
   ;;;; Output Methods
   
  -(defun %write-n-bytes (write-fn fd buf nbytes &optional timeout)
  +(defun %write-octets-from-foreign-memory (write-fn fd buf nbytes)
     (declare (type stream-buffer buf))
     (let ((bytes-written 0))
       (labels ((write-once ()
  -               (let ((num (handler-case
  -                              (nix:repeat-upon-condition-decreasing-timeout
  -                                  ((nix:eintr) timeout-var timeout)
  -                                (prog1
  -                                    (funcall write-fn fd (inc-pointer buf bytes-written)
  -                                             nbytes)
  -                                  (when (and timeout-var (zerop timeout-var))
  -                                    (return* (values nil :timeout)))))
  -                            (nix:epipe ()
  -                              (return* (values nil :eof))))))
  -                 (unless (zerop num) (incf bytes-written num))))
  -             (write-or-return ()
  -               (unless (write-once)
  -                 (when (errorp)
  -                   ;; FIXME signal something better -- maybe analyze the status
  -                   (return* (values nil :fail)))))
  -             (buffer-emptyp () (= bytes-written nbytes))
  -             (errorp () (handler-case (iomux:wait-until-fd-ready fd :output)
  -                          (iomux:poll-error () t)
  -                          (:no-error (r w) (declare (ignore r w)) nil))))
  -      (loop :until (buffer-emptyp) :do (write-or-return)
  -         :finally (return (values t bytes-written))))))
  -
  -(defun %flush-obuf (write-fn fd buf &optional timeout)
  +               (let ((num
  +                      (handler-case
  +                          (funcall write-fn fd (inc-pointer buf bytes-written)
  +                                   (- nbytes bytes-written))
  +                        (nix:epipe ()
  +                          (return* (values bytes-written :hangup)))
  +                        (nix:ewouldblock ()
  +                          (iomux:wait-until-fd-ready fd :output)))))
  +                 (incf bytes-written num)))
  +             (buffer-emptyp () (= bytes-written nbytes)))
  +      (loop :until (buffer-emptyp) :do (write-once)
  +         :finally (return* bytes-written)))))
  +
  +(defun %write-octets-from-iobuf (write-fn fd buf)
     (declare (type iobuf buf))
  -  (let ((bytes-written 0))
  -    (labels ((write-once ()
  -               (let ((num (handler-case
  -                              (nix:repeat-upon-condition-decreasing-timeout
  -                                  ((nix:eintr) timeout-var timeout)
  -                                (prog1
  -                                    (funcall write-fn fd (iobuf-start-pointer buf)
  -                                             (iobuf-length buf))
  -                                  (when (and timeout-var (zerop timeout-var))
  -                                    (return* (values nil :timeout)))))
  -                            (nix:epipe ()
  -                              (return* (values nil :eof))))))
  -                 (unless (zerop num)
  -                   (incf (iobuf-start buf) num)
  -                   (incf bytes-written num))))
  -             (write-or-return ()
  -               (unless (write-once)
  -                 (when (errorp)
  -                   ;; FIXME signal something better -- maybe analyze the status
  -                   (return* (values nil :fail)))))
  -             (buffer-emptyp ()
  -               (when (iobuf-empty-p buf)
  -                 (iobuf-reset buf) t))
  -             (errorp () (handler-case (iomux:wait-until-fd-ready fd :output)
  -                          (iomux:poll-error () t)
  -                          (:no-error (r w) (declare (ignore r w)) nil))))
  -      (loop :until (buffer-emptyp) :do (write-or-return)
  -         :finally (return (values t bytes-written))))))
  -
  -;;; TODO: add timeout support
  -(defun %flush-obuf-if-needed (stream)
  +  (multiple-value-bind (bytes-written hangup-p)
  +      (%write-octets-from-foreign-memory
  +       write-fn fd (iobuf-start-pointer buf) (iobuf-length buf))
  +    (incf (iobuf-start buf) bytes-written)
  +    (when (iobuf-empty-p buf) (iobuf-reset buf))
  +    (values bytes-written hangup-p)))
  +
  +(defun flush-obuf-if-needed (stream)
     (declare (type dual-channel-gray-stream stream))
     (with-accessors ((fd output-fd-of)
                      (write-fn write-fn-of)
  
positive.code:                    (dirtyp dirtyp))
        stream
      (when (or dirtyp (iobuf-full-p ob))
        (%flush-obuf write-fn fd ob)
        (setf dirtyp nil))))
  
  (defmethod stream-clear-output ((stream dual-channel-gray-stream))
  
negative.code:   (check-type integer ub8 "an unsigned 8-bit value")
    (with-accessors ((ob output-buffer-of))
        stream
      (flush-obuf-if-needed stream)
      (iobuf-push-octet ob integer)))
  
  ;;;; Buffer-related stuff
  