From: Dan Winship Date: Tue, 18 Aug 2009 14:10:45 +0000 (-0400) Subject: Tweak SoupConnection handling a bit wrt "not yet used" connections. X-Git-Tag: LIBSOUP_2_27_91~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f10591c66c5465a8949fd7795441e673340533a0;p=platform%2Fupstream%2Flibsoup.git Tweak SoupConnection handling a bit wrt "not yet used" connections. Should help to avoid the "undead" connections described in bug 592084. --- diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c index 78ea311..dc9c0b1 100644 --- a/libsoup/soup-connection.c +++ b/libsoup/soup-connection.c @@ -78,7 +78,9 @@ static void clear_current_request (SoupConnection *conn); static void soup_connection_init (SoupConnection *conn) { - ; + SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn); + + priv->last_used = time (NULL); } static void @@ -285,6 +287,7 @@ start_idle_timer (SoupConnection *conn) { SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn); + priv->last_used = time (NULL); if (priv->idle_timeout > 0 && !priv->idle_timeout_src) { priv->idle_timeout_src = soup_add_timeout (priv->async_context, @@ -334,10 +337,8 @@ clear_current_request (SoupConnection *conn) if (!soup_message_is_keepalive (cur_req)) soup_connection_disconnect (conn); - else { - priv->last_used = time (NULL); + else soup_message_io_stop (cur_req); - } } } @@ -537,12 +538,10 @@ soup_connection_disconnect (SoupConnection *conn) if (priv->cur_req && priv->cur_req->status_code == SOUP_STATUS_IO_ERROR && - priv->last_used != 0) { + soup_connection_get_age (conn) > 5) { /* There was a message queued on this connection, but * the socket was closed while it was being sent. - * Since last_used is not 0, then that means at least - * one message was successfully sent on this - * connection before, and so the most likely cause of + * Since the connection is idle, the most likely cause of * the IO_ERROR is that the connection was idle for * too long and the server timed out and closed it * (and we didn't notice until after we started @@ -559,14 +558,14 @@ soup_connection_disconnect (SoupConnection *conn) SOUP_MESSAGE_IO_STATUS_QUEUED); } - /* If cur_req is non-NULL but priv->last_used is 0, then that - * means this was the first message to be sent on this - * connection, and it failed, so the error probably means that - * there's some network or server problem, so we let the - * IO_ERROR be returned to the caller. + /* If cur_req is non-NULL but the connection was NOT idle when + * it was sent, then that means this was the first message to + * be sent on this connection, and it failed, so the error + * probably means that there's some network or server problem, + * so we let the IO_ERROR be returned to the caller. * * (Of course, it's also possible that the error in the - * last_used != 0 case was because of a network/server problem + * idle-connection case was because of a network/server problem * too. It's even possible that the message crashed the * server. In this case, requeuing it was the wrong thing to * do, but presumably, the next attempt will also get an @@ -631,21 +630,12 @@ soup_connection_set_state (SoupConnection *conn, SoupConnectionState state) clear_current_request (conn); } -/** - * soup_connection_last_used: - * @conn: a #SoupConnection. - * - * Returns the last time a response was received on @conn. - * - * Return value: the last time a response was received on @conn, or 0 - * if @conn has not been used yet. - */ -time_t -soup_connection_last_used (SoupConnection *conn) +guint +soup_connection_get_age (SoupConnection *conn) { g_return_val_if_fail (SOUP_IS_CONNECTION (conn), FALSE); - return SOUP_CONNECTION_GET_PRIVATE (conn)->last_used; + return time (NULL) - SOUP_CONNECTION_GET_PRIVATE (conn)->last_used; } /** diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h index 2dc6754..6497a11 100644 --- a/libsoup/soup-connection.h +++ b/libsoup/soup-connection.h @@ -74,7 +74,7 @@ SoupURI *soup_connection_get_proxy_uri (SoupConnection *conn); SoupConnectionState soup_connection_get_state (SoupConnection *conn); void soup_connection_set_state (SoupConnection *conn, SoupConnectionState state); -time_t soup_connection_last_used (SoupConnection *conn); +guint soup_connection_get_age (SoupConnection *conn); void soup_connection_send_request (SoupConnection *conn, SoupMessage *req); diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index 1a778de..d841ca0 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -973,7 +973,7 @@ soup_session_cleanup_connections (SoupSession *session, state = soup_connection_get_state (conn); if (state == SOUP_CONNECTION_REMOTE_DISCONNECTED || (prune_idle && state == SOUP_CONNECTION_IDLE && - soup_connection_last_used (conn) > 0)) + soup_connection_get_age (conn) > 5)) conns = g_slist_prepend (conns, g_object_ref (conn)); } g_mutex_unlock (priv->host_lock);