anchor.diff:    character)
   
   (defmethod close ((stream tcp-stream) &key abort)
  -  (let* ((connection (tcp-stream-connection stream)))
  -    (setf (tcp-connection-state connection) :closing)
  -    (tcp4-send-packet connection
  -                      (tcp-connection-s-next connection)
  -                      (tcp-connection-r-next connection)
  -                      nil
  -                      :fin-p t)))
  +  (close-tcp-connection (tcp-stream-connection stream)))
   
   (defun tcp-stream-connect (address port)
     (make-instance 'tcp-stream :connection (tcp-connect (sys.net::resolve-address address) port)))
  
positive.code:            (data-length (- end (+ start header-length))))
        (case (tcp-connection-state connection)
          (:syn-sent
           (if (and (logtest flags +tcp4-flag-ack+)
                    (logtest flags +tcp4-flag-syn+)
                    (eql ack (tcp-connection-s-next connection)))
               (progn
                 (setf (tcp-connection-state connection) :established
                       (tcp-connection-r-next connection) (logand (1+ seq) #xFFFFFFFF))
                 (tcp4-send-packet connection ack (tcp-connection-r-next connection) nil))
               (progn
                 (setf (tcp-connection-state connection) :closed)
                 (detach-tcp-connection connection)
                 (tcp4-send-packet connection 0 0 nil :ack-p nil :rst-p t)
                 (format t "TCP: got ack ~S, wanted ~S. Flags ~B~%" ack (tcp-connection-s-next connection) flags))))
          (:syn-received
           (cond ((and (eql flags +tcp4-flag-ack+)
                       (eql seq (tcp-connection-r-next connection))
                       (eql ack (tcp-connection-s-next connection)))
                  (setf (tcp-connection-state connection) :established))
                 (t (setf (tcp-connection-state connection) :closed)
                    (detach-tcp-connection connection)
                    (tcp4-send-packet connection 0 0 nil :ack-p nil :rst-p t)
                    (format t "TCP: Aborting connect. Got ack ~S, wanted ~S. Got seq ~S, wanted ~S. Flags ~B~%"
                            ack (tcp-connection-s-next connection)
                            seq (tcp-connection-r-next connection)
                            flags))))
          (:established
           ;; Ignore out-of-order packets.
           (when (not (eql seq (tcp-connection-r-next connection)))
             (format t "TCP: Ignoring packet with sequence number ~D, wanted ~D.~%"
                     seq (tcp-connection-r-next connection)))
           (when (eql seq (tcp-connection-r-next connection))
             (unless (eql data-length 0)
               ;; Send data to the user layer
               (if (tcp-connection-rx-data connection)
                   (setf (cdr (last (tcp-connection-rx-data connection))) (list (list packet (+ start header-length) end)))
                   (setf (tcp-connection-rx-data connection) (list (list packet (+ start header-length) end))))
               (setf (tcp-connection-r-next connection)
                     (logand (+ (tcp-connection-r-next connection) data-length)
                             #xFFFFFFFF)))
             (cond
               ((logtest flags +tcp4-flag-fin+)
                ;; Always ack FIN packets.
                (setf (tcp-connection-state connection) :closing
                      (tcp-connection-r-next connection)
                      (logand (+ (tcp-connection-r-next connection) 1)
                              #xFFFFFFFF))
                (tcp4-send-packet connection
                                  (tcp-connection-s-next connection)
                                  (tcp-connection-r-next connection)
                                  nil
                                  :fin-p t))
               ((not (eql data-length 0))
                (tcp4-send-packet connection
                                  (tcp-connection-s-next connection)
                                  (tcp-connection-r-next connection)
                                  nil)))))
          (:closing
           (cond ((logtest flags +tcp4-flag-ack+))
                 ((logtest flags +tcp4-flag-fin+)
                  (tcp4-send-packet connection
                                    (tcp-connection-s-next connection)
                                    (tcp-connection-r-next connection)
                                    nil
                                    :ack-p t
                                    :fin-p t)))
           (detach-tcp-connection connection)
           (setf (tcp-connection-state connection) :closed))
          (:closed
           (detach-tcp-connection connection))
          (t (tcp4-send-packet connection 0 0 nil :ack-p nil :rst-p t)
             (format t "TCP: Unknown connection state ~S ~S ~S.~%" (tcp-connection-state connection) start packet)
             (detach-tcp-connection connection)
             (setf (tcp-connection-state connection) :closed))))
      (mezzano.supervisor:condition-notify (tcp-connection-cvar connection) t)))
  
negative.code:          (when (not (eql (tcp-connection-state connection) :syn-sent))
             (return))
           (when (> (get-universal-time) timeout)
             (close-tcp-connection connection)
             (error "Connection timed out."))
           (mezzano.supervisor:wait-for-heartbeat)))
      connection))
  