socket/extconf.rb: RSTRING_SOCKLEN

* ext/socket/extconf.rb (RSTRING_SOCKLEN): macro to cast RSTRING_LEN
  to socklen_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-04-06 07:58:51 +00:00
Родитель 7e4a95cd06
Коммит c7135ddd2d
6 изменённых файлов: 20 добавлений и 13 удалений

Просмотреть файл

@ -1255,7 +1255,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
memset(&mh, 0, sizeof(mh)); memset(&mh, 0, sizeof(mh));
if (!NIL_P(dest_sockaddr)) { if (!NIL_P(dest_sockaddr)) {
mh.msg_name = RSTRING_PTR(dest_sockaddr); mh.msg_name = RSTRING_PTR(dest_sockaddr);
mh.msg_namelen = RSTRING_LENINT(dest_sockaddr); mh.msg_namelen = RSTRING_SOCKLEN(dest_sockaddr);
} }
mh.msg_iovlen = 1; mh.msg_iovlen = 1;
mh.msg_iov = &iov; mh.msg_iov = &iov;
@ -1264,7 +1264,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
#if defined(HAVE_ST_MSG_CONTROL) #if defined(HAVE_ST_MSG_CONTROL)
if (controls_str) { if (controls_str) {
mh.msg_control = RSTRING_PTR(controls_str); mh.msg_control = RSTRING_PTR(controls_str);
mh.msg_controllen = RSTRING_LENINT(controls_str); mh.msg_controllen = RSTRING_SOCKLEN(controls_str);
} }
else { else {
mh.msg_control = NULL; mh.msg_control = NULL;

Просмотреть файл

@ -243,7 +243,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
default: default:
StringValue(val); StringValue(val);
v = RSTRING_PTR(val); v = RSTRING_PTR(val);
vlen = RSTRING_LENINT(val); vlen = RSTRING_SOCKLEN(val);
break; break;
} }
@ -555,7 +555,7 @@ rsock_bsock_send(int argc, VALUE *argv, VALUE sock)
SockAddrStringValue(to); SockAddrStringValue(to);
to = rb_str_new4(to); to = rb_str_new4(to);
arg.to = (struct sockaddr *)RSTRING_PTR(to); arg.to = (struct sockaddr *)RSTRING_PTR(to);
arg.tolen = (socklen_t)RSTRING_LENINT(to); arg.tolen = RSTRING_SOCKLEN(to);
func = rsock_sendto_blocking; func = rsock_sendto_blocking;
} }
else { else {

Просмотреть файл

@ -41,7 +41,11 @@ have_type("struct sockaddr_storage", headers)
have_type("struct addrinfo", headers) have_type("struct addrinfo", headers)
have_type("socklen_t", headers) if have_type("socklen_t", headers)
if try_static_assert("sizeof(socklen_t) >= sizeof(long)", headers)
$defs << "-DRSTRING_SOCKLEN=(socklen_t)RSTRING_LEN"
end
end
have_type("struct in_pktinfo", headers) {|src| have_type("struct in_pktinfo", headers) {|src|
src.sub(%r'^/\*top\*/', '\&'"\n#if defined(IPPROTO_IP) && defined(IP_PKTINFO)") << src.sub(%r'^/\*top\*/', '\&'"\n#if defined(IPPROTO_IP) && defined(IP_PKTINFO)") <<

Просмотреть файл

@ -923,7 +923,7 @@ addrinfo_initialize(int argc, VALUE *argv, VALUE self)
else { else {
StringValue(sockaddr_arg); StringValue(sockaddr_arg);
sockaddr_ptr = (struct sockaddr *)RSTRING_PTR(sockaddr_arg); sockaddr_ptr = (struct sockaddr *)RSTRING_PTR(sockaddr_arg);
sockaddr_len = RSTRING_LENINT(sockaddr_arg); sockaddr_len = RSTRING_SOCKLEN(sockaddr_arg);
init_addrinfo(rai, sockaddr_ptr, sockaddr_len, init_addrinfo(rai, sockaddr_ptr, sockaddr_len,
i_pfamily, i_socktype, i_protocol, i_pfamily, i_socktype, i_protocol,
canonname, inspectname); canonname, inspectname);

Просмотреть файл

@ -91,6 +91,9 @@
#ifndef HAVE_TYPE_SOCKLEN_T #ifndef HAVE_TYPE_SOCKLEN_T
typedef int socklen_t; typedef int socklen_t;
#endif #endif
#ifndef RSTRING_SOCKLEN
# define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT
#endif
#ifndef EWOULDBLOCK #ifndef EWOULDBLOCK
# define EWOULDBLOCK EAGAIN # define EWOULDBLOCK EAGAIN

Просмотреть файл

@ -381,7 +381,7 @@ sock_connect(VALUE sock, VALUE addr)
addr = rb_str_new4(addr); addr = rb_str_new4(addr);
GetOpenFile(sock, fptr); GetOpenFile(sock, fptr);
fd = fptr->fd; fd = fptr->fd;
n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr), 0); n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr), 0);
if (n < 0) { if (n < 0) {
rsock_sys_fail_addrinfo_or_sockaddr("connect(2)", addr, rai); rsock_sys_fail_addrinfo_or_sockaddr("connect(2)", addr, rai);
} }
@ -442,7 +442,7 @@ sock_connect_nonblock(VALUE sock, VALUE addr)
addr = rb_str_new4(addr); addr = rb_str_new4(addr);
GetOpenFile(sock, fptr); GetOpenFile(sock, fptr);
rb_io_set_nonblock(fptr); rb_io_set_nonblock(fptr);
n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr)); n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr));
if (n < 0) { if (n < 0) {
if (errno == EINPROGRESS) if (errno == EINPROGRESS)
rb_mod_sys_fail(rb_mWaitWritable, "connect(2) would block"); rb_mod_sys_fail(rb_mWaitWritable, "connect(2) would block");
@ -546,7 +546,7 @@ sock_bind(VALUE sock, VALUE addr)
SockAddrStringValueWithAddrinfo(addr, rai); SockAddrStringValueWithAddrinfo(addr, rai);
GetOpenFile(sock, fptr); GetOpenFile(sock, fptr);
if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr)) < 0) if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr)) < 0)
rsock_sys_fail_addrinfo_or_sockaddr("bind(2)", addr, rai); rsock_sys_fail_addrinfo_or_sockaddr("bind(2)", addr, rai);
return INT2FIX(0); return INT2FIX(0);
@ -1096,7 +1096,7 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
t = AF_INET6; t = AF_INET6;
} }
#endif #endif
h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LENINT(addr), t); h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_SOCKLEN(addr), t);
if (h == NULL) { if (h == NULL) {
#ifdef HAVE_HSTRERROR #ifdef HAVE_HSTRERROR
extern int h_errno; extern int h_errno;
@ -1319,7 +1319,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen"); rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
} }
sap = &ss.addr; sap = &ss.addr;
salen = RSTRING_LENINT(sa); salen = RSTRING_SOCKLEN(sa);
goto call_nameinfo; goto call_nameinfo;
} }
tmp = rb_check_array_type(sa); tmp = rb_check_array_type(sa);
@ -1483,7 +1483,7 @@ sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
rb_raise(rb_eArgError, "not an AF_INET sockaddr"); rb_raise(rb_eArgError, "not an AF_INET sockaddr");
#endif #endif
} }
host = rsock_make_ipaddr((struct sockaddr*)sockaddr, RSTRING_LENINT(addr)); host = rsock_make_ipaddr((struct sockaddr*)sockaddr, RSTRING_SOCKLEN(addr));
OBJ_INFECT(host, addr); OBJ_INFECT(host, addr);
return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), host); return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), host);
} }
@ -1550,7 +1550,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d", rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un)); RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
} }
path = rsock_unixpath_str(sockaddr, RSTRING_LENINT(addr)); path = rsock_unixpath_str(sockaddr, RSTRING_SOCKLEN(addr));
OBJ_INFECT(path, addr); OBJ_INFECT(path, addr);
return path; return path;
} }