diff options
author | Paul A. Patience <paul@apatience.com> | 2021-09-10 02:53:58 -0400 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-09-11 09:27:10 -0700 |
commit | 42582b957984a7a5b6de9ab890a1eb3b853e88ca (patch) | |
tree | d00aa1db028615978d454993b72bea456198cea9 | |
parent | 01b8f412e97ec3dd8214f33bc5374d29d27e938e (diff) | |
download | txr-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.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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 |