def _write_on_socket(conn, data):
    """Write a chunk of data on a connection"""
    remaining = len(data)
    while remaining > 0:
        try:
            sent = conn.send(data[len(data) - remaining:])
        except InterruptedError:
            continue
        if sent == 0:
            raise EOFError('Broken socket!')
        remaining -= sent
