static void set_current_request (SoupConnectionPrivate *priv, SoupMessage *req) { g_return_if_fail (priv->cur_req == NULL); stop_idle_timer (priv); soup_message_set_io_status (req, SOUP_MESSAGE_IO_STATUS_RUNNING); priv->cur_req = req; if (priv->state == SOUP_CONNECTION_IDLE || req->method != SOUP_METHOD_CONNECT) priv->state = SOUP_CONNECTION_IN_USE; g_object_add_weak_pointer (G_OBJECT (req), (gpointer)&priv->cur_req); }
static void queue_message (SoupSession *session, SoupMessage *msg, SoupSessionCallback callback, gpointer user_data) { SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session); SoupMessageQueueItem *item; item = soup_message_queue_append (priv->queue, msg, callback, user_data); soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_QUEUED); g_signal_connect_after (msg, "finished", G_CALLBACK (message_finished), item); if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_NO_REDIRECT)) { soup_message_add_header_handler ( msg, "got_body", "Location", G_CALLBACK (redirect_handler), session); } g_signal_emit (session, signals[REQUEST_QUEUED], 0, msg); }
static void set_current_request (SoupConnection *conn, SoupMessage *req) { SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn); g_return_if_fail (priv->cur_req == NULL); g_object_freeze_notify (G_OBJECT (conn)); stop_idle_timer (priv); priv->unused_timeout = 0; soup_message_set_io_status (req, SOUP_MESSAGE_IO_STATUS_RUNNING); priv->cur_req = req; g_object_notify (G_OBJECT (conn), "message"); if (priv->state == SOUP_CONNECTION_IDLE || req->method != SOUP_METHOD_CONNECT) soup_connection_set_state (conn, SOUP_CONNECTION_IN_USE); g_object_add_weak_pointer (G_OBJECT (req), (gpointer)&priv->cur_req); g_object_thaw_notify (G_OBJECT (conn)); }
static void requeue_message (SoupSession *session, SoupMessage *msg) { soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_QUEUED); }
/** * soup_connection_disconnect: * @conn: a connection * * Disconnects @conn's socket and emits a %disconnected signal. * After calling this, @conn will be essentially useless. **/ void soup_connection_disconnect (SoupConnection *conn) { SoupConnectionPrivate *priv; g_return_if_fail (SOUP_IS_CONNECTION (conn)); priv = SOUP_CONNECTION_GET_PRIVATE (conn); if (!priv->socket) return; g_signal_handlers_disconnect_by_func (priv->socket, socket_disconnected, conn); soup_socket_disconnect (priv->socket); g_object_unref (priv->socket); priv->socket = NULL; /* Don't emit "disconnected" if we aren't yet connected */ if (priv->state < SOUP_CONNECTION_IDLE) return; priv->state = SOUP_CONNECTION_DISCONNECTED; if (priv->cur_req && priv->cur_req->status_code == SOUP_STATUS_IO_ERROR && priv->last_used != 0) { /* 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 * 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 * sending the message). So we want the message to get * tried again on a new connection. The only code path * that could have gotten us to this point is through * the call to io_cleanup() in * soup_message_io_finished(), and so all we need to * do to get the message requeued in this case is to * change its status. */ soup_message_cleanup_response (priv->cur_req); soup_message_set_io_status (priv->cur_req, 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. * * (Of course, it's also possible that the error in the * last_used != 0 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 * error, and eventually the message will be requeued onto a * fresh connection and get an error, at which point the error * will finally be returned to the caller.) */ /* NB: this might cause conn to be destroyed. */ g_signal_emit (conn, signals[DISCONNECTED], 0); }