Skip to content

Keep the HTTPGET/TELNET socket handle in telnet_sock - #2

Open
JC-000 wants to merge 3 commits into
ristola:masterfrom
JC-000:fix/net-socket-handle
Open

JC-000 wants to merge 3 commits into
ristola:masterfrom
JC-000:fix/net-socket-handle

Conversation

@JC-000

@JC-000 JC-000 commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #1

net_tcp_connect saved the socket handle in ult_tmp and then called ult_read_status, which ends with sty ult_tmp. That left the status length (5 for 00,OK) in ult_tmp, so HTTPGET wrote to handle 5 and read from another handle, and TELNET stored 5 as telnet_sock. The firmware answers an unknown handle with EBADF, so neither command worked.

Changes

Three commits. The first is the bug fix and stands alone; the second builds on it (HTTPGET only gets as far as the READ once the handle is right); the third is independent:

  1. Save the handle to telnet_sock in net_tcp_connect before ult_read_status. HTTPGET's SOCK_WRITE and SOCK_READ use telnet_sock; TELNET no longer copies from ult_tmp.
  2. HTTPGET asks READ again while it answers empty (length $FFFF, no data), for up to about 5 seconds, timed on the CIA1 time-of-day clock because the jiffy clock doesn't run with interrupts off. Adds ult_tod_start/ult_tod_expired to the SDK and no-op versions to the VICE stub.
  3. hg_append doesn't terminate the request in dir_buffer, so ult_cmd_str sent stale bytes after it. Write a zero after the last piece.

Testing

Built with ACME (all 22 banks, cartconv to EasyFlash .crt). Ran on an Ultimate 64 Elite, with an HTTP server and a telnet server on a computer on the LAN. With the EasyFlash .crt running on an Ultimate 64 Elite, $DF1C-$DF1F read $F0, so the Command Interface isn't reachable (and I don't know how you run it against a real Ultimate). So I loaded bank 11 itself, unchanged, into RAM at $8000 and called HttpGetCmd and TelnetCmd from a small driver that sets BASIC's text pointer to the arguments. The cartridge bank switching is not exercised.

Results, same build for each row, on firmware where READ waits 40 ms and on firmware where READ does not wait:

before commit 1 commits 1+2
HTTPGET, server replies at once connection made, no request arrives, nothing printed request arrives, body printed (40 ms firmware); request arrives, no body printed (no-wait firmware) body printed in 0.4 s on both
HTTPGET, server replies after 1.5 s connection made, no request arrives, nothing printed request arrives, nothing printed on either body printed after 1.7 s on both
TELNET connects, banner not shown banner shown banner shown

Typed characters reaching the telnet server came through in 2 of 4 attempts with commits 1+2 (both on the no-wait firmware) and in 0 of 4 with commit 1 alone. TELNET's code is the same in both builds, so I don't know why; I haven't shown TELNET's write side reliably.

For commit 3, I filled dir_buffer with STALE-BYTES- before running HTTPGET and captured what the server received. Before: GET / HTTP/1.0\r\nHost: 192.168.1.10\r\n\r\nALE-BYTES-STALE-BYTES-.... After: GET / HTTP/1.0\r\nHost: 192.168.1.10\r\n\r\n and nothing else.

The retry is there because a UCI READ may answer empty before the server's reply has arrived; see the discussion in GideonZ/1541ultimate#1087.

Written with Claude Sonnet 5.5 in Claude Code.

JC-000 and others added 3 commits November 12, 2026 08:09
net_tcp_connect stored the handle in ult_tmp and then called
ult_read_status, which ends with 'sty ult_tmp' (the status byte count,
5 for "00,OK"). HTTPGET and TELNET therefore wrote to handle 5 and
HTTPGET read from whatever ult_read_data left in ult_tmp. Save the
handle to telnet_sock before ult_read_status and have HTTPGET's SOCK_WRITE
and SOCK_READ use it, as TELNET already does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An empty NET READ can answer at once with length $FFFF and no data, so
HTTPGET printed nothing when the server's reply had not arrived yet. Retry
the READ until data comes or about 5 seconds pass, timed on the CIA1
time-of-day clock (the jiffy clock does not run with interrupts off).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
hg_append copies pieces into dir_buffer but never terminates the result, so
ult_cmd_str sent the request followed by whatever stale bytes were already
in dir_buffer. Write the terminator after the last piece.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

HTTPGET and TELNET use the wrong socket handle

1 participant