Skip to content

Commit ed96d7e

Browse files
authored
Discard only what's in _fifo, don't wait for more to arrive. (#1052)
* Discard only what's in _fifo, don't wait for more to arrive. * [atari] Don't forget to sync occasionally during write.
1 parent 59d1de0 commit ed96d7e

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

lib/bus/sio/NetSIO.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void NetSIO::begin(std::string host, int port, int baud)
5252
end();
5353
}
5454

55+
discard_timeout_ms = 0;
56+
5557
_baud = baud;
5658
_resume_time = 0;
5759
setHost(host, port);
@@ -565,28 +567,61 @@ void NetSIO::updateFIFO()
565567
return;
566568
}
567569

570+
void NetSIO::handle_write_sync(uint8_t c)
571+
{
572+
// handle pending sync request
573+
if (_sync_write_size < 0)
574+
{
575+
// SYNC RESPONSE
576+
// send byte (should be ACK/NAK) bundled in sync response
577+
sendSyncResponse(NETSIO_ACK_SYNC, c, 0);
578+
return;
579+
}
580+
else
581+
{
582+
// sio_late_ack() was not from whatever reason followed by bus_to_peripheral()
583+
Debug_println("Warn: NetSIO late ACK without bus_to_peripheral");
584+
// send late ACK byte
585+
sendSyncResponse(NETSIO_ACK_SYNC, _sync_ack_byte, _sync_write_size);
586+
}
587+
588+
return;
589+
}
590+
568591
size_t NetSIO::dataOut(const void *buffer, size_t size)
569592
{
570593
int result;
571594
int to_send;
572595
int txbytes = 0;
573596
uint8_t txbuf[513];
597+
uint8_t *ptr = (uint8_t *) buffer;
574598

575599
if (!_initialized)
576600
return 0;
577601

578-
while (txbytes < size)
602+
if (size && _sync_request_num >= 0)
603+
{
604+
handle_write_sync(ptr[0]);
605+
ptr++;
606+
size--;
607+
}
608+
609+
while (size)
579610
{
580611
// send block
581-
to_send = ((size-txbytes) > sizeof(txbuf)-1) ? sizeof(txbuf)-1 : (size-txbytes);
612+
to_send = std::min(size, sizeof(txbuf) - 1);
582613
txbuf[0] = NETSIO_DATA_BLOCK;
583-
memcpy(txbuf+1, ((uint8_t *)buffer)+txbytes, to_send);
614+
memcpy(txbuf+1, ptr+txbytes, to_send);
584615
// ? calculate credit based on amount of data ?
585616
if (!wait_for_credit(1))
586617
break;
587618
result = write_sock(txbuf, to_send+1);
588619
if (result > 0)
589-
txbytes += result-1;
620+
{
621+
result--;
622+
txbytes += result;
623+
size -= result;
624+
}
590625
else if (result < 0)
591626
break;
592627
}

lib/bus/sio/NetSIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class NetSIO : public IOChannel
7171
// flow control
7272
int _credit;
7373

74+
void handle_write_sync(uint8_t c);
75+
7476
protected:
7577
void suspend(int ms=5000);
7678
bool resume_test();

0 commit comments

Comments
 (0)