+ uint8_t *rdptr;
+ size_t rdlen, rcvd;
+ int ret;
+
+ /* Get another chunk of receive data. */
+ rdptr = (uint8_t *)buf;
+ rdlen = maxlen;
+ ret = sr_tcp_read_bytes(tcp->tcp_dev, rdptr, rdlen, FALSE);
+ if (ret < 0) {
+ sr_err("Receive error: %s", g_strerror(errno));
+ return SR_ERR;
+ }
+ rcvd = (size_t)ret;
+
+ /*
+ * Raw data mode (in contrast to Rigol mode). Prepare to answer
+ * the "completed" condition while the payload's length is not
+ * known. Pretend that the length buffer had been received.
+ * Assume that short reads correspond to the end of a response,
+ * while full reads of the caller specified size suggest that
+ * more data can follow.
+ */
+ tcp->length_bytes_read = LENGTH_BYTES;
+ tcp->response_length = rcvd < rdlen ? rcvd : rdlen + 1;
+ tcp->response_bytes_read = rcvd;