mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
option.c: single byte boolean
* ext/socket/option.c (sockopt_bool): relax boolean size to be one too not only sizeof(int). Winsock getsockopt() returns a single byte as a boolean socket option. [ruby-core:72730] [Bug #11958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f918d2b8e2
commit
0bc5341690
3 changed files with 19 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Sun Jan 17 15:30:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/socket/option.c (sockopt_bool): relax boolean size to be one
|
||||
too not only sizeof(int). Winsock getsockopt() returns a single
|
||||
byte as a boolean socket option. [ruby-core:72730] [Bug #11958]
|
||||
|
||||
Sun Jan 17 14:43:01 2016 Kuniaki IGARASHI <igaiga@gmail.com>
|
||||
|
||||
* test/ruby/test_env.rb: [Fix GH-1201]
|
||||
|
|
|
@ -302,10 +302,15 @@ static VALUE
|
|||
sockopt_bool(VALUE self)
|
||||
{
|
||||
int i;
|
||||
long len;
|
||||
VALUE data = sockopt_data(self);
|
||||
StringValue(data);
|
||||
check_size(RSTRING_LEN(data), sizeof(int));
|
||||
memcpy((char*)&i, RSTRING_PTR(data), sizeof(int));
|
||||
len = RSTRING_LEN(data);
|
||||
if (len == 1) {
|
||||
return *RSTRING_PTR(data) == 0 ? Qfalse : Qtrue;
|
||||
}
|
||||
check_size(len, sizeof(int));
|
||||
memcpy((char*)&i, RSTRING_PTR(data), len);
|
||||
return i == 0 ? Qfalse : Qtrue;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,12 @@ class TestSocketOption < Test::Unit::TestCase
|
|||
assert_equal(true, opt.bool)
|
||||
opt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 2)
|
||||
assert_equal(true, opt.bool)
|
||||
Socket.open(:INET, :STREAM) {|s|
|
||||
s.setsockopt(Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, true))
|
||||
assert_equal(true, s.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).bool)
|
||||
s.setsockopt(Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false))
|
||||
assert_equal(false, s.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).bool)
|
||||
}
|
||||
end
|
||||
|
||||
def test_ipv4_multicast_loop
|
||||
|
|
Loading…
Reference in a new issue