summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul A. Patience <paul@apatience.com>2021-09-10 02:53:58 -0400
committerKaz Kylheku <kaz@kylheku.com>2021-09-11 09:27:10 -0700
commit42582b957984a7a5b6de9ab890a1eb3b853e88ca (patch)
treed00aa1db028615978d454993b72bea456198cea9
parent01b8f412e97ec3dd8214f33bc5374d29d27e938e (diff)
downloadtxr-42582b957984a7a5b6de9ab890a1eb3b853e88ca.tar.gz
txr-42582b957984a7a5b6de9ab890a1eb3b853e88ca.tar.bz2
txr-42582b957984a7a5b6de9ab890a1eb3b853e88ca.zip
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.
-rw-r--r--socket.c5
1 files changed, 5 insertions, 0 deletions
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