Skip to content

fix(network): bsdsocket event monitor and blocking-call fixes - #2334

Merged
midwan merged 6 commits into
masterfrom
fix/bsdsocket-review-findings
Sep 15, 2026
Merged

midwan merged 6 commits into
masterfrom
fix/bsdsocket-review-findings

Conversation

@midwan

@midwan midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes three bsdsocket.library host-layer bugs found by an automated review of the amiberry-lite backport PR (BlitterStudio/amiberry-lite#39). All three exist in current master.

  • bsdthr_blockingstuff: EINTR lost on aborted blocking calls. When a blocking send/recv/accept/connect is aborted via sockabort, the code sets errno = EINTR, but the unconditional errno = saved_errno at function exit overwrites it with the pre-select EAGAIN/EINPROGRESS. bsdlib_threadfunc() then maps the wrong errno to the Amiga side, so callers retry an operation that was explicitly interrupted.
  • Unconnected datagram sockets get no events. register_socket_events() derives connected from getpeername(), which fails with ENOTCONN on bound-but-unconnected UDP sockets. The monitor gates REP_READ/REP_WRITE/REP_CLOSE polling on connected, so a UDP server using SO_EVENTMASK never receives read notifications. Datagrams are now detected via SO_TYPE and treated as always ready for readiness polling.
  • False REP_CLOSE on UDP. peek_socket() maps recv() == 0 to EOF. On a connected UDP socket a zero-length datagram is valid data, but it was reported as REP_CLOSE. EOF semantics are now applied to stream sockets only.

Verification

  • Clean build (macOS, Apple Silicon)
  • AROS boot with socket_emu=true: no errors, clean exit on SIGTERM

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T19:27:27.510528Z f055642 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 111289851d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/osdep/bsdsocket_host.cpp
- bsdthr_blockingstuff: keep EINTR when a blocking call was aborted
  via sockabort; the unconditional saved_errno restore reported
  EAGAIN/EINPROGRESS so callers retried aborted operations
- event monitor: treat unconnected datagram sockets as ready for
  read/write readiness polling (getpeername fails with ENOTCONN on
  bound UDP sockets, which blocked all event delivery)
- event monitor: recv() returning 0 is EOF only on stream sockets;
  on UDP it is a valid zero-length datagram and must not fire
  REP_CLOSE
@midwan
midwan force-pushed the fix/bsdsocket-review-findings branch from 1112898 to fadcaa1 Compare September 15, 2026 18:43
@midwan

midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fadcaa1a45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/osdep/bsdsocket_host.cpp Outdated
Marking unconnected datagram sockets connected=true let the monitor's
REP_CONNECT fallback post a false connect-completed event when a broad
mask (e.g. REP_ALL) included REP_CONNECT. dgram now relaxes only the
read/write readiness gates; connected keeps the getpeername() result.
trap_put_string() writes through the terminating NUL and ignores its
maxlen on the direct-memory path, so a hostname longer than the
caller's buffer spilled past the validated namelen range into
adjacent guest memory. Truncate to namelen-1 plus NUL and copy with
the strictly bounded trap_put_bytes().
@midwan

midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f91940f5c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/osdep/bsdsocket_host.cpp Outdated
REP_CLOSE polling added datagram sockets to readfds, but a queued
datagram keeps select() readable forever with no event able to fire
(REP_CLOSE never fires on datagrams, REP_READ not requested or
already fired) — a permanent 10ms busy-poll. Datagram sockets have
no EOF; their readfds entry comes from the REP_READ gate, so
close-only polling is now stream-only.
@midwan

midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3720a198d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/osdep/bsdsocket_host.cpp
Comment thread src/osdep/bsdsocket_host.cpp
…RITE on datagrams

- REP_ACCEPT fired for any readable socket whose mask contained it
  (e.g. REP_ALL), sending datagram and connected sockets down an
  invalid accept path. accept-ready is now tracked via SO_ACCEPTCONN
  at registration and both the readfds gate and the event handler
  require it — this also stops the spurious REP_ACCEPT a connected
  TCP socket with REP_ALL previously got on incoming data.
- host_setsockopt force-adds REP_WRITE to REP_CONNECT requests
  (dynAMIte implicit-writability workaround). On an unconnected
  datagram socket that forced bit fired an unrequested write
  notification; the force is now stream-only.
@midwan

midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b67567688d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/osdep/bsdsocket_host.cpp
REP_ACCEPT gating snapshots SO_ACCEPTCONN at registration, so a
server arming SO_EVENTMASK before listen() never reported
accept-ready: host_listen() now updates the monitor entry on
success, and listen-before-mask orderings query live state at
registration anyway.
@midwan

midwan commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: f0556423ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@midwan
midwan merged commit e5dafee into master Sep 15, 2026
27 of 28 checks passed
@midwan
midwan deleted the fix/bsdsocket-review-findings branch September 15, 2026 19:29
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