summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/ipsocket.c9
-rw-r--r--ext/socket/unixsocket.c7
2 files changed, 13 insertions, 3 deletions
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index 447ae40db6..b6b2426e97 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -104,8 +104,13 @@ init_inetsock_internal(struct inetsock_arg *arg)
arg->fd = -1;
- if (type == INET_SERVER)
- listen(fd, 5);
+ if (type == INET_SERVER) {
+ status = listen(fd, 5);
+ if (status < 0) {
+ close(fd);
+ syscall = "listen(2)";
+ }
+ }
/* create new instance */
return rsock_init_sock(arg->sock, fd);
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 907f89cc49..4c3c5a7f7a 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -65,7 +65,12 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
rb_sys_fail(sockaddr.sun_path);
}
- if (server) listen(fd, 5);
+ if (server) {
+ if (listen(fd, 5) < 0) {
+ close(fd);
+ rb_sys_fail("listen(2)");
+ }
+ }
rsock_init_sock(sock, fd);
if (server) {