diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-03-22 15:16:34 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-03-22 15:16:34 -0400 |
commit | bac67ca0f668cd381205b243355da8c906c58b5b (patch) | |
tree | 8f652c63195f27ebf46719ccc953c6597b079095 | |
parent | 2627ab6f5cfd96df06016a88b7e5a245e3ab9d8f (diff) |
Press a button to send a message
-rw-r--r-- | lib/js/urweb.js | 28 | ||||
-rw-r--r-- | src/c/urweb.c | 2 | ||||
-rw-r--r-- | tests/channel.ur | 5 |
3 files changed, 25 insertions, 10 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index d5147369..18842188 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -115,9 +115,13 @@ function pfl(s) { throw "Can't parse float: " + s; } +function whine(msg) { + alert(msg); + throw msg; +} + function pf() { - alert("Pattern match failure"); - throw "Pattern match failure"; + whine("Pattern match failure"); } var closures = []; @@ -180,8 +184,7 @@ function rc(uri, parse, k) { if (isok) k(parse(xhr.responseText)); else { - alert("Error querying remote server!"); - throw "Error querying remote server!"; + whine("Error querying remote server!"); } } }; @@ -200,8 +203,7 @@ function path_join(s1, s2) { function listener() { var uri = path_join(url_prefix, ".msgs"); var xhr = getXHR(); - - xhr.onreadystatechange = function() { + var orsc = function() { if (xhr.readyState == 4) { var isok = false; @@ -211,15 +213,23 @@ function listener() { } catch (e) { } if (isok) { - alert("Messages: " + xhr.responseText); + var lines = xhr.responseText.split("\n"); + if (lines.length < 2) + whine("Empty message from remote server"); + + for (var i = 0; i+1 < lines.length; i += 2) { + alert("Message(" + lines[i] + "): " + lines[i+1]); + } + + xhr.onreadystatechange = orsc; requestUri(xhr, uri); } else { - alert("Error querying remote server for messages!"); - throw "Error querying remote server for messages!"; + whine("Error querying remote server for messages!"); } } }; + xhr.onreadystatechange = orsc; requestUri(xhr, uri); } diff --git a/src/c/urweb.c b/src/c/urweb.c index abe08221..a0bbe575 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -342,6 +342,7 @@ static void uw_channel_send(channel *ch, const char *msg) { pthread_mutex_lock(&c->data.used.lock); if (c->data.used.sock != -1) { + printf("Immediate send\n"); uw_really_send(c->data.used.sock, begin_msgs, sizeof(begin_msgs) - 1); uw_really_send(c->data.used.sock, pre, preLen); uw_really_send(c->data.used.sock, msg, len); @@ -349,6 +350,7 @@ static void uw_channel_send(channel *ch, const char *msg) { close(c->data.used.sock); c->data.used.sock = -1; } else { + printf("Delayed send\n"); buf_append(&c->data.used.msgs, pre, preLen); buf_append(&c->data.used.msgs, msg, len); buf_append(&c->data.used.msgs, "\n", 1); diff --git a/tests/channel.ur b/tests/channel.ur index 2ea89e87..6b98f5d7 100644 --- a/tests/channel.ur +++ b/tests/channel.ur @@ -4,8 +4,11 @@ fun main () : transaction page = fun onload () = subscribe ch; send ch "Hello world!" + + fun haveAnother () = + send ch "Here's another." in return <xml><body onload={onload ()}> - + <button value="Another?" onclick={haveAnother ()}/> </body></xml> end |