summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
authorDon Ward2010-05-06 10:02:35 -0400
committerDon Ward2010-05-06 14:40:48 -0400
commita61fc516f5deeef67b48a704c5426c3969d36248 (patch)
tree2f872243de305a42b54bc6dcfc06774e397b5eba /gnuradio-core/src/lib
parent761a6f97a623e07f51743d70d1962c98b26bb599 (diff)
downloadgnuradio-a61fc516f5deeef67b48a704c5426c3969d36248.tar.gz
gnuradio-a61fc516f5deeef67b48a704c5426c3969d36248.tar.bz2
gnuradio-a61fc516f5deeef67b48a704c5426c3969d36248.zip
Flush pending errors in gr_udp_sink on disconnect()
On some systems (e.g., Debian/lenny) UDP errors are reported on the following send() or recv() call. To avoid having errors (such as ECONNREFUSED) from an old connection showing up on the first write to a new connection, we do a recv() on disconnect() to flush them. This may not work for all errors on all systems, but it works in some simple cases of interest.
Diffstat (limited to 'gnuradio-core/src/lib')
-rwxr-xr-xgnuradio-core/src/lib/io/gr_udp_sink.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc
index a9cb87a21..a323aef98 100755
--- a/gnuradio-core/src/lib/io/gr_udp_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc
@@ -251,6 +251,31 @@ void gr_udp_sink::disconnect()
(void) send( d_socket, NULL, 0, 0 ); // ignore errors
}
+ // Sending EOF can produce ERRCONNREFUSED errors that won't show up
+ // until the next send or recv, which might confuse us if it happens
+ // on a new connection. The following does a nonblocking recv to
+ // clear any such errors.
+ timeval timeout;
+ timeout.tv_sec = 0; // zero time for immediate return
+ timeout.tv_usec = 0;
+ fd_set readfds;
+ FD_ZERO(&readfds);
+ FD_SET(d_socket, &readfds);
+ int r = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
+ if(r < 0) {
+ #if SNK_VERBOSE
+ report_error("udp_sink/select",NULL);
+ #endif
+ }
+ else if(r > 0) { // call recv() to get error return
+ r = recv(d_socket, (char*)&readfds, sizeof(readfds), 0);
+ if(r < 0) {
+ #if SNK_VERBOSE
+ report_error("udp_sink/recv",NULL);
+ #endif
+ }
+ }
+
// Since I can't find any way to disconnect a datagram socket in Cygwin,
// we just leave it connected but disable sending.
#if 0