- if (err == ERR_OK) {
- outputf("RFB: attempting send %d", sndlength);
- } else {
- outputf("RFB: send error %d", err);
+ state->chunk_actually_sent = 1;
+
+ /* Send a header */
+ hdr.msgtype = 0;
+ state->chunk_bytes_sent = 0;
+ hdr.nrects = htons(1);
+ hdr.xpos = htons(state->chunk_xpos);
+ hdr.ypos = htons(state->chunk_ypos);
+ hdr.width = htons(state->chunk_width);
+ hdr.height= htons(state->chunk_height);
+ hdr.enctype = htonl(0);
+
+ err = tcp_write(pcb, &hdr, sizeof(hdr), TCP_WRITE_FLAG_COPY);
+
+ if (err != ERR_OK) {
+ if (err != ERR_MEM)
+ outputf("RFB: header send error %d", err);
+
+ /* Try again later. */
+ return;
+ }
+
+ state->send_state = SST_DATA;
+
+ /* Snag the data. */
+ fb->copy_pixels(state->blockbuf,
+ state->chunk_xpos, state->chunk_ypos,
+ state->chunk_width, state->chunk_height);
+
+ /* FALL THROUGH to SST_DATA */
+
+ case SST_DATA:
+
+ bytes_left = 4 * state->chunk_width * state->chunk_height - state->chunk_bytes_sent;
+
+ if (bytes_left == 0) {
+ state->send_state = SST_HEADER;
+ state->checksums[state->chunk_xnum][state->chunk_ynum] = state->chunk_checksum;
+ if (advance_chunk(state))
+ return;