summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-30 07:39:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-30 07:39:46 +0000
commitdb7a4e66e1eec8367d948e32815fde8cb25a24a9 (patch)
tree4e936172a62e56c1b0410cc687560e7f8501017b /ext/socket
parentd7168fa61eb872a4d16390e6c6b925b4ef413fb8 (diff)
ipsocket.c: sys_error
* ext/socket/ipsocket.c (init_inetsock_internal): preserve errno before other library calls and use rb_syserr_fail. [ruby-core:68531] [Bug #10975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/ipsocket.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index c84023daa2..9b32d082dd 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -41,6 +41,7 @@ inetsock_cleanup(struct inetsock_arg *arg)
static VALUE
init_inetsock_internal(struct inetsock_arg *arg)
{
+ int error = 0;
int type = arg->type;
struct addrinfo *res, *lres;
int fd, status = 0, local = 0;
@@ -80,6 +81,7 @@ init_inetsock_internal(struct inetsock_arg *arg)
syscall = "socket(2)";
fd = status;
if (fd < 0) {
+ error = errno;
continue;
}
arg->fd = fd;
@@ -107,6 +109,7 @@ init_inetsock_internal(struct inetsock_arg *arg)
}
if (status < 0) {
+ error = errno;
close(fd);
arg->fd = fd = -1;
continue;
@@ -124,7 +127,7 @@ init_inetsock_internal(struct inetsock_arg *arg)
port = arg->remote.serv;
}
- rsock_sys_fail_host_port(syscall, host, port);
+ rsock_syserr_fail_host_port(error, mesg, host, port);
}
arg->fd = -1;
@@ -132,8 +135,9 @@ init_inetsock_internal(struct inetsock_arg *arg)
if (type == INET_SERVER) {
status = listen(fd, SOMAXCONN);
if (status < 0) {
+ error = errno;
close(fd);
- rb_sys_fail("listen(2)");
+ rb_syserr_fail(error, "listen(2)");
}
}