Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/33eebb9aaf94539557a1d86675d01a7b9d699366
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/33eebb9aaf94539557a1d86675d01a7b9d699366
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/33eebb9aaf94539557a1d86675d01a7b9d699366

The branch, jmb/ievent has been created
        at  33eebb9aaf94539557a1d86675d01a7b9d699366 (commit)

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=33eebb9aaf94539557a1d86675d01a7b9d699366
commit 33eebb9aaf94539557a1d86675d01a7b9d699366
Author: John-Mark Bell <[email protected]>
Commit: John-Mark Bell <[email protected]>

    RISC OS: use Internet event
    
    Enable the Internet event for our sockets and convert it into a
    pollword update. This allows us to ditch the schedule-based fetch
    path and take the same one as we do on other platforms. This also
    allows us to refactor the main poll loop such that we need only
    poll idle while waiting for things to happen (once something has
    happened, we poll aggressively until there are no non-pollword
    events left).

diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c
index 83d70a7..b8bccf0 100644
--- a/content/fetchers/curl.c
+++ b/content/fetchers/curl.c
@@ -37,6 +37,7 @@
 #include <string.h>
 #include <strings.h>
 #include <time.h>
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 
 #include <libwapcaplet/libwapcaplet.h>
@@ -1798,6 +1799,29 @@ fetch_curl_debug(CURL *handle,
 
 
 /**
+ * Callback function to set arbitrary socket options
+ */
+static int fetch_curl_sockopt(void *clientp, curl_socket_t curlfd,
+               curlsocktype purpose)
+{
+       (void) clientp;
+
+//XXX: indirect through fetch vtable?
+#ifdef riscos
+       if (purpose == CURLSOCKTYPE_IPCXN) {
+               int one = 1;
+               ioctl(curlfd, FIOASYNC, &one);
+       }
+#else
+       (void) curlfd;
+       (void) purpose;
+#endif
+
+       return CURL_SOCKOPT_OK;
+}
+
+
+/**
  * Callback function for cURL.
  */
 static size_t fetch_curl_data(char *data, size_t size, size_t nmemb, void *_f)
@@ -2052,6 +2076,7 @@ nserror fetch_curl_register(void)
        SETOPT(CURLOPT_LOW_SPEED_TIME, 180L);
        SETOPT(CURLOPT_NOSIGNAL, 1L);
        SETOPT(CURLOPT_CONNECTTIMEOUT, nsoption_uint(curl_fetch_timeout));
+       SETOPT(CURLOPT_SOCKOPTFUNCTION, fetch_curl_sockopt);
 
        if (nsoption_charp(ca_bundle) &&
            strcmp(nsoption_charp(ca_bundle), "")) {
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index 1a2b944..190aacb 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -38,6 +38,7 @@
 #include <oslib/osbyte.h>
 #include <oslib/osmodule.h>
 #include <oslib/osfscontrol.h>
+#include <oslib/socket.h>
 
 #include "utils/utils.h"
 #include "utils/nsoption.h"
@@ -57,6 +58,7 @@
 #include "desktop/save_complete.h"
 #include "desktop/hotlist.h"
 #include "content/backing_store.h"
+#include "content/fetch.h"
 
 #include "riscos/gui.h"
 #include "riscos/bitmap.h"
@@ -113,11 +115,14 @@ static const char *task_name = "NetSurf";
 
 ro_gui_drag_type gui_current_drag_type;
 wimp_t task_handle; /**< RISC OS wimp task handle. */
-static clock_t gui_last_poll; /**< Time of last wimp_poll. */
 osspriteop_area *gui_sprites; /**< Sprite area containing pointer and hotlist 
sprites */
 
 #define DIR_SEP ('.')
 
+static void *pollword;
+static bool eventv_claimed;
+static bool internet_event_enabled;
+
 /**
  * Accepted wimp user messages.
  */
@@ -388,6 +393,16 @@ static void ro_gui_cleanup(void)
        xhourglass_off();
        /* Uninstall NetSurf-specific fonts */
        xos_cli("FontRemove NetSurf:Resources.Fonts.");
+       if (internet_event_enabled) {
+               xos_byte(osbyte_DISABLE_EVENT, Event_Internet, 0, NULL, NULL);
+       }
+       if (eventv_claimed) {
+               xos_release(EventV, (asm_routine) (((uintptr_t) pollword) + 4),
+                       pollword);
+       }
+       if (pollword != NULL) {
+               xosmodule_free(pollword);
+       }
 }
 
 
@@ -1114,6 +1129,44 @@ static bool ro_gui__os_alpha_sprites_supported(void)
 }
 
 /**
+ * Set up internet event handling
+ */
+static os_error *ro_gui_init_internet_event(void)
+{
+       static const uint32_t event_handler_code[] = {
+               0x00000000, // pollword value
+               0xE3300013, // TEQ r0, #Event_Internet
+               0x11A0F00E, // MOVNE pc, lr
+               0xE59C5000, // LDR r5, [r12]
+               0xE2855001, // ADD r5, r5, #1
+               0xE58C5000, // STR r5, [r12]
+               0xE1A0F00E, // MOV pc, lr
+       };
+       os_error *error;
+
+       error = xosmodule_alloc(sizeof(event_handler_code), &pollword);
+       if (error != NULL)
+               return error;
+       memcpy(pollword, event_handler_code, sizeof(event_handler_code));
+       error = xos_synchronise_code_areas(os_GIVEN_CODE_RANGE,
+                       (asm_routine) (((uintptr_t) pollword) + 4),
+                       (asm_routine) (((uintptr_t) pollword) +
+                               sizeof(event_handler_code) - 4));
+       if (error != NULL)
+               return error;
+       error = xos_claim(EventV, (asm_routine) (((uintptr_t) pollword) + 4),
+                       pollword);
+       if (error != NULL)
+               return error;
+       eventv_claimed = true;
+       error = xos_byte(osbyte_ENABLE_EVENT, Event_Internet, 0, NULL, NULL);
+       if (error != NULL)
+               return error;
+       internet_event_enabled = true;
+       return NULL;
+}
+
+/**
  * Initialise the RISC OS specific GUI.
  *
  * \param argc The number of command line arguments.
@@ -1214,6 +1267,14 @@ static nserror gui_init(int argc, char** argv)
        urldb_load(nsoption_charp(url_path));
        urldb_load_cookies(nsoption_charp(cookie_file));
 
+       /* Setup Internet event handling (must be after atexit) */
+       error = ro_gui_init_internet_event();
+       if (error != NULL) {
+               NSLOG(netsurf, INFO, "init_internet_event: 0x%x: %s",
+                     error->errnum, error->errmess);
+               die(error->errmess);
+       }
+
        /* Initialise with the wimp */
        error = xwimp_initialise(wimp_VERSION_RO38, task_name,
                        PTR_WIMP_MESSAGE_LIST(&task_messages), 0,
@@ -1837,6 +1898,13 @@ static void ro_gui_handle_event(wimp_event_no event, 
wimp_block *block)
                                ro_gui_scroll(&(block->scroll));
                        break;
 
+               case wimp_POLLWORD_NON_ZERO:
+                       /* simply reset pollword */
+                       if (pollword != NULL) {
+                               *((uint32_t *) pollword) = 0;
+                       }
+                       break;
+
                case wimp_USER_MESSAGE:
                case wimp_USER_MESSAGE_RECORDED:
                case wimp_USER_MESSAGE_ACKNOWLEDGE:
@@ -1853,44 +1921,54 @@ static void riscos_poll(void)
 {
        wimp_event_no event;
        wimp_block block;
-       const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN | 
wimp_SAVE_FP;
-       os_t track_poll_offset;
+       const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN |
+               wimp_GIVEN_POLLWORD | wimp_SAVE_FP;
+       os_t t, track_poll_offset;
 
-       /* Poll wimp. */
-       xhourglass_off();
-       track_poll_offset = ro_mouse_poll_interval();
-       if (sched_active || (track_poll_offset > 0)) {
-               os_t t = os_read_monotonic_time();
+       /* Drain pending non-pollword events until the first NULL event */
+       do {
+               xhourglass_off();
+               event = wimp_poll(wimp_MASK_POLLWORD | mask, &block, pollword);
+               xhourglass_on();
 
-               if (track_poll_offset > 0) {
-                       t += track_poll_offset;
-               } else {
-                       t += 10;
-               }
+               ro_gui_handle_event(event, &block);
+       } while (event != wimp_NULL_REASON_CODE);
 
-               if (sched_active && (sched_time - t) < 0) {
-                       t = sched_time;
-               }
+       /* Redraw window contents */
+       ro_gui_window_update_boxes();
+
+       /* Run scheduled callbacks, if any */
+       schedule_run();
+
+       /* Drive any active fetches. */
+       {
+               fd_set read_fd_set, write_fd_set, exc_fd_set;
+               int max_fd;
+
+               fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &max_fd);
+       }
 
-               event = wimp_poll_idle(mask, &block, t, 0);
+       /* Poll wimp in the ordinary way. */
+       xhourglass_off();
+       t = os_read_monotonic_time();
+       track_poll_offset = ro_mouse_poll_interval();
+       /* Work out how long we're prepared to wait for an event */
+       if (track_poll_offset > 0) {
+               t += track_poll_offset;
+       } else if (sched_active) {
+               t += 10;
        } else {
-               event = wimp_poll(wimp_MASK_NULL | mask, &block, 0);
+               t += 100;
        }
+       /* And then clamp that to min(sched_time, t) */
+       if (sched_active && (sched_time - t) < 0) {
+               t = sched_time;
+       }
+
+       event = wimp_poll_idle(mask, &block, t, pollword);
 
        xhourglass_on();
-       gui_last_poll = clock();
        ro_gui_handle_event(event, &block);
-
-       /* Only run scheduled callbacks on a null poll
-        * We cannot do this in the null event handler, as that may be called
-        * from gui_multitask(). Scheduled callbacks must only be run from the
-        * top-level.
-        */
-       if (event == wimp_NULL_REASON_CODE) {
-               schedule_run();
-       }
-
-       ro_gui_window_update_boxes();
 }
 
 


-----------------------------------------------------------------------


-- 
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to