mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-22 22:41:30 +03:00
[project @ 2005-12-19 21:54:51 by bursa]
Fix busy polling in gtk build. svn path=/import/netsurf/; revision=1900
This commit is contained in:
parent
17aa1a3ff3
commit
ad13eb98af
@ -78,7 +78,7 @@ struct fetch {
|
||||
};
|
||||
|
||||
static const char * const user_agent = "NetSurf";
|
||||
static CURLM *curl_multi; /**< Global cURL multi handle. */
|
||||
CURLM *fetch_curl_multi; /**< Global cURL multi handle. */
|
||||
/** Curl handle with default options set; not used for transfers. */
|
||||
static CURL *fetch_blank_curl;
|
||||
static struct fetch *fetch_list = 0; /**< List of active fetches. */
|
||||
@ -121,8 +121,8 @@ void fetch_init(void)
|
||||
die("Failed to initialise the fetch module "
|
||||
"(curl_global_init failed).");
|
||||
|
||||
curl_multi = curl_multi_init();
|
||||
if (!curl_multi)
|
||||
fetch_curl_multi = curl_multi_init();
|
||||
if (!fetch_curl_multi)
|
||||
die("Failed to initialise the fetch module "
|
||||
"(curl_multi_init failed).");
|
||||
|
||||
@ -189,7 +189,7 @@ void fetch_quit(void)
|
||||
|
||||
curl_easy_cleanup(fetch_blank_curl);
|
||||
|
||||
codem = curl_multi_cleanup(curl_multi);
|
||||
codem = curl_multi_cleanup(fetch_curl_multi);
|
||||
if (codem != CURLM_OK)
|
||||
LOG(("curl_multi_cleanup failed: ignoring"));
|
||||
|
||||
@ -356,7 +356,7 @@ struct fetch * fetch_start(char *url, char *referer,
|
||||
goto failed;
|
||||
|
||||
/* add to the global curl multi handle */
|
||||
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
|
||||
codem = curl_multi_add_handle(fetch_curl_multi, fetch->curl_handle);
|
||||
assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM);
|
||||
|
||||
fetch->next = fetch_list;
|
||||
@ -491,7 +491,8 @@ void fetch_stop(struct fetch *f)
|
||||
|
||||
/* remove from curl multi handle */
|
||||
if (f->curl_handle) {
|
||||
codem = curl_multi_remove_handle(curl_multi, f->curl_handle);
|
||||
codem = curl_multi_remove_handle(fetch_curl_multi,
|
||||
f->curl_handle);
|
||||
assert(codem == CURLM_OK);
|
||||
}
|
||||
|
||||
@ -506,7 +507,7 @@ void fetch_stop(struct fetch *f)
|
||||
code = fetch_set_options(fetch);
|
||||
if (code == CURLE_OK)
|
||||
/* add to the global curl multi handle */
|
||||
codem = curl_multi_add_handle(curl_multi,
|
||||
codem = curl_multi_add_handle(fetch_curl_multi,
|
||||
fetch->curl_handle);
|
||||
|
||||
if (code == CURLE_OK && (codem == CURLM_OK ||
|
||||
@ -576,12 +577,12 @@ void fetch_poll(void)
|
||||
|
||||
/* do any possible work on the current fetches */
|
||||
do {
|
||||
codem = curl_multi_perform(curl_multi, &running);
|
||||
codem = curl_multi_perform(fetch_curl_multi, &running);
|
||||
assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM);
|
||||
} while (codem == CURLM_CALL_MULTI_PERFORM);
|
||||
|
||||
/* process curl results */
|
||||
curl_msg = curl_multi_info_read(curl_multi, &queue);
|
||||
curl_msg = curl_multi_info_read(fetch_curl_multi, &queue);
|
||||
while (curl_msg) {
|
||||
switch (curl_msg->msg) {
|
||||
case CURLMSG_DONE:
|
||||
@ -591,7 +592,7 @@ void fetch_poll(void)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
curl_msg = curl_multi_info_read(curl_multi, &queue);
|
||||
curl_msg = curl_multi_info_read(fetch_curl_multi, &queue);
|
||||
}
|
||||
|
||||
if (!fetch_list)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define _NETSURF_DESKTOP_FETCH_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "curl/curl.h"
|
||||
#include "netsurf/utils/config.h"
|
||||
|
||||
typedef enum {
|
||||
@ -34,6 +35,7 @@ struct form_successful_control;
|
||||
#endif
|
||||
|
||||
extern bool fetch_active;
|
||||
extern CURLM *fetch_curl_multi;
|
||||
|
||||
void fetch_init(void);
|
||||
struct fetch * fetch_start(char *url, char *referer,
|
||||
|
@ -5,14 +5,17 @@
|
||||
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE /* for strndup */
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <curl/curl.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "netsurf/content/content.h"
|
||||
#include "netsurf/content/fetch.h"
|
||||
#include "netsurf/desktop/401login.h"
|
||||
#include "netsurf/desktop/browser.h"
|
||||
#include "netsurf/desktop/gui.h"
|
||||
@ -21,6 +24,7 @@
|
||||
#include "netsurf/render/box.h"
|
||||
#include "netsurf/render/form.h"
|
||||
#include "netsurf/render/html.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/utf8.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
@ -68,7 +72,52 @@ void gui_init2(int argc, char** argv)
|
||||
|
||||
void gui_poll(bool active)
|
||||
{
|
||||
gtk_main_iteration_do(!active);
|
||||
CURLMcode code;
|
||||
fd_set read_fd_set, write_fd_set, exc_fd_set;
|
||||
int max_fd;
|
||||
GPollFD *fd_list[1000];
|
||||
unsigned int fd_count = 0;
|
||||
|
||||
if (active) {
|
||||
fetch_poll();
|
||||
FD_ZERO(&read_fd_set);
|
||||
FD_ZERO(&write_fd_set);
|
||||
FD_ZERO(&exc_fd_set);
|
||||
code = curl_multi_fdset(fetch_curl_multi,
|
||||
&read_fd_set,
|
||||
&write_fd_set,
|
||||
&exc_fd_set,
|
||||
&max_fd);
|
||||
assert(code == CURLM_OK);
|
||||
for (int i = 0; i <= max_fd; i++) {
|
||||
if (FD_ISSET(i, &read_fd_set)) {
|
||||
GPollFD *fd = malloc(sizeof *fd);
|
||||
fd->fd = i;
|
||||
fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
|
||||
g_main_context_add_poll(0, fd, 0);
|
||||
fd_list[fd_count++] = fd;
|
||||
}
|
||||
if (FD_ISSET(i, &write_fd_set)) {
|
||||
GPollFD *fd = malloc(sizeof *fd);
|
||||
fd->fd = i;
|
||||
fd->events = G_IO_OUT | G_IO_ERR;
|
||||
g_main_context_add_poll(0, fd, 0);
|
||||
fd_list[fd_count++] = fd;
|
||||
}
|
||||
if (FD_ISSET(i, &exc_fd_set)) {
|
||||
GPollFD *fd = malloc(sizeof *fd);
|
||||
fd->fd = i;
|
||||
fd->events = G_IO_ERR;
|
||||
g_main_context_add_poll(0, fd, 0);
|
||||
fd_list[fd_count++] = fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
gtk_main_iteration_do(true);
|
||||
for (unsigned int i = 0; i != fd_count; i++) {
|
||||
g_main_context_remove_poll(0, fd_list[i]);
|
||||
free(fd_list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user