qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fad...@apache.org
Subject svn commit: r1556179 - in /qpid/proton/branches/fadams-javascript-binding: examples/messenger/c/recv-async.c examples/messenger/c/send-async.c proton-c/bindings/javascript/CMakeLists.txt proton-c/bindings/javascript/my-library.js
Date Tue, 07 Jan 2014 11:05:21 GMT
Author: fadams
Date: Tue Jan  7 11:05:20 2014
New Revision: 1556179

URL: http://svn.apache.org/r1556179
Log:
Added true event driven async mechanism triggered by WebSocket events to my-library.js - this
needs to be pushed back to emscripten in due course.

Modified:
    qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/recv-async.c
    qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/send-async.c
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
    qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/recv-async.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/recv-async.c?rev=1556179&r1=1556178&r2=1556179&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/recv-async.c (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/recv-async.c Tue Jan
 7 11:05:20 2014
@@ -28,6 +28,7 @@
 
 #if EMSCRIPTEN
 #include <emscripten.h>
+void emscripten_set_network_callback(void (*func)());
 #endif
 
 #define check(messenger)                                                     \
@@ -93,8 +94,15 @@ printf("err = %d\n", err);
 void work() {
 //printf("                          *** work ***\n");
 
-    int err = pn_messenger_work(messenger, 0); // Sends any outstanding messages queued for
messenger.
-//printf("err = %d\n", err);
+    int err = pn_messenger_work(messenger, 0);
+printf("err = %d\n", err);
+
+    if (err >= 0) {
+        process();
+    }
+
+    err = pn_messenger_work(messenger, 0);
+printf("err = %d\n", err);
 
     if (err >= 0) {
         process();
@@ -186,7 +194,9 @@ pn_messenger_set_blocking(messenger, fal
   pn_messenger_recv(messenger, -1); // Receive as many messages as messenger can buffer
 
 #if EMSCRIPTEN
-  emscripten_set_main_loop(work, 0, 0);
+  //emscripten_set_main_loop(work, 0, 0);
+
+  emscripten_set_network_callback(work);
 #else
   while (1) {
     pn_messenger_work(messenger, -1); // Block indefinitely until there has been socket activity.

Modified: qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/send-async.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/send-async.c?rev=1556179&r1=1556178&r2=1556179&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/send-async.c (original)
+++ qpid/proton/branches/fadams-javascript-binding/examples/messenger/c/send-async.c Tue Jan
 7 11:05:20 2014
@@ -30,6 +30,7 @@
 
 #if EMSCRIPTEN
 #include <emscripten.h>
+void emscripten_set_network_callback(void (*func)());
 #endif
 
 #define check(messenger)                                                     \
@@ -47,6 +48,8 @@
 pn_tracker_t tracker;
 int tracked = 1;
 
+int running = 1;
+
 
 void die(const char *file, int line, const char *message)
 {
@@ -76,20 +79,36 @@ printf("status = %d\n", status);
         //pn_messenger_settle(messenger, tracker, 0);
         //tracked--;
 
+        if (running) {
+printf("stopping\n");
+            pn_messenger_stop(messenger);
+            running = 0;
+        } 
+    }
+
+    if (pn_messenger_stopped(messenger)) {
 printf("exiting\n");
-        pn_message_free(message); // Release message.
-        pn_messenger_stop(messenger);
+        pn_message_free(message);
         pn_messenger_free(messenger);
         exit(0);
     }
 }
 
+
+
 // Callback used by emscripten to ensure pn_messenger_work gets called.
 void work() {
 //printf("                          *** work ***\n");
 
-    int err = pn_messenger_work(messenger, 0); // Sends any outstanding messages queued for
messenger.
-//printf("err = %d\n", err);
+    int err = pn_messenger_work(messenger, 0);
+printf("err = %d\n", err);
+
+    if (err >= 0) {
+        process();
+    }
+
+    err = pn_messenger_work(messenger, 0);
+printf("err = %d\n", err);
 
     if (err >= 0) {
         process();
@@ -158,7 +177,9 @@ int main(int argc, char** argv)
 
 
 #if EMSCRIPTEN
-  emscripten_set_main_loop(work, 0, 0);
+  //emscripten_set_main_loop(work, 0, 0);
+
+  emscripten_set_network_callback(work);
 #else
   while (1) {
     pn_messenger_work(messenger, -1); // Block indefinitely until there has been socket activity.

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt?rev=1556179&r1=1556178&r2=1556179&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
(original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/CMakeLists.txt
Tue Jan  7 11:05:20 2014
@@ -191,7 +191,10 @@ set_target_properties(
   send-async.js recv-async.js
   PROPERTIES
   COMPILE_FLAGS "${COMPILE_WARNING_FLAGS} ${COMPILE_PLATFORM_FLAGS}"
-  LINK_FLAGS "-s SOCKET_DEBUG=1 --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
+  #LINK_FLAGS "-s SOCKET_DEBUG=1 --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
+  LINK_FLAGS "-O2 --closure 1 --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
+  #LINK_FLAGS "-s VERBOSE=1 -O2 --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
+  #LINK_FLAGS "-O2 --js-library ${CMAKE_CURRENT_SOURCE_DIR}/my-library.js"
   )
 
 

Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js?rev=1556179&r1=1556178&r2=1556179&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js
(original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/bindings/javascript/my-library.js
Tue Jan  7 11:05:20 2014
@@ -267,6 +267,24 @@ console.log('e: ' + e);
           }
 
           sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
+
+// TODO trigger new emscripten_set_network_callback here.
+
+          if (Module['networkCallback']) {
+console.log("triggering networkCallback");
+
+            try {
+              Runtime.dynCall('v', Module['networkCallback']);
+            } catch (e) {
+              if (e instanceof ExitStatus) {
+                return;
+              } else {
+                if (e && typeof e === 'object' && e.stack) Module.printErr('exception
thrown: ' + [e, e.stack]);
+                throw e;
+              }
+            }
+          }
+
         };
 
         if (ENVIRONMENT_IS_NODE) {
@@ -420,6 +438,7 @@ console.log('close');
         if (sock.server) {
            throw new FS.ErrnoError(ERRNO_CODES.EINVAL);  // already listening
         }
+
         var WebSocketServer = require('ws').Server;
         var host = sock.saddr;
 #if SOCKET_DEBUG
@@ -451,6 +470,29 @@ console.log('close');
             // to the correct client
             SOCKFS.websocket_sock_ops.createPeer(sock, ws);
           }
+
+
+
+
+// TODO trigger new emscripten_set_network_callback here.
+
+          if (Module['networkCallback']) {
+console.log("triggering networkCallback");
+
+            try {
+              Runtime.dynCall('v', Module['networkCallback']);
+            } catch (e) {
+              if (e instanceof ExitStatus) {
+                return;
+              } else {
+                if (e && typeof e === 'object' && e.stack) Module.printErr('exception
thrown: ' + [e, e.stack]);
+                throw e;
+              }
+            }
+          }
+
+
+
         });
         sock.server.on('closed', function() {
 console.log('closed');
@@ -462,7 +504,6 @@ console.log('error');
         });
       },
       accept: function(listensock) {
-console.log('accept');
         if (!listensock.server) {
           throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
         }
@@ -549,8 +590,10 @@ console.log('getname');
 #if SOCKET_DEBUG
           Module.print('websocket send (' + length + ' bytes): ' + [Array.prototype.slice.call(new
Uint8Array(data))]);
 #endif
+
           // send the actual data
           dest.socket.send(data);
+
           return length;
         } catch (e) {
           throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
@@ -616,6 +659,9 @@ console.log('getname');
     }
   },
 
-
+  emscripten_set_network_callback: function(func) {
+    Module['noExitRuntime'] = true;
+    Module['networkCallback'] = func;
+  }
 
 });



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message