From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id B04A5809EA; Sun, 21 Aug 2022 11:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661081133; bh=CKawNDAbrj8nQnaxSMTYRvMoJMT2x6SdGIWQZsk86vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ioz0k1GPYiVyWYsG/WpnzYNlLzs8cN185VIQZUYLJNZIf6/HQf8wR409pjexHK/K3 xQWgzfk5MwsFVn/ZiQMp9kYE7AYlxwkLmL5pONRUqujV2GhCMZMf7kXNj7Hje91Jcf AB6Wc2GBPWr8Oqrbz885xDxbNVUOBhLf1kb/8EEZIXa7Rbp9OwG+O6w/XYfRWa8RnL p9P5AfW36c80tBc4W9f3r9x6/kEGDHPfPUlAmyXApUSvgKCo86GkJAxLQpChO04Rh5 WzZVzeC7Hcc1ebOICbGa+74uOIjp/NoNTf4vhKEOoFPb53FLPoWRvXLgXdfadxZOOQ QAIr8Pt4evIqA== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , GNU/Weeb Mailing List Subject: [PATCH v1 07/22] chnet: node: Add get_error function to return the error string Date: Sun, 21 Aug 2022 18:24:38 +0700 Message-Id: <20220821112453.3026255-8-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> References: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is very useful to get the reason of the error as a string. Signed-off-by: Ammar Faizi --- chnet/chnet_node.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/chnet/chnet_node.cc b/chnet/chnet_node.cc index fdac525..4a60b0e 100644 --- a/chnet/chnet_node.cc +++ b/chnet/chnet_node.cc @@ -374,6 +374,20 @@ static Napi::Number CHN_NetReadRet(const Napi::CallbackInfo &info) return Napi::Number::New(env, ch->ch_.read_ret()); } +static Napi::Value CHN_NetGetError(const Napi::CallbackInfo &info) +{ + Napi::Env env = info.Env(); + const char *err; + NodeCHNet *ch; + + ch = (NodeCHNet *)info.Data(); + err = ch->ch_.GetErrorStr(); + if (err) + return Napi::String::New(env, err); + + return env.Null(); +} + static void CHN_NetDestruct(Napi::Env env, NodeCHNet *ch) { delete ch; @@ -391,6 +405,7 @@ static Napi::Object CHN_CreateNet(const Napi::CallbackInfo &info) obj_add_func(env, obj, ch, CHN_NetSetMethod, "set_method"); obj_add_func(env, obj, ch, CHN_NetReadRet, "read_ret"); obj_add_func(env, obj, ch, CHN_NetReadBuf, "read_buf"); + obj_add_func(env, obj, ch, CHN_NetGetError, "get_error"); ch_ptr = (int64_t) (intptr_t) ch; obj["__ch"] = Napi::Number::New(env, ch_ptr); -- Ammar Faizi