Gitweb links:

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

The branch, jmb/ievent has been updated
       via  e55e97587122489797b713b5ce0bed9689da0daa (commit)
      from  0387362e92ed285e9431ea7df7a2e99da5676e74 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

    RISC OS: forcibly deregister from SocketWatch on exit

diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index 02a3020..5629695 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -122,6 +122,8 @@ osspriteop_area *gui_sprites; /**< Sprite area containing 
pointer and hotlist sp
 #define DIR_SEP ('.')
 
 static void *pollword;
+static int *sockets_active;
+static size_t sockets_active_size;
 
 /**
  * Accepted wimp user messages.
@@ -394,7 +396,16 @@ static void ro_gui_cleanup(void)
        /* Uninstall NetSurf-specific fonts */
        xos_cli("FontRemove NetSurf:Resources.Fonts.");
        if (pollword != NULL) {
-               //XXX: need to make sure _all_ sockets are closed
+               size_t i;
+               /* Deregister any remaining sockets from SocketWatch */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] != -1) {
+                               /* SocketWatch_Deregister */
+                               (void) _swix(0x52281, _INR(0,1),
+                                               sockets_active[i], pollword);
+                               sockets_active[i] = -1;
+                       }
+               }
                xosmodule_free(pollword);
        }
 }
@@ -1126,6 +1137,7 @@ static int ro_gui_socket_open(int domain, int type, int 
protocol)
 {
        int sock = socket(domain, type, protocol);
        if (sock != -1) {
+               size_t i;
                int rosock;
                _kernel_oserror *error;
 
@@ -1143,6 +1155,30 @@ static int ro_gui_socket_open(int domain, int type, int 
protocol)
                        errno = ENOMEM;
                        return -1;
                }
+
+               /* Insert RISC OS socket handle into sockets_active */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] == -1) {
+                               sockets_active[i] = rosock;
+                               break;
+                       }
+               }
+               if (i == sockets_active_size) {
+                       /* No free slots: expand table */
+                       int *tmp = realloc(sockets_active,
+                                       sockets_active_size * 2 * sizeof(int));
+                       if (tmp == NULL) {
+                               /* SocketWatch_Deregister */
+                               (void) _swix(0x52281, _INR(0,1), rosock, 
pollword);
+                               close(sock);
+                               errno = ENOMEM;
+                               return -1;
+                       }
+                       memset(sockets_active + sockets_active_size, 0xff,
+                                       sockets_active_size * sizeof(int));
+                       sockets_active_size *= 2;
+                       sockets_active[i] = rosock;
+               }
        }
        return sock;
 }
@@ -1153,6 +1189,14 @@ static int ro_gui_socket_close(int socket)
 
        rosock = __get_ro_socket(socket);
        if (rosock != -1) {
+               size_t i;
+               /* Invalidate active sockets entry */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] == rosock) {
+                               sockets_active[i] = -1;
+                               break;
+                       }
+               }
                /* SocketWatch_Deregister */
                (void) _swix(0x52281, _INR(0,1), rosock, pollword);
        }
@@ -1165,11 +1209,21 @@ static int ro_gui_socket_close(int socket)
  */
 static os_error *ro_gui_init_internet_event(void)
 {
+       static os_error nomem = { 1, "No memory"};
        os_error *error;
 
+       sockets_active = malloc(32 * sizeof(int));
+       if (sockets_active == NULL) {
+               return &nomem;
+       }
+       memset(sockets_active, 0xff, 32 * sizeof(int));
+       sockets_active_size = 32;
+
        error = xosmodule_alloc(4, &pollword);
-       if (error != NULL)
+       if (error != NULL) {
                return error;
+       }
+
        *((uint32_t*) pollword) = 0;
        return NULL;
 }


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

Summary of changes:
 frontends/riscos/gui.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index 02a3020..5629695 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -122,6 +122,8 @@ osspriteop_area *gui_sprites; /**< Sprite area containing 
pointer and hotlist sp
 #define DIR_SEP ('.')
 
 static void *pollword;
+static int *sockets_active;
+static size_t sockets_active_size;
 
 /**
  * Accepted wimp user messages.
@@ -394,7 +396,16 @@ static void ro_gui_cleanup(void)
        /* Uninstall NetSurf-specific fonts */
        xos_cli("FontRemove NetSurf:Resources.Fonts.");
        if (pollword != NULL) {
-               //XXX: need to make sure _all_ sockets are closed
+               size_t i;
+               /* Deregister any remaining sockets from SocketWatch */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] != -1) {
+                               /* SocketWatch_Deregister */
+                               (void) _swix(0x52281, _INR(0,1),
+                                               sockets_active[i], pollword);
+                               sockets_active[i] = -1;
+                       }
+               }
                xosmodule_free(pollword);
        }
 }
@@ -1126,6 +1137,7 @@ static int ro_gui_socket_open(int domain, int type, int 
protocol)
 {
        int sock = socket(domain, type, protocol);
        if (sock != -1) {
+               size_t i;
                int rosock;
                _kernel_oserror *error;
 
@@ -1143,6 +1155,30 @@ static int ro_gui_socket_open(int domain, int type, int 
protocol)
                        errno = ENOMEM;
                        return -1;
                }
+
+               /* Insert RISC OS socket handle into sockets_active */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] == -1) {
+                               sockets_active[i] = rosock;
+                               break;
+                       }
+               }
+               if (i == sockets_active_size) {
+                       /* No free slots: expand table */
+                       int *tmp = realloc(sockets_active,
+                                       sockets_active_size * 2 * sizeof(int));
+                       if (tmp == NULL) {
+                               /* SocketWatch_Deregister */
+                               (void) _swix(0x52281, _INR(0,1), rosock, 
pollword);
+                               close(sock);
+                               errno = ENOMEM;
+                               return -1;
+                       }
+                       memset(sockets_active + sockets_active_size, 0xff,
+                                       sockets_active_size * sizeof(int));
+                       sockets_active_size *= 2;
+                       sockets_active[i] = rosock;
+               }
        }
        return sock;
 }
@@ -1153,6 +1189,14 @@ static int ro_gui_socket_close(int socket)
 
        rosock = __get_ro_socket(socket);
        if (rosock != -1) {
+               size_t i;
+               /* Invalidate active sockets entry */
+               for (i = 0; i < sockets_active_size; i++) {
+                       if (sockets_active[i] == rosock) {
+                               sockets_active[i] = -1;
+                               break;
+                       }
+               }
                /* SocketWatch_Deregister */
                (void) _swix(0x52281, _INR(0,1), rosock, pollword);
        }
@@ -1165,11 +1209,21 @@ static int ro_gui_socket_close(int socket)
  */
 static os_error *ro_gui_init_internet_event(void)
 {
+       static os_error nomem = { 1, "No memory"};
        os_error *error;
 
+       sockets_active = malloc(32 * sizeof(int));
+       if (sockets_active == NULL) {
+               return &nomem;
+       }
+       memset(sockets_active, 0xff, 32 * sizeof(int));
+       sockets_active_size = 32;
+
        error = xosmodule_alloc(4, &pollword);
-       if (error != NULL)
+       if (error != NULL) {
                return error;
+       }
+
        *((uint32_t*) pollword) = 0;
        return NULL;
 }


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

Reply via email to