Actions
Bug #11958
closedTCPSocket.getsockopt().bool raises a TypeError on windows
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.7p400 (2015-08-18 revision 51632) [x64-mingw32]
Description
The following code snippet works as expected on linux (it returns "false"):
require 'net/http'
http = Net::HTTP.new('192.168.111.21', 8080)
http.start
socket = http.instance_variable_get(:@socket).io
socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).bool
But on windows, it raises this error:
TypeError: size differ. expected as sizeof(int)=4 but 1
from (irb):8:in `bool'
from (irb):8
from irb:11:in `<main>'
(TCPSocket.getsockopt().int
has the same problem.)
Digging a bit further, I noticed what socket.getsockopt().data
returns is platform-specific, despite Socket::Option.bool().data
being the same on both platforms.
On linux:
socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).data
"\x00\x00\x00\x00"
Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false).data
"\x00\x00\x00\x00"
On windows:
socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE).data
"\x00"
Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false).data
"\x00\x00\x00\x00"
This might explain the size differ. expected as sizeof(int)=4 but 1
raised by getsockopt()
?
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Status changed from Open to Closed
Applied in changeset r53561.
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]
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Description updated (diff)
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED
Updated by usa (Usaku NAKAMURA) over 8 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED, 2.3: REQUIRED
ruby_2_1 r53931 merged revision(s) 53561.
Updated by nagachika (Tomoyuki Chikanaga) over 8 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED, 2.3: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE, 2.3: REQUIRED
Backported into ruby_2_2
branch at r54067.
Updated by naruse (Yui NARUSE) over 8 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE, 2.3: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE, 2.3: DONE
ruby_2_3 r54355 merged revision(s) 53557,53561.
Actions
Like0
Like0Like0Like0Like0Like0