⚡ Sangsakala Proxy 🏠 Home
Skip to content

Align socket receive and control argument binding - #9668

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:socket-control-binding-group-20261103
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:socket-control-binding-group-20261103

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

  • Share recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order.
  • Return immediately from zero-length recv and recv_into, including on closed sockets, as CPython does.
  • Bind sendto and setsockopt arguments before conversion, retain original arguments through I/O, and acquire sendto's buffer export before converting flags without holding its data lock across callbacks.

Only production Rust files change. Existing special no-keyword and sendto overload diagnostics remain.

Evidence and validation

Checked CPython 3.15 source (Modules/socketmodule.c: sock_recv_guts, sock_recv_into, sock_recvfrom_into, sock_sendto, and sock_setsockopt). Bounded CPython 3.15.0 probes using only an owned socketpair confirmed:

  • Both into-methods accept buffer, nbytes, and flags keywords.
  • Buffer rejection precedes numeric callbacks; valid numeric callbacks precede duplicate/unknown keyword errors.
  • Numeric callbacks can mutate exported buffer contents.
  • Zero-byte recv and recv_into return immediately, including after closing the socket.
  • sendto rejects an invalid buffer before invoking a flags callback.
  • Invalid setsockopt arity does not invoke numeric callbacks.

rustfmt and git diff --check passed. Exact-head cached patches for #9638, #9640, and #9642 each apply cleanly over this change.

Passed on Linux against main 0b081b0283987c7b2d79327dd481f403d515580b:

  • cargo check -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1
  • cargo clippy -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1 -- -D warnings

RustPython runtime tests, the full Rust suites, Python suites, and other-platform testing were not run. CPython probes establish reference behavior, not execution of the patched RustPython interpreter.

Known limits

The receive methods already had a text-signature mismatch with CPython's keyword support. Their representation now becomes generic (*args, **kwargs); this patch does not repair introspection metadata. Writable-buffer error wording remains that of the shared buffer helper rather than claiming exact CPython wording.

The zero-byte results above were observed on Linux. On non-poll platforms CPython checks high-descriptor selectability before returning zero, so these observations do not establish blanket cross-platform equivalence.

Independent source review passed with no blocker.

Integration note

#9651 changes ArgSpec::parse_with from Fn to FnMut. This change exposes that existing helper and deliberately does not duplicate #9651's callback change. There is one adjacent-line textual conflict: preserve pub fn parse_with from this change and mut check: impl FnMut from #9651. The receive parser remains compatible with either callback signature.

AI assistance

The source investigation, patch, reference probes, and this draft were prepared with OpenAI Codex assistance under the maintainer's direction. Human review is requested before merge.

Reuse keyword parsing for receive buffers, preserve conversion ordering and argument lifetimes, and avoid zero-length receive waits.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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