Project

General

Profile

Feature #17134 ยป resolv_timeout.patch

Glass_saga (Masaki Matsushita), 08/29/2020 05:26 AM

View differences:

ext/socket/ipsocket.c
} remote, local;
int type;
int fd;
VALUE resolv_timeout;
};
static VALUE
......
int fd, status = 0, local = 0;
int family = AF_UNSPEC;
const char *syscall = 0;
VALUE resolv_timeout = arg->resolv_timeout;
#ifdef HAVE_GETADDRINFO_A
arg->remote.res = rsock_addrinfo_a(arg->remote.host, arg->remote.serv,
family, SOCK_STREAM,
(type == INET_SERVER) ? AI_PASSIVE : 0,
resolv_timeout);
#else
arg->remote.res = rsock_addrinfo(arg->remote.host, arg->remote.serv,
family, SOCK_STREAM,
(type == INET_SERVER) ? AI_PASSIVE : 0);
#endif
/*
* Maybe also accept a local address
*/
......
VALUE
rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv,
VALUE local_host, VALUE local_serv, int type)
VALUE local_host, VALUE local_serv, int type,
VALUE resolv_timeout)
{
struct inetsock_arg arg;
arg.sock = sock;
......
arg.local.res = 0;
arg.type = type;
arg.fd = -1;
arg.resolv_timeout = resolv_timeout;
return rb_ensure(init_inetsock_internal, (VALUE)&arg,
inetsock_cleanup, (VALUE)&arg);
}
ext/socket/raddrinfo.c
return rsock_getaddrinfo(host, port, &hints, 1);
}
#ifdef HAVE_GETADDRINFO_A
struct rb_addrinfo*
rsock_addrinfo_a(VALUE host, VALUE port, int family, int socktype, int flags, VALUE timeout)
{
struct addrinfo hints;
MEMZERO(&hints, struct addrinfo, 1);
hints.ai_family = family;
hints.ai_socktype = socktype;
hints.ai_flags = flags;
return rsock_getaddrinfo_a(host, port, &hints, 1, timeout);
}
#endif
VALUE
rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
{
ext/socket/rubysocket.h
struct rb_addrinfo *rsock_addrinfo(VALUE host, VALUE port, int family, int socktype, int flags);
struct rb_addrinfo *rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack);
#ifdef HAVE_GETADDRINFO_A
struct rb_addrinfo *rsock_addrinfo_a(VALUE host, VALUE port, int family, int socktype, int flags, VALUE timeout);
struct rb_addrinfo *rsock_getaddrinfo_a(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack, VALUE timeout);
#endif
......
int rsock_detect_cloexec(int fd);
VALUE rsock_init_sock(VALUE sock, int fd);
VALUE rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass);
VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type);
VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type, VALUE resolv_timeout);
VALUE rsock_init_unixsock(VALUE sock, VALUE path, int server);
struct rsock_send_arg {
ext/socket/sockssocket.c
init = 1;
}
return rsock_init_inetsock(sock, host, port, Qnil, Qnil, INET_SOCKS);
return rsock_init_inetsock(sock, host, port, Qnil, Qnil, INET_SOCKS, Qnil);
}
#ifdef SOCKS5
ext/socket/tcpserver.c
VALUE hostname, port;
rb_scan_args(argc, argv, "011", &hostname, &port);
return rsock_init_inetsock(sock, hostname, port, Qnil, Qnil, INET_SERVER);
return rsock_init_inetsock(sock, hostname, port, Qnil, Qnil, INET_SERVER, Qnil);
}
/*
ext/socket/tcpsocket.c
{
VALUE remote_host, remote_serv;
VALUE local_host, local_serv;
VALUE opt;
static ID keyword_ids[1];
VALUE kwargs[1];
VALUE resolv_timeout = Qnil;
rb_scan_args(argc, argv, "22", &remote_host, &remote_serv,
&local_host, &local_serv);
if (!keyword_ids[0]) {
CONST_ID(keyword_ids[0], "resolv_timeout");
}
rb_scan_args(argc, argv, "22:", &remote_host, &remote_serv,
&local_host, &local_serv, &opt);
if (!NIL_P(opt)) {
rb_get_kwargs(opt, keyword_ids, 0, 1, kwargs);
if (kwargs[0] != Qundef) {
resolv_timeout = kwargs[0];
}
}
return rsock_init_inetsock(sock, remote_host, remote_serv,
local_host, local_serv, INET_CLIENT);
local_host, local_serv, INET_CLIENT,
resolv_timeout);
}
static VALUE
test/socket/test_tcp.rb
t.close if t && !t.closed?
end
def test_initialize_resolv_timeout
TCPServer.open("localhost", 0) do |svr|
th = Thread.new {
c = svr.accept
c.close
}
addr = svr.addr
s = TCPSocket.new(addr[3], addr[1], resolv_timeout: 10)
th.join
ensure
s.close()
end
end
def test_recvfrom
TCPServer.open("localhost", 0) {|svr|
th = Thread.new {
    (1-1/1)