summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-06 07:58:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-06 07:58:51 +0000
commitc7135ddd2dcd59ca46ea3307b21f68dea7504ac8 (patch)
treeca957b72291232741b6d7f14b9dd32fefb9e2d61 /ext
parent7e4a95cd062ac961a91b7b7185b75c103bc7496d (diff)
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
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/ancdata.c4
-rw-r--r--ext/socket/basicsocket.c4
-rw-r--r--ext/socket/extconf.rb6
-rw-r--r--ext/socket/raddrinfo.c2
-rw-r--r--ext/socket/rubysocket.h3
-rw-r--r--ext/socket/socket.c14
6 files changed, 20 insertions, 13 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 0693c24..5ca5bdd 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -1255,7 +1255,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
memset(&mh, 0, sizeof(mh));
if (!NIL_P(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_iov = &iov;
@@ -1264,7 +1264,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
#if defined(HAVE_ST_MSG_CONTROL)
if (controls_str) {
mh.msg_control = RSTRING_PTR(controls_str);
- mh.msg_controllen = RSTRING_LENINT(controls_str);
+ mh.msg_controllen = RSTRING_SOCKLEN(controls_str);
}
else {
mh.msg_control = NULL;
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index 94c34da..19dc2f5 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -243,7 +243,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
default:
StringValue(val);
v = RSTRING_PTR(val);
- vlen = RSTRING_LENINT(val);
+ vlen = RSTRING_SOCKLEN(val);
break;
}
@@ -555,7 +555,7 @@ rsock_bsock_send(int argc, VALUE *argv, VALUE sock)
SockAddrStringValue(to);
to = rb_str_new4(to);
arg.to = (struct sockaddr *)RSTRING_PTR(to);
- arg.tolen = (socklen_t)RSTRING_LENINT(to);
+ arg.tolen = RSTRING_SOCKLEN(to);
func = rsock_sendto_blocking;
}
else {
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 011a110..0a37a9b 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -41,7 +41,11 @@ have_type("struct sockaddr_storage", 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|
src.sub(%r'^/\*top\*/', '\&'"\n#if defined(IPPROTO_IP) && defined(IP_PKTINFO)") <<
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 11d2980..d0d4d85 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -923,7 +923,7 @@ addrinfo_initialize(int argc, VALUE *argv, VALUE self)
else {
StringValue(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,
i_pfamily, i_socktype, i_protocol,
canonname, inspectname);
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 133276c..c68cff1 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -91,6 +91,9 @@
#ifndef HAVE_TYPE_SOCKLEN_T
typedef int socklen_t;
#endif
+#ifndef RSTRING_SOCKLEN
+# define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT
+#endif
#ifndef EWOULDBLOCK
# define EWOULDBLOCK EAGAIN
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 0590116..9783313 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -381,7 +381,7 @@ sock_connect(VALUE sock, VALUE addr)
addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
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) {
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);
GetOpenFile(sock, 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 (errno == EINPROGRESS)
rb_mod_sys_fail(rb_mWaitWritable, "connect(2) would block");
@@ -546,7 +546,7 @@ sock_bind(VALUE sock, VALUE addr)
SockAddrStringValueWithAddrinfo(addr, rai);
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);
return INT2FIX(0);
@@ -1096,7 +1096,7 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
t = AF_INET6;
}
#endif
- h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LENINT(addr), t);
+ h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_SOCKLEN(addr), t);
if (h == NULL) {
#ifdef HAVE_HSTRERROR
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");
}
sap = &ss.addr;
- salen = RSTRING_LENINT(sa);
+ salen = RSTRING_SOCKLEN(sa);
goto call_nameinfo;
}
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");
#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);
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",
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);
return path;
}