anchor.diff:    remote-name
     remote-port
     (read-buffer (make-array buffer-size :element-type '(unsigned-byte 8)))
  -  (write-buffer (make-array buffer-size :element-type '(unsigned-byte 8))))
  +  (write-queue (make-queue))
  +  write-buffer
  +  write-buffer-offset)
   
   (defclass tcp-server ()
     ((driver :initarg :driver)))
  
positive.code: (defevent on-client-error (driver client error))
  (defevent on-drain (driver client))
  
  (defparameter *max-buffer-size* 16384)
  (defstruct (tcp-client
               (:constructor make-client (socket remote-name remote-port
  
negative.code:   (declare (ignore driver))
    (iolib:remove-fd-handlers event-base (iolib:socket-os-fd (tcp-client-socket client)) :read t))
  
  (defun start-writes (driver event-base client)
    (iolib:set-io-handler
     event-base (iolib:socket-os-fd (tcp-client-socket client))
     :write
     (lambda (&rest ig)
       (declare (ignore ig))
       (loop
          (unless (tcp-client-write-buffer client)
            (setf (tcp-client-write-buffer client) (dequeue (tcp-client-write-queue client))
                  (tcp-client-write-buffer-offset client) 0))
          (when (tcp-client-write-buffer client)
            (handler-case
                (let ((bytes-written (iolib:send-to (tcp-client-socket client)
                                                    (tcp-client-write-buffer client)
                                                    :start (tcp-client-write-buffer-offset client))))
  
                  (when (>= (incf (tcp-client-write-buffer-offset client) bytes-written)
                            (length (tcp-client-write-buffer client)))
                    (setf (tcp-client-write-buffer client) nil)
                    (when (queue-empty-p (tcp-client-write-queue client))
                      (on-drain driver client))))
              ((or iolib:socket-connection-reset-error isys:ewouldblock isys:epipe) (e)
                (on-client-error driver client e))))
          (when (queue-empty-p (tcp-client-write-queue client))
            (return))))))
  
  (defun write-to-client (client data)
    (enqueue data (tcp-client-write-queue client)))
  
  ;; TCP server test
  (defclass echo () ())
  (defmethod on-connect ((driver echo) client)
    (format t "~&Client connected.")
    (write-to-client client (flex:string-to-octets (format nil "~&Welcome. Everything you say will be echoed back to you now.~%"))))
  (defmethod on-data ((driver echo) client data)
    (format t "~&Data length: ~S~%" (length data))
    (write-to-client client data))
  (defmethod on-disconnect ((driver echo) client)
    (format t "~&Client disconnected: ~S~%" client))
  #+nil(start-listener (make-tcp-server (make-instance 'echo)) :host "127.0.0.1" :port 1337 :external-format :utf8)
  