Implementation of the send thread.  Waits for data to be added
        to the send buffer, then passes as much of the buffered data
        to the socket ``send()`` method as possible.

def _send(self):
        """
        Implementation of the send thread.  Waits for data to be added
        to the send buffer, then passes as much of the buffered data
        to the socket ``send()`` method as possible.
        """

        # Outer loop: wait for data to send
        while True:
            # Release the send lock and wait for data, then reacquire
            # the send lock
            self._send_lock.release()
            self._sendbuf_event.wait()
            self._send_lock.acquire()

            # Inner loop: send as much data as we can
            while self._sendbuf:
                sent = self._sock.send(self._sendbuf)

                # Trim that much data off the send buffer, so we don't
                # accidentally re-send anything
                self._sendbuf = self._sendbuf[sent:]

            # OK, _sendbuf is empty; clear the event so we'll sleep
            self._sendbuf_event.clear()