Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / rtsp / gstrtspconnection.c
index 7bd1195..2de21b9 100644 (file)
  * @short_description: manage RTSP connections
  * @see_also: gstrtspurl
  *  
- * <refsect2>
- * <para>
  * This object manages the RTSP connection to the server. It provides function
  * to receive and send bytes and messages.
- * </para>
- * </refsect2>
  *  
  * Last reviewed on 2007-07-24 (0.10.14)
  */
@@ -596,6 +592,14 @@ do_connect (const gchar * ip, guint16 port, GstPollFD * fdout,
     getsockopt (fd, SOL_SOCKET, SO_ERROR, (char *) &errno, &len);
 #endif
     goto sys_error;
+  } else {
+#ifdef __APPLE__
+    /* osx wakes up select with POLLOUT if the connection is refused... */
+    socklen_t len = sizeof (errno);
+    getsockopt (fd, SOL_SOCKET, SO_ERROR, (char *) &errno, &len);
+    if (errno != 0)
+      goto sys_error;
+#endif
   }
 
   gst_poll_fd_ignored (fdset, fdout);
@@ -2273,7 +2277,9 @@ gst_rtsp_connection_receive (GstRTSPConnection * conn, GstRTSPMessage * message,
     if (gst_poll_fd_has_error (conn->fdset, conn->writefd))
       goto socket_error;
 
-    gst_poll_set_controllable (conn->fdset, FALSE);
+    /* once we start reading the wait cannot be controlled */
+    if (builder.state != STATE_START)
+      gst_poll_set_controllable (conn->fdset, FALSE);
   }
 
   /* we have a message here */
@@ -2486,16 +2492,30 @@ gst_rtsp_connection_next_timeout (GstRTSPConnection * conn, GTimeVal * timeout)
   gdouble elapsed;
   glong sec;
   gulong usec;
+  gint ctimeout;
 
   g_return_val_if_fail (conn != NULL, GST_RTSP_EINVAL);
   g_return_val_if_fail (timeout != NULL, GST_RTSP_EINVAL);
 
+  ctimeout = conn->timeout;
+  if (ctimeout >= 20) {
+    /* Because we should act before the timeout we timeout 5
+     * seconds in advance. */
+    ctimeout -= 5;
+  } else if (ctimeout >= 5) {
+    /* else timeout 20% earlier */
+    ctimeout -= ctimeout / 5;
+  } else if (ctimeout >= 1) {
+    /* else timeout 1 second earlier */
+    ctimeout -= 1;
+  }
+
   elapsed = g_timer_elapsed (conn->timer, &usec);
-  if (elapsed >= conn->timeout) {
+  if (elapsed >= ctimeout) {
     sec = 0;
     usec = 0;
   } else {
-    sec = conn->timeout - elapsed;
+    sec = ctimeout - elapsed;
     if (usec <= G_USEC_PER_SEC)
       usec = G_USEC_PER_SEC - usec;
     else