def METHOD_NAME(sock, data):
    if isinstance(data, six.text_type):
        data = data.encode('utf-8')
    if not sock:
        raise WebSocketConnectionClosedException("socket is already closed.")
    def _send():
        try:
            return sock.METHOD_NAME(data)
        except SSLWantWriteError:
            pass
        except socket.error as exc:
            error_code = extract_error_code(exc)
            if error_code is None:
                raise
            if error_code != errno.EAGAIN or error_code != errno.EWOULDBLOCK:
                raise
        r, w, e = select.select((), (sock, ), (), sock.gettimeout())
        if w:
            return sock.METHOD_NAME(data)
    try:
        if sock.gettimeout() == 0:
            return sock.METHOD_NAME(data)
        else:
            return _send()
    except socket.timeout as e:
        message = extract_err_message(e)
        raise WebSocketTimeoutException(message)
    except Exception as e:
        message = extract_err_message(e)
        if isinstance(message, str) and "timed out" in message:
            raise WebSocketTimeoutException(message)
        else:
            raise