- }
-
- 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;
+ do {
+ err = tcp_write(pcb, mbuf, sndlength, TCP_WRITE_FLAG_COPY /* This is my memory on the stack, thank you very much. */);
+ 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) {
+ /* We'll just give up for now and come back when we have space later. */
+ //outputf("RFB: send error %d", err);
+ break;