Skip to content

Add missing signatures to socket - #3217

Merged
ksss merged 4 commits into
ruby:masterfrom
ksss:socket-missing-signatures
Oct 10, 2026
Merged

ksss merged 4 commits into
ruby:masterfrom
ksss:socket-missing-signatures

Conversation

@ksss

@ksss ksss commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fill in classes and methods that socket was missing, found by diffing the runtime (ObjectSpace / instance_methods(false)) against the loaded RBS environment.

  • Add Socket::ResolutionError (#error_code, Ruby 3.3+)
  • Add Socket::Option (.new, .bool, .byte, .int, .linger, .ipv4_multicast_*, and the matching instance methods)
  • Add Socket.tcp_fast_fallback / Socket.tcp_fast_fallback= (Ruby 3.4+)
  • Fix BasicSocket#getsockopt: it returned Integer | boolish | String but actually returns Socket::Option
  • Fix BasicSocket#setsockopt: add the (Socket::Option) form (the return type stays void)

Intentionally not added: Socket::HostnameResolutionResult, Socket::HostnameResolutionStore and Addrinfo#connect_internal, which are internal to Socket.tcp.

Notes

  • getsockopt now returns Socket::Option, so code that treated the result as Integer or String will see different type errors. Option has #unpack, #int, #bool, etc.
  • Socket.tcp_fast_fallback= stores any object as is, but is typed (bool) to keep the getter's bool return sound.
  • The docs comments are hand-written in rdoc style, not generated from upstream.

Test plan

  • test/stdlib/socket/*_test.rb (27 tests) pass with LC_ALL=en_US.UTF-8
  • rbs -rsocket validate
  • bin/steep check

🤖 Generated with Claude Code

ksss and others added 4 commits October 10, 2026 16:54
- Add `Socket::ResolutionError`
- Add `Socket::Option`
- Add `Socket.tcp_fast_fallback` and `Socket.tcp_fast_fallback=`
- Fix `BasicSocket#getsockopt` to return `Socket::Option`, and let
  `BasicSocket#setsockopt` accept a `Socket::Option`

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replace the hand-written comments with the ones generated from RDoc.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The `0` is just the success code of setsockopt(2) and is not documented as a
return value, so callers should not rely on it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ksss
ksss added this pull request to the merge queue Oct 10, 2026
Merged via the queue into ruby:master with commit ec2c04e Oct 10, 2026
25 checks passed
@ksss
ksss deleted the socket-missing-signatures branch October 10, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant