Skip to content

Commit 0bd01e5

Browse files
authored
Fix a blocking recv() (#9)
Only call `recv()` to read the payload if there is one.
1 parent 51516db commit 0bd01e5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

NetSDR_Settings.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,12 @@ bool SoapyNetSDR::transaction( const unsigned char *cmd, size_t size,
313313
if ( (length < 2) || (length > (int)sizeof(data)) )
314314
return false;
315315

316-
length -= 2; /* subtract header size */
317-
318-
nbytes = recv(_tcp, (char *)&data[2], length, 0); /* read payload */
319-
if ( nbytes != length )
320-
return false;
321-
316+
length -= 2; /* subtract header size */
317+
if (length > 0) {
318+
nbytes = recv(_tcp, (char *)&data[2], length, 0); /* read payload if it's there */
319+
if ( nbytes != length )
320+
return false;
321+
}
322322
rx_bytes = 2 + length; /* header + payload */
323323
}
324324

0 commit comments

Comments
 (0)