From 532dac1b951be95342acd1a3c1dfed5c45a156f5 Mon Sep 17 00:00:00 2001 From: llmII Date: Mon, 6 Sep 2021 09:45:58 -0500 Subject: [PATCH] Check type instead of value Primarily because trying to check the value results in a panic when the value is not the type of value requested from the API. Also probably cheaper and the previous idea of just getting the value then comparing was pretty stupid (needed a string comparison... and was going to do pointer comparison). --- src/core/net.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/core/net.c b/src/core/net.c index e1748c24..edfbc023 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -302,8 +302,7 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset, int sock * specify from where we connect, and in general don't care about a * port */ int32_t current_offset = 3; - if (janet_keyeq(argv[current_offset], "stream") || - janet_keyeq(argv[current_offset], "datagram")) { + if (janet_checktype(argv[3], JANET_KEYWORD)) { current_offset = 4; } host = (char *)janet_getcstring(argv, current_offset); @@ -419,12 +418,9 @@ JANET_CORE_FN(cfun_net_connect, } } - /* TODO: check if need bind and bind! */ ai = NULL; if (argc >= 3 && is_unix == 0) { - if (argc == 4 || - (!janet_keyeq(argv[3], "stream") && - !janet_keyeq(argv[3], "datagram"))) { + if (argc == 4 || !janet_checktype(argv[3], JANET_KEYWORD)) { ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 1); } }