diff options
author | Jo-Philipp Wich <jo@mein.io> | 2024-05-17 15:01:27 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2024-05-17 15:49:04 +0200 |
commit | 7b269f1cd3d2b8fb84f1711e1db9f9f59306f95f (patch) | |
tree | 7337eb2717eb749a125ed951d586d2dc661ffd29 | |
parent | 3a586dc7ddbeeb14c25da5439a6c4e989b856f6e (diff) |
socket: improve uc_socket_listen() behavior
- Treat address string values containing slashes as AF_UNIX addresses
- Default to SOCK_DGRAM for non AF_INET, AF_INET6 sockets
- Gracefully handle EOPNOTSUPP condition after listen() call
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lib/socket.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/socket.c b/lib/socket.c index 7fc56c8..2c0728d 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -2461,7 +2461,7 @@ uc_socket_listen(uc_vm_t *vm, size_t nargs) ai_hints = hints ? (struct addrinfo *)uv_to_struct(hints, &st_addrinfo) : NULL; - if (host == NULL || ucv_type(host) == UC_STRING) { + if (host == NULL || should_resolve(host)) { char *servstr = (ucv_type(serv) != UC_STRING) ? ucv_to_string(vm, serv) : NULL; @@ -2525,7 +2525,12 @@ uc_socket_listen(uc_vm_t *vm, size_t nargs) ((struct sockaddr_in *)&ss)->sin_port = htons(port); } - socktype = ai_hints ? ai_hints->ai_socktype : SOCK_STREAM; + int default_socktype = SOCK_STREAM; + + if (ss.ss_family != AF_INET && ss.ss_family != AF_INET6) + default_socktype = SOCK_DGRAM; + + socktype = ai_hints ? ai_hints->ai_socktype : default_socktype; protocol = ai_hints ? ai_hints->ai_protocol : 0; } @@ -2548,7 +2553,7 @@ uc_socket_listen(uc_vm_t *vm, size_t nargs) ret = listen(fd, backlog ? ucv_to_unsigned(backlog) : 128); - if (ret == -1) { + if (ret == -1 && errno != EOPNOTSUPP) { close(fd); err_return(errno, "listen()"); } |