jcs
/subtext
/amendments
/502
zmodem: Set ZP0 to something in ZRINIT
When left at zero, the sender may just send us way more data than we
can handle and it'll timeout. By sending a reasonble block size, the
sender will have to wait for us to ACK along the way.
Fixes NetRunner 2.0B21, also tested with SyncTERM.
jcs made amendment 502 about 1 year ago
--- zmodem.c Sun Mar 12 20:52:53 2023
+++ zmodem.c Mon May 1 21:52:46 2023
@@ -202,7 +202,7 @@ hdrtype_name(short type)
if (type >= ZRQINIT && type <= ZSTDERR)
return (s[type]);
- return NULL;
+ return "";
}
static const char *
@@ -232,7 +232,7 @@ state_name(struct zmodem_session *zs)
if (zs->ZState >= Z_RecvInit && zs->ZState <= Z_End)
return (s[zs->ZState]);
- return NULL;
+ return "";
}
#endif /* ZMODEM_DEBUG */
@@ -407,11 +407,11 @@ ZPutBin(struct zmodem_session *zs, short *i, unsigned
switch (b) {
case 0x0D: // CR
case 0x8D: // CR | 0x80
- // if (zs->CtlEsc || ((zs->LastSent & 0x7f) == '@')) {
+ if (zs->CtlEsc || ((zs->LastSent & 0x7f) == '@')) {
zs->PktOut[*i] = ZDLE;
(*i)++;
b = b ^ 0x40;
- // }
+ }
break;
case 0x0A: // LF
case 0x10: // DLE
@@ -497,8 +497,9 @@ void
ZSendRInit(struct zmodem_session *zs)
{
zs->Pos = 0;
- ZStoHdr(zs, 0);
- zs->TxHdr[ZF0] = CANFC32 | CANFDX; // | CANOVIO;
+ /* we only want this much data thrown at us before we ack it */
+ ZStoHdr(zs, ZMODEM_BLOCK_SIZE * 2);
+ zs->TxHdr[ZF0] = CANFC32 | CANFDX;
if (zs->CtlEsc)
zs->TxHdr[ZF0] = zs->TxHdr[ZF0] | ESCCTL;
ZShHdr(zs, ZRINIT);
@@ -1081,11 +1082,20 @@ ZParseHdr(struct zmodem_session *zs)
break;
case ZEOF:
if (zs->Pos != ZRclHdr(zs)) {
+#ifdef ZMODEM_DEBUG
+ logger_printf("[%s] ZParseHdr: ZEOF but pos %ld != received %ld",
+ state_name(zs), zs->Pos, ZRclHdr(zs));
+#endif
ZSendRPOS(zs);
return;
}
if (zs->file) {
+#ifdef ZMODEM_DEBUG
+ logger_printf("[%s] ZParseHdr: finished with file at %ld, "
+ "closing", state_name(zs), zs->Pos);
+#endif
+ ZSendRPOS(zs);
if (zs->CRRecv) {
zs->CRRecv = false;
fwrite("\r", 1, 1, zs->file);