Transfers: ZMODEM sends without waiting on a header's trailing XON, C-Kermit's capital names in lower case, YMODEM's end sooner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
Claude committed 2026-10-16 23:01:53 +00:00
1 parent ada1b39c62
commit 5e5af6952d
4 files changed
+25 -5

No files matched your search

@@ -510,7 +510,10 @@ class Kermit(
var reply = ByteArray(0)
when (r.type) {
'F' -> {
val name = decodeText(r.data)
val name = decodeText(r.data).let { n ->
// (a name sent "converted", all capitals, as C-Kermit does: back in lower case)
if (n.any { it.isLetter() } && n.none { it.isLowerCase() }) n.lowercase() else n
}
val (o, actual) = into.create(name, -1)
out = o.buffered()
current = actual
@@ -51,6 +51,16 @@ class TransferIo(private val send: (ByteArray) -> Unit) {
}
}
/** the next byte if one is waiting (left there), else -1: without waiting */
fun peek(): Int {
while (true) {
val c = cur
if (c != null && pos < c.size) return c[pos].toInt() and 0xff
cur = queue.poll() ?: return -1
pos = 0
}
}
/** whether bytes are waiting (without waiting for any) */
fun available(): Boolean = (cur?.let { pos < it.size } == true) || queue.isNotEmpty()
@@ -246,7 +246,7 @@ class XYModem(
val end = blockBytes(0, ByteArray(128), true)
for (attempt in 0 until 3) {
io.write(end)
if (answer(allowC = true) == ACK) return
if (answer(allowC = true, wait = 2_000) == ACK) return
}
}
@@ -328,8 +328,8 @@ class XYModem(
* an ACK for block 0 when [allowC] (receivers that ask for the data
* straight away)
*/
private fun answer(allowC: Boolean): Int {
val deadline = System.currentTimeMillis() + timeoutMs
private fun answer(allowC: Boolean, wait: Long = timeoutMs): Int {
val deadline = System.currentTimeMillis() + wait
while (true) {
val left = deadline - System.currentTimeMillis()
if (left <= 0) return NAK
@@ -550,7 +550,14 @@ class ZModem(
sendBin(Header.pos(ZDATA, r.pos))
var sinceAck = 0
while (true) {
// the receiver's word in between, if any: a ZRPOS (an error: back to it)
// the receiver's word in between, if any: a ZRPOS (an error: back to it).
// (what isn't the start of a header let go first: the XON, CR LF a hex header ends
// with, else it would be waited on as a header that never comes)
while (true) {
val c = io.peek()
if (c < 0 || c == ZPAD || c == ZDLE) break
io.read(0)
}
if (io.available()) {
val h = readHeaderOrNull()
when (h?.type) {