From 13883a15ee8c1d9617f45ebcd6fdae8e01291e20 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Fri, 10 Sep 2021 02:53:58 -0400 Subject: sockets: throw exception if socket call fails. The open_socket function was not checking the result of the socket call for failure, which would cause datagram socket streams to be initialized with an invalid file descriptor (-1) and, when opening stream sockets, throw an error not representative of the actual problem. * socket.c (open_socket): Throw exception if socket call fails. --- socket.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/socket.c b/socket.c index 0e83cadb..b05d15e8 100644 --- a/socket.c +++ b/socket.c @@ -1102,6 +1102,11 @@ static val open_socket(val family, val type, val mode_str) { val self = lit("open-socket"); int fd = socket(c_num(family, self), c_num(type, self), 0); + + if (fd < 0) + uw_ethrowf(socket_error_s, lit("~a failed: ~d/~s"), + self, num(errno), errno_to_str(errno), nao); + #if SOCK_NONBLOCK || SOCK_CLOEXEC type = num_fast(c_num(type, self) & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)); #endif -- cgit v1.2.3