def _send_bytes(self, data):
        """Send some data via non-blocking IO

        Note: this method is not synchronized internally; you should
        always hold the _lock before calling

        Returns: number of bytes
        Raises: socket exception
        """
        total_sent = 0
        while total_sent < len(data):
            try:
                sent_bytes = self._sock.send(data[total_sent:])
                total_sent += sent_bytes
            except (SSLWantReadError, SSLWantWriteError):
                break
            except (ConnectionError, TimeoutError) as e:
                if six.PY2 and e.errno == errno.EWOULDBLOCK:
                    break
                raise
            except BlockingIOError:
                if six.PY3:
                    break
                raise
        return total_sent
Send some data via non-blocking IO

        Note: this method is not synchronized internally; you should
        always hold the _lock before calling

        Returns: number of bytes
        Raises: socket exception
        
kafka/conn.py