I'm looking at the source code for GrOsmoSdr's rtl_tcp_source_f.cc, which is a GNU Radio source which reads interleaved I/Q data from TCP.
The work function looks like this:
int rtl_tcp_source_f::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
float *out = (float *) output_items[0];
ssize_t r = 0;
int bytesleft = noutput_items;
int index = 0;
int receivedbytes = 0;
while(bytesleft > 0) {
receivedbytes = recv(d_socket, (char*)&d_temp_buff[index], bytesleft, 0);
if(receivedbytes == -1 && !is_error(EAGAIN)){
fprintf(stderr, "socket error\n");
return -1;
}
bytesleft -= receivedbytes;
index += receivedbytes;
}
r = noutput_items;
for(int i=0; i<r; ++i)
out[i]=d_LUT[*(d_temp_buff+d_temp_offset+i)];
return r;
}
The buffer d_temp_buff
is set up in the constructor:
d_temp_buff = new unsigned char[d_payload_size];
where d_payload_size
is a constructor parameter which is passed in by configuration.
The work function reads exactly noutput_items
into d_temp_buff
. How is noutput_items
selected by Gnuradio in general, and how can this work function be sure that noutput_items <= d_payload_size
?