mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-23 00:00:06 +01:00

As it is, if time_t is 32-bit on the platform it might lead to arithmetic overflow, so force it to lws_usec_t (uint64_t) even though it works OK here on x86_64. Add a minimal example aimed at testing the wsi hrtimer stability consistently across platforms. Add and disable by default hrtimer dump code (this is too expensive and specific to internal testing to leave in for debug mode even if it's not printed). If you hack it enabled, it will dump the sul list for the pt and assert if the list is disordered.
69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
|
|
function get_appropriate_ws_url(extra_url)
|
|
{
|
|
var pcol;
|
|
var u = document.URL;
|
|
|
|
/*
|
|
* We open the websocket encrypted if this page came on an
|
|
* https:// url itself, otherwise unencrypted
|
|
*/
|
|
|
|
if (u.substring(0, 5) === "https") {
|
|
pcol = "wss://";
|
|
u = u.substr(8);
|
|
} else {
|
|
pcol = "ws://";
|
|
if (u.substring(0, 4) === "http")
|
|
u = u.substr(7);
|
|
}
|
|
|
|
u = u.split("/");
|
|
|
|
/* + "/xxx" bit is for IE10 workaround */
|
|
|
|
return pcol + u[0] + "/" + extra_url;
|
|
}
|
|
|
|
function new_ws(urlpath, protocol)
|
|
{
|
|
if (typeof MozWebSocket != "undefined")
|
|
return new MozWebSocket(urlpath, protocol);
|
|
|
|
return new WebSocket(urlpath, protocol);
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
var ws = new_ws(get_appropriate_ws_url(""), "timer");
|
|
try {
|
|
ws.onopen = function() {
|
|
document.getElementById("m").disabled = 0;
|
|
document.getElementById("b").disabled = 0;
|
|
};
|
|
|
|
ws.onmessage =function got_packet(msg) {
|
|
document.getElementById("r").value =
|
|
document.getElementById("r").value + msg.data + "\n";
|
|
document.getElementById("r").scrollTop =
|
|
document.getElementById("r").scrollHeight;
|
|
};
|
|
|
|
ws.onclose = function(){
|
|
document.getElementById("m").disabled = 1;
|
|
document.getElementById("b").disabled = 1;
|
|
};
|
|
} catch(exception) {
|
|
alert("<p>Error " + exception);
|
|
}
|
|
|
|
function sendmsg()
|
|
{
|
|
ws.send(document.getElementById("m").value);
|
|
document.getElementById("m").value = "";
|
|
}
|
|
|
|
document.getElementById("b").addEventListener("click", sendmsg);
|
|
|
|
}, false);
|
|
|