socket: fix recvmsg without argument

* ext/socket/ancdata.c (bsock_recvmsg_internal): grow buffer
  on unspecified maxdatlen
  [ruby-core:71517] [Bug #11701]
* ext/socket/lib/socket.rb (Socket#recvmsg): nil default for dlen
  (Socket#recvmsg_nonblock): ditto
* test/socket/test_socket.rb (test_recvmsg_udp_no_arg): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-11-17 22:00:23 +00:00
Родитель dd2949a712
Коммит 508b5fdd52
4 изменённых файлов: 28 добавлений и 3 удалений

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

@ -1,3 +1,12 @@
Wed Nov 18 06:59:52 2015 Eric Wong <e@80x24.org>
* ext/socket/ancdata.c (bsock_recvmsg_internal): grow buffer
on unspecified maxdatlen
[ruby-core:71517] [Bug #11701]
* ext/socket/lib/socket.rb (Socket#recvmsg): nil default for dlen
(Socket#recvmsg_nonblock): ditto
* test/socket/test_socket.rb (test_recvmsg_udp_no_arg): new test
Tue Nov 17 19:50:06 2015 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (fstat): declare for mingw.

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

@ -1465,7 +1465,7 @@ bsock_recvmsg_internal(VALUE sock,
int gc_done = 0;
#endif
maxdatlen = NUM2SIZET(vmaxdatlen);
maxdatlen = NIL_P(vmaxdatlen) ? 4061 : NUM2SIZET(vmaxdatlen);
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
maxctllen = NIL_P(vmaxctllen) ? 4096 : NUM2SIZET(vmaxctllen);
#else

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

@ -425,7 +425,7 @@ class BasicSocket < IO
# return ancdata.unix_rights[0]
# end
# }
def recvmsg(dlen = 4096, flags = 0, clen = nil, scm_rights: false)
def recvmsg(dlen = nil, flags = 0, clen = nil, scm_rights: false)
__recvmsg(dlen, flags, clen, scm_rights)
end
@ -441,7 +441,7 @@ class BasicSocket < IO
# By specifying `exception: false`, the _opts_ hash allows you to indicate
# that recvmsg_nonblock should not raise an IO::WaitWritable exception, but
# return the symbol :wait_writable instead.
def recvmsg_nonblock(dlen = 4096, flags = 0, clen = nil,
def recvmsg_nonblock(dlen = nil, flags = 0, clen = nil,
scm_rights: false, exception: true)
__recvmsg_nonblock(dlen, flags, clen, scm_rights, exception)
end

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

@ -653,4 +653,20 @@ class TestSocket < Test::Unit::TestCase
end
end
def test_recvmsg_udp_no_arg
n = 4097
s1 = Addrinfo.udp("127.0.0.1", 0).bind
s2 = s1.connect_address.connect
s2.send("a" * n, 0)
ret = s1.recvmsg
assert_equal n, ret[0].bytesize, '[ruby-core:71517] [Bug #11701]'
s2.send("a" * n, 0)
IO.select([s1])
ret = s1.recvmsg_nonblock
assert_equal n, ret[0].bytesize, 'non-blocking should also grow'
ensure
s1.close
s2.close
end
end if defined?(Socket)