- if (tcp->length_bytes_read < LENGTH_BYTES) {
- len = recv(tcp->socket, tcp->length_buf + tcp->length_bytes_read,
- LENGTH_BYTES - tcp->length_bytes_read, 0);
- if (len < 0) {
+/* Receive response data. tcp-rigol mode. */
+static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
+{
+ struct scpi_tcp *tcp = priv;
+ uint8_t *rdptr;
+ size_t rdlen, rcvd;
+ int ret;
+
+ /*
+ * Rigol mode, chunks are prefixed by a length spec.
+ * Get more length bytes when we haven't read them before.
+ * Return "zero length read" if length has yet to get received.
+ * Otherwise get chunk length from length bytes buffer.
+ */
+ if (tcp->length_bytes_read < sizeof(tcp->length_buf)) {
+ rdptr = &tcp->length_buf[tcp->length_bytes_read];
+ rdlen = sizeof(tcp->length_buf) - tcp->length_bytes_read;
+ ret = sr_tcp_read_bytes(tcp->tcp_dev, rdptr, rdlen, FALSE);
+ if (ret < 0) {