mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
udpsocket.c: refix r52097
* ext/socket/udpsocket.c (udp_connect, udp_bind): get open files inside ensure functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a00fc76ce5
commit
d9ac64fdc7
2 changed files with 36 additions and 20 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Oct 10 19:04:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/socket/udpsocket.c (udp_connect, udp_bind): get open files
|
||||
inside ensure functions.
|
||||
|
||||
Sat Oct 10 18:35:12 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_insnhelper.c (vm_call_method0): do not propagate enable_fastpath,
|
||||
|
|
|
@ -44,15 +44,18 @@ udp_init(int argc, VALUE *argv, VALUE sock)
|
|||
struct udp_arg
|
||||
{
|
||||
struct rb_addrinfo *res;
|
||||
int fd;
|
||||
VALUE io;
|
||||
};
|
||||
|
||||
static VALUE
|
||||
udp_connect_internal(struct udp_arg *arg)
|
||||
{
|
||||
int fd = arg->fd;
|
||||
rb_io_t *fptr;
|
||||
int fd;
|
||||
struct addrinfo *res;
|
||||
|
||||
GetOpenFile(arg->io, 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) {
|
||||
return Qtrue;
|
||||
|
@ -80,19 +83,35 @@ udp_connect_internal(struct udp_arg *arg)
|
|||
static VALUE
|
||||
udp_connect(VALUE sock, VALUE host, VALUE port)
|
||||
{
|
||||
rb_io_t *fptr;
|
||||
struct udp_arg arg;
|
||||
VALUE ret;
|
||||
|
||||
GetOpenFile(sock, fptr);
|
||||
arg.io = sock;
|
||||
arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
arg.fd = fptr->fd;
|
||||
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
|
||||
rsock_freeaddrinfo, (VALUE)arg.res);
|
||||
if (!ret) rsock_sys_fail_host_port("connect(2)", host, port);
|
||||
return INT2FIX(0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
udp_bind_internal(struct udp_arg *arg)
|
||||
{
|
||||
rb_io_t *fptr;
|
||||
int fd;
|
||||
struct addrinfo *res;
|
||||
|
||||
GetOpenFile(arg->io, fptr);
|
||||
fd = fptr->fd;
|
||||
for (res = arg->res->ai; res; res = res->ai_next) {
|
||||
if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) {
|
||||
continue;
|
||||
}
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* udpsocket.bind(host, port) #=> 0
|
||||
|
@ -108,22 +127,14 @@ udp_connect(VALUE sock, VALUE host, VALUE port)
|
|||
static VALUE
|
||||
udp_bind(VALUE sock, VALUE host, VALUE port)
|
||||
{
|
||||
rb_io_t *fptr;
|
||||
struct rb_addrinfo *res0;
|
||||
struct addrinfo *res;
|
||||
struct udp_arg arg;
|
||||
VALUE ret;
|
||||
|
||||
GetOpenFile(sock, fptr);
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
for (res = res0->ai; res; res = res->ai_next) {
|
||||
if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
|
||||
continue;
|
||||
}
|
||||
rb_freeaddrinfo(res0);
|
||||
return INT2FIX(0);
|
||||
}
|
||||
rb_freeaddrinfo(res0);
|
||||
|
||||
rsock_sys_fail_host_port("bind(2)", host, port);
|
||||
arg.io = sock;
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue