Add CUPS events as soon as possible when printing

CUPS events are added in prepare part of the main loop. These
events are initialized before their addition (#434318, #586466).
This commit is contained in:
Marek Kasik
2009-08-29 21:32:01 -04:00
committed by Matthias Clasen
parent 2d8b8e054a
commit 3b336186ee

View File

@ -803,6 +803,39 @@ request_password (gpointer data)
return FALSE;
}
static void
cups_dispatch_add_poll (GSource *source)
{
GtkPrintCupsDispatchWatch *dispatch;
GtkCupsPollState poll_state;
dispatch = (GtkPrintCupsDispatchWatch *) source;
poll_state = gtk_cups_request_get_poll_state (dispatch->request);
if (dispatch->request->http != NULL)
{
if (dispatch->data_poll == NULL)
{
dispatch->data_poll = g_new0 (GPollFD, 1);
if (poll_state == GTK_CUPS_HTTP_READ)
dispatch->data_poll->events = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
else if (poll_state == GTK_CUPS_HTTP_WRITE)
dispatch->data_poll->events = G_IO_OUT | G_IO_ERR;
else
dispatch->data_poll->events = 0;
#ifdef HAVE_CUPS_API_1_2
dispatch->data_poll->fd = httpGetFd (dispatch->request->http);
#else
dispatch->data_poll->fd = dispatch->request->http->fd;
#endif
g_source_add_poll (source, dispatch->data_poll);
}
}
}
static gboolean
cups_dispatch_watch_check (GSource *source)
{
@ -817,29 +850,7 @@ cups_dispatch_watch_check (GSource *source)
poll_state = gtk_cups_request_get_poll_state (dispatch->request);
if (dispatch->request->http != NULL)
{
if (dispatch->data_poll == NULL)
{
dispatch->data_poll = g_new0 (GPollFD, 1);
g_source_add_poll (source, dispatch->data_poll);
}
else
{
if (poll_state == GTK_CUPS_HTTP_READ)
dispatch->data_poll->events = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
else if (poll_state == GTK_CUPS_HTTP_WRITE)
dispatch->data_poll->events = G_IO_OUT | G_IO_ERR;
else
dispatch->data_poll->events = 0;
}
#ifdef HAVE_CUPS_API_1_2
dispatch->data_poll->fd = httpGetFd (dispatch->request->http);
#else
dispatch->data_poll->fd = dispatch->request->http->fd;
#endif
}
cups_dispatch_add_poll (source);
if (poll_state != GTK_CUPS_HTTP_IDLE && !dispatch->request->need_password)
if (!(dispatch->data_poll->revents & dispatch->data_poll->events))
@ -868,6 +879,7 @@ cups_dispatch_watch_prepare (GSource *source,
gint *timeout_)
{
GtkPrintCupsDispatchWatch *dispatch;
gboolean result;
dispatch = (GtkPrintCupsDispatchWatch *) source;
@ -876,7 +888,11 @@ cups_dispatch_watch_prepare (GSource *source,
*timeout_ = -1;
return gtk_cups_request_read_write (dispatch->request);
result = gtk_cups_request_read_write (dispatch->request);
cups_dispatch_add_poll (source);
return result;
}
static gboolean