зеркало из https://github.com/github/ruby.git
* ext/socket/socket.c (rb_getaddrinfo): defined for address lookup without GVL.
(struct getaddrinfo_arg): defined. (nogvl_getaddrinfo): defined. (rb_getnameinfo): defined for name lookup without GVL. (getnameinfo_arg): defined. (nogvl_getnameinfo): defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
deeade6f3e
Коммит
d4a0895181
|
@ -1,3 +1,12 @@
|
||||||
|
Sun Jan 4 22:37:19 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/socket.c (rb_getaddrinfo): defined for address lookup without GVL.
|
||||||
|
(struct getaddrinfo_arg): defined.
|
||||||
|
(nogvl_getaddrinfo): defined.
|
||||||
|
(rb_getnameinfo): defined for name lookup without GVL.
|
||||||
|
(getnameinfo_arg): defined.
|
||||||
|
(nogvl_getnameinfo): defined.
|
||||||
|
|
||||||
Sun Jan 4 18:10:10 2009 Martin Duerst <duerst@it.aoyama.ac.jp>
|
Sun Jan 4 18:10:10 2009 Martin Duerst <duerst@it.aoyama.ac.jp>
|
||||||
|
|
||||||
* enc/trans/gbk.trans, gbk-tbl.rb:
|
* enc/trans/gbk.trans, gbk-tbl.rb:
|
||||||
|
|
|
@ -228,6 +228,7 @@ ruby_getnameinfo__aix(sa, salen, host, hostlen, serv, servlen, flags)
|
||||||
#undef getnameinfo
|
#undef getnameinfo
|
||||||
#define getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
|
#define getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
|
||||||
ruby_getnameinfo__aix((sa), (salen), (host), (hostlen), (serv), (servlen), (flags))
|
ruby_getnameinfo__aix((sa), (salen), (host), (hostlen), (serv), (servlen), (flags))
|
||||||
|
|
||||||
#ifndef CMSG_SPACE
|
#ifndef CMSG_SPACE
|
||||||
# define CMSG_SPACE(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + _CMSG_ALIGN(len))
|
# define CMSG_SPACE(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + _CMSG_ALIGN(len))
|
||||||
#endif
|
#endif
|
||||||
|
@ -241,6 +242,76 @@ ruby_getnameinfo__aix(sa, salen, host, hostlen, serv, servlen, flags)
|
||||||
#define close closesocket
|
#define close closesocket
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct getaddrinfo_arg
|
||||||
|
{
|
||||||
|
const char *node;
|
||||||
|
const char *service;
|
||||||
|
const struct addrinfo *hints;
|
||||||
|
struct addrinfo **res;
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
nogvl_getaddrinfo(void *arg)
|
||||||
|
{
|
||||||
|
struct getaddrinfo_arg *ptr = arg;
|
||||||
|
return getaddrinfo(ptr->node, ptr->service,
|
||||||
|
ptr->hints, ptr->res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
rb_getaddrinfo(const char *node, const char *service,
|
||||||
|
const struct addrinfo *hints,
|
||||||
|
struct addrinfo **res)
|
||||||
|
{
|
||||||
|
struct getaddrinfo_arg arg;
|
||||||
|
int ret;
|
||||||
|
arg.node = node;
|
||||||
|
arg.service = service;
|
||||||
|
arg.hints = hints;
|
||||||
|
arg.res = res;
|
||||||
|
ret = BLOCKING_REGION(nogvl_getaddrinfo, &arg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct getnameinfo_arg
|
||||||
|
{
|
||||||
|
const struct sockaddr *sa;
|
||||||
|
socklen_t salen;
|
||||||
|
char *host;
|
||||||
|
size_t hostlen;
|
||||||
|
char *serv;
|
||||||
|
size_t servlen;
|
||||||
|
int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
nogvl_getnameinfo(void *arg)
|
||||||
|
{
|
||||||
|
struct getnameinfo_arg *ptr = arg;
|
||||||
|
return getnameinfo(ptr->sa, ptr->salen,
|
||||||
|
ptr->host, ptr->hostlen,
|
||||||
|
ptr->serv, ptr->servlen,
|
||||||
|
ptr->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||||
|
char *host, size_t hostlen,
|
||||||
|
char *serv, size_t servlen, int flags)
|
||||||
|
{
|
||||||
|
struct getnameinfo_arg arg;
|
||||||
|
int ret;
|
||||||
|
arg.sa = sa;
|
||||||
|
arg.salen = salen;
|
||||||
|
arg.host = host;
|
||||||
|
arg.hostlen = hostlen;
|
||||||
|
arg.serv = serv;
|
||||||
|
arg.servlen = servlen;
|
||||||
|
arg.flags = flags;
|
||||||
|
ret = BLOCKING_REGION(nogvl_getnameinfo, &arg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
constant_arg(VALUE arg, int (*str_to_int)(char*, int, int*), const char *errmsg)
|
constant_arg(VALUE arg, int (*str_to_int)(char*, int, int*), const char *errmsg)
|
||||||
{
|
{
|
||||||
|
@ -893,7 +964,7 @@ make_ipaddr0(struct sockaddr *addr, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST);
|
error = rb_getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST);
|
||||||
if (error) {
|
if (error) {
|
||||||
raise_socket_error("getnameinfo", error);
|
raise_socket_error("getnameinfo", error);
|
||||||
}
|
}
|
||||||
|
@ -1015,7 +1086,7 @@ sock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_ha
|
||||||
hints->ai_socktype = SOCK_DGRAM;
|
hints->ai_socktype = SOCK_DGRAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = getaddrinfo(hostp, portp, hints, &res);
|
error = rb_getaddrinfo(hostp, portp, hints, &res);
|
||||||
if (error) {
|
if (error) {
|
||||||
if (hostp && hostp[strlen(hostp)-1] == '\n') {
|
if (hostp && hostp[strlen(hostp)-1] == '\n') {
|
||||||
rb_raise(rb_eSocket, "newline at the end of hostname");
|
rb_raise(rb_eSocket, "newline at the end of hostname");
|
||||||
|
@ -1076,13 +1147,13 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
|
||||||
|
|
||||||
addr1 = Qnil;
|
addr1 = Qnil;
|
||||||
if (!norevlookup) {
|
if (!norevlookup) {
|
||||||
error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
|
error = rb_getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
|
||||||
NULL, 0, 0);
|
NULL, 0, 0);
|
||||||
if (! error) {
|
if (! error) {
|
||||||
addr1 = rb_str_new2(hbuf);
|
addr1 = rb_str_new2(hbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
|
error = rb_getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
|
||||||
pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV);
|
pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (error) {
|
if (error) {
|
||||||
raise_socket_error("getnameinfo", error);
|
raise_socket_error("getnameinfo", error);
|
||||||
|
@ -3393,7 +3464,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
|
||||||
hints.ai_socktype = (fl & NI_DGRAM) ? SOCK_DGRAM : SOCK_STREAM;
|
hints.ai_socktype = (fl & NI_DGRAM) ? SOCK_DGRAM : SOCK_STREAM;
|
||||||
/* af */
|
/* af */
|
||||||
hints.ai_family = NIL_P(af) ? PF_UNSPEC : family_arg(af);
|
hints.ai_family = NIL_P(af) ? PF_UNSPEC : family_arg(af);
|
||||||
error = getaddrinfo(hptr, pptr, &hints, &res);
|
error = rb_getaddrinfo(hptr, pptr, &hints, &res);
|
||||||
if (error) goto error_exit_addr;
|
if (error) goto error_exit_addr;
|
||||||
sap = res->ai_addr;
|
sap = res->ai_addr;
|
||||||
}
|
}
|
||||||
|
@ -3402,7 +3473,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
call_nameinfo:
|
call_nameinfo:
|
||||||
error = getnameinfo(sap, SA_LEN(sap), hbuf, sizeof(hbuf),
|
error = rb_getnameinfo(sap, SA_LEN(sap), hbuf, sizeof(hbuf),
|
||||||
pbuf, sizeof(pbuf), fl);
|
pbuf, sizeof(pbuf), fl);
|
||||||
if (error) goto error_exit_name;
|
if (error) goto error_exit_name;
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -3410,7 +3481,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
|
||||||
char hbuf2[1024], pbuf2[1024];
|
char hbuf2[1024], pbuf2[1024];
|
||||||
|
|
||||||
sap = r->ai_addr;
|
sap = r->ai_addr;
|
||||||
error = getnameinfo(sap, SA_LEN(sap), hbuf2, sizeof(hbuf2),
|
error = rb_getnameinfo(sap, SA_LEN(sap), hbuf2, sizeof(hbuf2),
|
||||||
pbuf2, sizeof(pbuf2), fl);
|
pbuf2, sizeof(pbuf2), fl);
|
||||||
if (error) goto error_exit_name;
|
if (error) goto error_exit_name;
|
||||||
if (strcmp(hbuf, hbuf2) != 0|| strcmp(pbuf, pbuf2) != 0) {
|
if (strcmp(hbuf, hbuf2) != 0|| strcmp(pbuf, pbuf2) != 0) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче