mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									7e4a95cd06
								
							
						
					
					
						commit
						c7135ddd2d
					
				
					 6 changed files with 20 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)") <<
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue