summaryrefslogtreecommitdiff
path: root/ext/socket/udpsocket.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-12 00:11:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-12 00:11:37 +0000
commit3cf04aceec67a4eb4aa32c6c50187c59ac71280c (patch)
tree1bef46901893e30f15f0408e5ecc2f282dd8f754 /ext/socket/udpsocket.c
parent2ddb885863ca61c2687e968b0a0b1ac611842b6b (diff)
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
Diffstat (limited to 'ext/socket/udpsocket.c')
-rw-r--r--ext/socket/udpsocket.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c
index 2257fc9..1138280 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);
}