mirror of
https://github.com/janet-lang/janet
synced 2024-12-27 17:00:27 +00:00
Quit trying to make it 3 different functions
Prior commits was an attempt to make this one function adhere to 3 different function signatures! This puts an end to that and makes it where it's a single function signature and if one wants to use the 4th argument they'll need to explicitly set the 3rd argument (to nil for default).
This commit is contained in:
parent
c9bef39f96
commit
7446802a70
@ -301,6 +301,7 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset, int sock
|
|||||||
/* when is_bind is set, we're performing a connect, but wanting to
|
/* when is_bind is set, we're performing a connect, but wanting to
|
||||||
* specify from where we connect, and in general don't care about a
|
* specify from where we connect, and in general don't care about a
|
||||||
* port */
|
* port */
|
||||||
|
/* TODO: remove check, argv[3] is where our bindhost is at! */
|
||||||
int32_t current_offset = 2;
|
int32_t current_offset = 2;
|
||||||
if (janet_checktype(argv[current_offset], JANET_KEYWORD)) {
|
if (janet_checktype(argv[current_offset], JANET_KEYWORD)) {
|
||||||
current_offset++;
|
current_offset++;
|
||||||
@ -382,29 +383,16 @@ JANET_CORE_FN(cfun_net_connect,
|
|||||||
"connection, with the default being the same as using the OS's preferred address. ") {
|
"connection, with the default being the same as using the OS's preferred address. ") {
|
||||||
janet_arity(argc, 2, 4);
|
janet_arity(argc, 2, 4);
|
||||||
|
|
||||||
int socktype = SOCK_STREAM;
|
int socktype = janet_get_sockettype(argv, argc, 2);
|
||||||
int strict = 0;
|
|
||||||
int is_unix = 0;
|
int is_unix = 0;
|
||||||
|
/* Where we're connecting to */
|
||||||
struct addrinfo *ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 0);
|
struct addrinfo *ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 0);
|
||||||
|
|
||||||
/* figure out socket type */
|
|
||||||
switch (argc) {
|
|
||||||
case 4:
|
|
||||||
strict = 1;
|
|
||||||
case 3:
|
|
||||||
if(janet_checktype(argv[2], JANET_KEYWORD) || strict)
|
|
||||||
socktype = janet_get_sockettype(argv, argc, 2);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
socktype = SOCK_STREAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if we're binding address */
|
/* Check if we're binding address */
|
||||||
struct addrinfo *binding = NULL;
|
struct addrinfo *binding = NULL;
|
||||||
if (argc >= 3 && is_unix == 0) {
|
if (argc > 3 && is_unix == 0 && !janet_checktype(argv[3], JANET_NIL)) {
|
||||||
if (argc == 4 || !janet_checktype(argv[2], JANET_KEYWORD)) {
|
int is_bindhost_unix = 0; /* discarded value */
|
||||||
binding = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 1);
|
binding = janet_get_addrinfo(argv, 0, socktype, 0, &is_bindhost_unix, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create socket */
|
/* Create socket */
|
||||||
@ -459,7 +447,7 @@ JANET_CORE_FN(cfun_net_connect,
|
|||||||
}
|
}
|
||||||
freeaddrinfo(binding);
|
freeaddrinfo(binding);
|
||||||
if (NULL == rp) {
|
if (NULL == rp) {
|
||||||
janet_panic("could not bind outgoing address");
|
janet_panicf("could not bind outgoing address: %V", janet_ev_lasterr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user