Receive buffers containing samples described by the metadata.
Receive handles fragmentation as follows: If the buffer has insufficient space to hold all samples that were received in a single packet over-the-wire, then the buffer will be completely filled and the implementation will hold a pointer into the remaining portion of the packet. Subsequent calls will load from the remainder of the packet, and will flag the metadata to show that this is a fragment. The next call to receive, after the remainder becomes exhausted, will perform an over-the-wire receive as usual. See the rx metadata fragment flags and offset fields for details.
This is a blocking call and will not return until the number of samples returned have been written into each buffer. Under a timeout condition, the number of samples returned may be less than the number of samples specified.
The one_packet option allows the user to guarantee that the call will return after a single packet has been processed. This may be useful to maintain packet boundaries in some cases.
Note on threading: recv() is not thread-safe, to avoid locking overhead. The application calling recv() is responsible for making sure that not more than one thread can call recv() on the same streamer at the same time. If there are multiple streamers, receiving from different sources, then those may be called from different threads simultaneously.
Error Handling
metadata
is a value that is set inside this function (effectively, a return value), and should be checked for potential error codes (see rx_metadata_t::error_code_t).
The most common error code when something goes wrong is an overrun (also referred to as overflow: error_code_t::ERROR_CODE_OVERFLOW). This error code means that the device produced data faster than the application could read, and various buffers filled up leaving no more space for the device to write data to. Note that an overrun on the device will not immediatiely show up when calling recv(). Depending on the device implementation, there may be many more valid samples available before the device had to stop writing samples to the FIFO. Only when all valid samples are returned to the call site will the error code be set to "overrun". When this happens, all valid samples have been returned to application where recv() was called. If the device is streaming continuously, it will reset itself when the FIFO is cleared, and recv() can be called again to retrieve new, valid data.
- Parameters
-
| buffs | a vector of writable memory to fill with samples |
| nsamps_per_buff | the size of each buffer in number of samples |
[out] | metadata | data to fill describing the buffer |
| timeout | the timeout in seconds to wait for a packet |
| one_packet | return after the first packet is received |
- Returns
- the number of samples received or 0 on error