diff -U 3 -H -d -r -N -- temp_original//gst/udp/gstmultiudpsink.c temp-gst-good//gst/udp/gstmultiudpsink.c
--- temp_original//gst/udp/gstmultiudpsink.c	2011-06-27 10:51:28.000000000 +0100
+++ temp-gst-good//gst/udp/gstmultiudpsink.c	2011-08-22 16:53:14.084769001 +0100
@@ -41,6 +41,15 @@
 #include <errno.h>
 #include <string.h>
 
+/*#define SENDTO_DEBUG */
+#ifdef SENDTO_DEBUG
+#include <sys/time.h>
+#endif
+
+#define SENDTO_NON_BLOCK
+#define	MAX_SENDTO_RETRIES 12 // maximum 5ms before gstreamer crashes out on block
+#define	SENDTO_RETRY_INTERVAL_MS 300
+
 GST_DEBUG_CATEGORY_STATIC (multiudpsink_debug);
 #define GST_CAT_DEFAULT (multiudpsink_debug)
 
@@ -381,9 +390,9 @@
 {
 #ifdef G_OS_WIN32
   /* Windows doesn't seem to have an EAGAIN for sockets */
-  return WSAGetLastError () == WSAEINTR;
+  return ((WSAGetLastError () == WSAEINTR) || (WSAGetLastError() == WSAECONNREFUSED));
 #else
-  return errno == EINTR || errno == EAGAIN;
+  return ((errno == EINTR) || (errno == EAGAIN) || ( errno == ECONNREFUSED) );
 #endif
 }
 
@@ -421,6 +430,31 @@
 #endif
 }
 
+#ifdef SENDTO_DEBUG
+static int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y){
+       /* Perform the carry for the later subtraction by updating y. */
+       if (x->tv_usec < y->tv_usec) {
+         int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
+         y->tv_usec -= 1000000 * nsec;
+         y->tv_sec += nsec;
+       }
+       if (x->tv_usec - y->tv_usec > 1000000) {
+         int nsec = (x->tv_usec - y->tv_usec) / 1000000;
+         y->tv_usec += 1000000 * nsec;
+         y->tv_sec -= nsec;
+       }
+
+       /* Compute the time remaining to wait.
+          tv_usec is certainly positive. */
+       result->tv_sec = x->tv_sec - y->tv_sec;
+       result->tv_usec = x->tv_usec - y->tv_usec;
+
+       /* Return 1 if result is negative. */
+       return x->tv_sec < y->tv_sec;
+}
+#endif
+
+
 static GstFlowReturn
 gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
 {
@@ -429,6 +463,11 @@
   guint8 *data;
   GList *clients;
   gint len;
+#ifdef SENDTO_DEBUG
+  struct timeval first,second,third;
+  gettimeofday(&first,NULL);
+#endif
+  int fail_count =0;
 
   sink = GST_MULTIUDPSINK (bsink);
 
@@ -448,7 +487,7 @@
     client = (GstUDPClient *) clients->data;
     no_clients++;
     GST_LOG_OBJECT (sink, "sending %d bytes to client %p", size, client);
-
+    fail_count = 0;
     while (TRUE) {
       len = gst_udp_get_sockaddr_length (&client->theiraddr);
 
@@ -470,6 +509,14 @@
           g_free (errormessage);
           break;
         }
+        else {
+			fail_count++;
+			if (fail_count > MAX_SENDTO_RETRIES) {
+			GST_WARNING_OBJECT (sink, "Slow UDP sink socket (tried %d times) - Dropping data ",fail_count);
+						break;
+					}
+					usleep(SENDTO_RETRY_INTERVAL_MS);
+				}
       } else {
         num++;
         client->bytes_sent += ret;
@@ -483,7 +530,12 @@
 
   GST_LOG_OBJECT (sink, "sent %d bytes to %d (of %d) clients", size, num,
       no_clients);
-
+#ifdef SENDTO_DEBUG		
+		gettimeofday(&second, NULL);
+		timeval_subtract(&third, &second, &first);
+        //if ( (third.tv_usec > 2000) || (third.tv_sec > 0))
+		printf("INFO: sendto time  secs %ld usecs %ld\n", third.tv_sec, third.tv_usec);
+#endif
   return GST_FLOW_OK;
 }
 
@@ -857,6 +909,16 @@
     sink->sock = sink->sockfd;
     sink->externalfd = TRUE;
   }
+  
+
+#ifdef SENDTO_NON_BLOCK
+  /* Sendto clocks for >3s when clients dissapear -crashing the gstreamer pipeline
+   * poll/epoll or I_CANPUT ioctls don't work well in detecting port issues
+   * so we use send use sendto in non-blok mode and retry for less then gstreamer pipeline's
+   * stall threshold (about 5ms). Other cleints are temporarilly stalled when one client dissapears 
+   */
+  	fcntl(sink->sock,F_SETFL,O_NONBLOCK);
+#endif
 
   bc_val = 1;
   if (setsockopt (sink->sock, SOL_SOCKET, SO_BROADCAST, &bc_val,
