anchor.diff:              :type tcp-sequence-number)
      (%window-size :accessor tcp-connection-window-size :initarg :window-size)
      (%max-seg-size :accessor tcp-connection-max-seg-size :initarg :max-seg-size)
  -   (%rx-data :accessor tcp-connection-rx-data :initarg :rx-data)
  -   (%rx-data-unordered :reader tcp-connection-rx-data-unordered :initarg :rx-data-unordered)
  -   (%lock :reader tcp-connection-lock :initarg :lock)
  -   (%cvar :reader tcp-connection-cvar :initarg :cvar)
  +   (%rx-data :accessor tcp-connection-rx-data :initform '())
  +   (%rx-data-unordered :reader tcp-connection-rx-data-unordered :initform (make-hash-table))
  +   (%lock :reader tcp-connection-lock
  +          :initform (mezzano.supervisor:make-mutex "TCP connection lock"))
  +   (%cvar :reader tcp-connection-cvar
  +          :initform (mezzano.supervisor:make-condition-variable "TCP connection cvar"))
      (%receive-event :reader tcp-connection-receive-event
  -                   :initform (mezzano.supervisor:make-event :name "TCP connection data available")))
  +                   :initform (mezzano.supervisor:make-event :name "TCP connection data available"))
  +   (%pending-error :accessor tcp-connection-pending-error :initform nil)
  +   (%retransmit-timer :reader tcp-connection-retransmit-timer
  +                      :initform (mezzano.supervisor:make-timer :name "TCP connection retransmit"))
  +   (%retransmit-source :reader tcp-connection-retransmit-source)
  +   (%timeout-timer :reader tcp-connection-timeout-timer
  +                   :initform (mezzano.supervisor:make-timer :name "TCP connection timeout"))
  +   (%timeout-source :reader tcp-connection-timeout-source))
     (:default-initargs
  -   :max-seg-size 1000
  -   :rx-data '()
  -   :rx-data-unordered (make-hash-table)
  -   :lock (mezzano.supervisor:make-mutex "TCP connection lock")
  -   :cvar (mezzano.supervisor:make-condition-variable "TCP connection cvar")))
  +   :max-seg-size 1000))
  +
  +(defun arm-retransmit-timer (seconds connection)
  +  (mezzano.supervisor:timer-arm seconds
  +                                (tcp-connection-retransmit-timer connection))
  +  (values))
  +
  +(defun disarm-retransmit-timer (connection)
  +  (mezzano.supervisor:timer-disarm (tcp-connection-retransmit-timer connection))
  +  (values))
  +
  +(defun retransmit-timer-handler (connection)
  +  (when (not (mezzano.supervisor:timer-expired-p
  +              (tcp-connection-retransmit-timer connection)))
  +    ;; Timer is either still pending or isn't actually running.
  +    ;; This can happen if the timer expires but some other task reconfigures
  +    ;; a new retransmit time.
  +    (return-from retransmit-timer-handler))
  +  ;; Disarm it so it stops triggering the source
  +  (mezzano.supervisor:timer-disarm (tcp-connection-retransmit-timer connection))
  +  ;; What're we retransmitting?
  +  (format t "Doing retransmit on connection ~S~%" connection)
  +  (ecase (tcp-connection-state connection)
  +    (:syn-sent
  +     (let ((seq (logand #xFFFFFFFF (1- (tcp-connection-s-next connection)))))
  +       (tcp4-send-packet connection seq 0 nil :ack-p nil :syn-p t)
  +       (arm-retransmit-timer 1 connection)))))
  +
  +(defun arm-timeout-timer (seconds connection)
  +  (mezzano.supervisor:timer-arm seconds
  +                                (tcp-connection-timeout-timer connection))
  +  (values))
  +
  +(defun disarm-timeout-timer (connection)
  +  (mezzano.supervisor:timer-disarm (tcp-connection-timeout-timer connection))
  +  (values))
  +
  +(defun timeout-timer-handler (connection)
  +  (when (not (mezzano.supervisor:timer-expired-p
  +              (tcp-connection-timeout-timer connection)))
  +    ;; Timer is either still pending or isn't actually running.
  +    ;; This can happen if the timer expires but some other task reconfigures
  +    ;; a new timeout time.
  +    (return-from timeout-timer-handler))
  +  ;; Disarm it so it stops triggering the source
  +  (mezzano.supervisor:timer-disarm (tcp-connection-timeout-timer connection))
  +  (mezzano.supervisor:with-mutex ((tcp-connection-lock connection))
  +    (setf (tcp-connection-pending-error connection)
  +          (make-condition 'connection-timed-out
  +                          :host (tcp-connection-remote-ip connection)
  +                          :port (tcp-connection-remote-port connection)))
  +    (setf (tcp-connection-state connection) :closed)
  +    (mezzano.supervisor:condition-notify (tcp-connection-cvar connection) t)
  +    (detach-tcp-connection connection)))
  +
  +(defmethod initialize-instance :after ((instance tcp-connection) &key)
  +  (setf (slot-value instance '%retransmit-source)
  +        (mezzano.sync.dispatch:make-source (tcp-connection-retransmit-timer instance)
  +                                           (lambda ()
  +                                             (retransmit-timer-handler instance))
  +                                           :target sys.net::*network-serial-queue*))
  +  (setf (slot-value instance '%timeout-source)
  +        (mezzano.sync.dispatch:make-source (tcp-connection-timeout-timer instance)
  +                                           (lambda ()
  +                                             (timeout-timer-handler instance))
  +                                           :target sys.net::*network-serial-queue*)))
   
   (defmethod print-object ((instance tcp-connection) stream)
     (print-unreadable-object (instance stream :type t :identity t)
  
positive.code:                            nil
                             :ack-p t))))
  
  (defun tcp4-receive (connection packet &optional (start 0) end listener)
    (unless end (setf end (length packet)))
    (with-tcp-connection-locked connection
      (let* ((seq (ub32ref/be packet (+ start +tcp4-header-sequence-number+)))
             (ack (ub32ref/be packet (+ start +tcp4-header-acknowledgment-number+)))
             (flags-and-data-offset (ub16ref/be packet (+ start +tcp4-header-flags-and-data-offset+)))
  
negative.code:                     (tcp-connection-r-next connection)
                      nil
                      :rst-p t)
    (mezzano.sync.dispatch:dispatch-async
     (lambda ()
       (detach-tcp-connection connection))
     sys.net::*network-serial-queue*))
  
  (defun close-tcp-connection (connection)
    (ecase (tcp-connection-state connection)
  