SoupConnectionState soup_connection_get_state (SoupConnection *conn) { SoupConnectionPrivate *priv; g_return_val_if_fail (SOUP_IS_CONNECTION (conn), SOUP_CONNECTION_DISCONNECTED); priv = SOUP_CONNECTION_GET_PRIVATE (conn); #ifdef G_OS_UNIX if (priv->state == SOUP_CONNECTION_IDLE) { GPollFD pfd; pfd.fd = soup_socket_get_fd (priv->socket); pfd.events = G_IO_IN; pfd.revents = 0; if (g_poll (&pfd, 1, 0) == 1) soup_connection_set_state (conn, SOUP_CONNECTION_REMOTE_DISCONNECTED); } #endif if (priv->state == SOUP_CONNECTION_IDLE && priv->unused_timeout && priv->unused_timeout < time (NULL)) soup_connection_set_state (conn, SOUP_CONNECTION_REMOTE_DISCONNECTED); return priv->state; }
static void snra_server_client_wrote_headers (SoupMessage * msg, SnraServerClient * client) { GList *cur; /* Pause the message so Soup doesn't do any more responding */ soup_server_pause_message (client->soup, msg); g_print ("client %u ready for traffic\n", client->conn_id); client->io = g_io_channel_unix_new (soup_socket_get_fd (client->socket)); g_io_channel_set_encoding (client->io, NULL, NULL); g_io_channel_set_buffered (client->io, FALSE); client->io_watch = g_io_add_watch (client->io, G_IO_IN | G_IO_HUP, (GIOFunc) (snra_server_client_io_cb), client); /* Send any pending messages */ while ((cur = client->pending_msgs)) { GList *next; PendingMsg *msg = (PendingMsg *) (cur->data); next = g_list_next (cur); snra_server_client_send_message (client, msg->body, msg->len); client->pending_msgs = g_list_delete_link (client->pending_msgs, cur); g_free (msg->body); g_free (msg); cur = next; } }
static void close_socket (SoupMessage *msg, gpointer user_data) { SoupSocket *sock = user_data; int sockfd; /* Actually calling soup_socket_disconnect() here would cause * us to leak memory, so just shutdown the socket instead. */ sockfd = soup_socket_get_fd (sock); #ifdef G_OS_WIN32 shutdown (sockfd, SD_SEND); #else shutdown (sockfd, SHUT_WR); #endif }
static void close_socket (SoupMessage *msg, gpointer user_data) { SoupSocket *sock = user_data; int sockfd; /* Actually calling soup_socket_disconnect() here would cause * us to leak memory, so just shutdown the socket instead. */ sockfd = soup_socket_get_fd (sock); #ifdef G_OS_WIN32 shutdown (sockfd, SD_SEND); #else shutdown (sockfd, SHUT_WR); #endif /* Then add the missing data to the message now, so SoupServer * can clean up after itself properly. */ soup_message_body_append (msg->response_body, SOUP_MEMORY_STATIC, "foo", 3); }