- do {
- err = tcp_write(pcb, fb->fbaddr + state->update_pos, sndlength, 0);
- if (err == ERR_MEM) {
- outputf("RFB: ERR_MEM sending %d", sndlength);
- sndlength /= 2;
+ sndlength = left;
+ do {
+ err = tcp_write(pcb, fb->fbaddr + state->update_pos, sndlength, TCP_WRITE_FLAG_COPY /* The card can't DMA from there. */);
+ if (err == ERR_MEM) /* Back down until lwip says we've got space. */
+ sndlength /= 2;
+ } while (err == ERR_MEM && sndlength > 1);
+
+ if (err != ERR_OK) {
+ if (err != ERR_MEM)
+ outputf("RFB: send error %d", err);
+
+ /* We'll just give up for now and come back when we have space later. */
+ break;