[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4430 - gnuradio/branches/developers/trondeau/udp/gnur
From: |
trondeau |
Subject: |
[Commit-gnuradio] r4430 - gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io |
Date: |
Thu, 8 Feb 2007 08:26:17 -0700 (MST) |
Author: trondeau
Date: 2007-02-08 08:26:17 -0700 (Thu, 08 Feb 2007)
New Revision: 4430
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
Log:
break as soon as we get data
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-08 08:36:55 UTC (rev 4429)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-08 15:26:17 UTC (rev 4430)
@@ -28,11 +28,11 @@
#define SRC_VERBOSE 0
gr_udp_source::gr_udp_source(size_t itemsize, const char *ipaddr,
- unsigned short port, int mtu)
+ unsigned short port, int payload_size)
: gr_sync_block ("udp_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
- d_itemsize(itemsize), d_updated(false), d_mtu(mtu), d_residual(0),
d_temp_offset(0)
+ d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size),
d_residual(0), d_temp_offset(0)
{
// Set up the address stucture for the local address and port numbers
inet_aton(ipaddr, &d_ipaddr_local); // format IP address
@@ -42,17 +42,17 @@
d_sockaddr_local.sin_addr = d_ipaddr_local;
d_sockaddr_local.sin_port = d_port_local;
- d_temp_buff = new char[d_mtu]; // allow it to hold up to mtu bytes
+ d_temp_buff = new char[d_payload_size]; // allow it to hold up to
payload_size bytes
open();
}
gr_udp_source_sptr
gr_make_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, int mtu)
+ unsigned short port, int payload_size)
{
return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr,
- port, mtu));
+ port, payload_size));
}
gr_udp_source::~gr_udp_source ()
@@ -152,10 +152,10 @@
d_temp_offset = d_temp_offset+d_residual;
}
- while(bytes_received < total_bytes) {
+ while(1) {
// get the data into our output buffer and record the number of bytes
// This is a non-blocking call with a timeout set in the constructor
- r = recv(d_socket, d_temp_buff, d_mtu, 0); // get the entire MTU or the
rest of what's available
+ r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire
payload or the what's available
// Check if there was a problem; forget it if the operation just timed out
if(r == -1) {
@@ -163,7 +163,9 @@
#if SRC_VERBOSE
printf("UDP receive timed out\n");
#endif
- continue;
+
+ // Break here to allow the rest of the flow graph time to run and so
ctrl-C breaks
+ break;
}
else {
perror("udp_source");
@@ -173,6 +175,9 @@
else {
// Calculate the number of bytes we can take from the buffer in this call
nbytes = std::min(r, total_bytes-bytes_received);
+
+ // adjust the total number of bytes we have to round down to nearest
integer of an itemsize
+ nbytes -= ((bytes_received+nbytes) % d_itemsize);
// copy the number of bytes we want to look at here
memcpy(out, d_temp_buff, nbytes);
@@ -186,8 +191,8 @@
// increment the pointer
out += nbytes;
- // break here
// Immediately return when data comes in
+ break;
}
#if SNK_VERBOSE
@@ -196,10 +201,11 @@
}
#if SRC_VERBOSE
- printf("Total Bytes Received: %d (noutput_items=%d)\n", bytes_received,
noutput_items);
+ printf("Total Bytes Received: %d (bytes_received / noutput_items = %d /
%d)\n",
+ bytes_received, bytes_received, noutput_items);
#endif
- // return biggest legal increment (not fractional)
- return noutput_items;
+ // bytes_received is already set to some integer multiple of itemsize
+ return bytes_received/d_itemsize;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4430 - gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io,
trondeau <=