From ed9e256e39a9e5856d4977fe0c369afc16c7a357 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 12 Oct 2015 00:11:37 +0000 Subject: udpsocket.c: check once first * ext/socket/udpsocket.c (udp_connect, udp_bind): check if the socket is opened once before retreiving address infos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/udpsocket.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'ext/socket') diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c index 2257fc95c8..113828038d 100644 --- a/ext/socket/udpsocket.c +++ b/ext/socket/udpsocket.c @@ -44,7 +44,7 @@ udp_init(int argc, VALUE *argv, VALUE sock) struct udp_arg { struct rb_addrinfo *res; - VALUE io; + rb_io_t *fptr; }; static VALUE @@ -54,7 +54,7 @@ udp_connect_internal(struct udp_arg *arg) int fd; struct addrinfo *res; - GetOpenFile(arg->io, fptr); + rb_io_check_closed(fptr = arg->fptr); fd = fptr->fd; for (res = arg->res->ai; res; res = res->ai_next) { if (rsock_connect(fd, res->ai_addr, res->ai_addrlen, 0) >= 0) { @@ -86,7 +86,7 @@ udp_connect(VALUE sock, VALUE host, VALUE port) struct udp_arg arg; VALUE ret; - arg.io = sock; + GetOpenFile(sock, arg.fptr); arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0); ret = rb_ensure(udp_connect_internal, (VALUE)&arg, rsock_freeaddrinfo, (VALUE)arg.res); @@ -101,7 +101,7 @@ udp_bind_internal(struct udp_arg *arg) int fd; struct addrinfo *res; - GetOpenFile(arg->io, fptr); + rb_io_check_closed(fptr = arg->fptr); fd = fptr->fd; for (res = arg->res->ai; res; res = res->ai_next) { if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) { @@ -130,12 +130,11 @@ udp_bind(VALUE sock, VALUE host, VALUE port) struct udp_arg arg; VALUE ret; - arg.io = sock; + GetOpenFile(sock, arg.fptr); arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0); ret = rb_ensure(udp_bind_internal, (VALUE)&arg, rsock_freeaddrinfo, (VALUE)arg.res); if (!ret) rsock_sys_fail_host_port("bind(2)", host, port); - return INT2FIX(0); } -- cgit v1.2.3