static void
soup_connection_init (SoupConnection *conn)
{
- ;
+ SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
+
+ priv->last_used = time (NULL);
}
static void
{
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,
if (!soup_message_is_keepalive (cur_req))
soup_connection_disconnect (conn);
- else {
- priv->last_used = time (NULL);
+ else
soup_message_io_stop (cur_req);
- }
}
}
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
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
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;
}
/**