[Toss-devel-svn] SF.net SVN: toss:[1692] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2012-03-12 11:26:23
|
Revision: 1692
http://toss.svn.sourceforge.net/toss/?rev=1692&view=rev
Author: lukaszkaiser
Date: 2012-03-12 11:26:12 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
Small Client-Server corrections.
Modified Paths:
--------------
trunk/Toss/Client/Main.js
trunk/Toss/Client/index.html
trunk/Toss/Server/Server.ml
Modified: trunk/Toss/Client/Main.js
===================================================================
--- trunk/Toss/Client/Main.js 2012-03-12 00:27:22 UTC (rev 1691)
+++ trunk/Toss/Client/Main.js 2012-03-12 11:26:12 UTC (rev 1692)
@@ -60,7 +60,21 @@
function startup () {
- // should do some work here perhaps
+ if (navigator.userAgent.indexOf('MSIE') != -1 &&
+ navigator.userAgent.indexOf('MSIE 9') == -1) {
+ document.getElementById("nosvg").style.display = "block";
+ }
+ if (window.location.href.indexOf("?simple=true") > 0) {
+ document.getElementById ("ads").style.display = "none";
+ document.getElementById ("more-games-bt-div").style.display = "none";
+ }
+ var gindex = window.location.href.indexOf("?game=")
+ var cur_game = "";
+ if (gindex > 0) {
+ cur_game = window.location.href.substring(gindex+6,
+ window.location.href.length)
+ }
+ if (cur_game != "") { new_play_click (cur_game); }
}
function new_play_click (game) {
Modified: trunk/Toss/Client/index.html
===================================================================
--- trunk/Toss/Client/index.html 2012-03-12 00:27:22 UTC (rev 1691)
+++ trunk/Toss/Client/index.html 2012-03-12 11:26:12 UTC (rev 1692)
@@ -15,6 +15,8 @@
<body onload="startup ('')">
+<div id="ads">
+</div>
<div id="main">
Modified: trunk/Toss/Server/Server.ml
===================================================================
--- trunk/Toss/Server/Server.ml 2012-03-12 00:27:22 UTC (rev 1691)
+++ trunk/Toss/Server/Server.ml 2012-03-12 11:26:12 UTC (rev 1692)
@@ -3,15 +3,18 @@
let debug_level = ref 0
-let quit_on_eof = ref false
-
-let html_dir_path = ref "Client/"
-
let set_debug_level i =
debug_level := i;
AuxIO.set_debug_level "GameTree" i;
AuxIO.set_debug_level "Play" i
+
+let quit_on_eof = ref false
+let html_dir_path = ref "Client/"
+let cache_html = ref true
+let html_req_counter = ref 0
+let html_cache = Hashtbl.create 7
+
let init_state =
(None, true, Arena.empty_state, TranslateGame.empty_gdl_translation, 0)
@@ -111,6 +114,16 @@
(if cookies = [] then "" else cookies_s ^ "\r\n") ^
"Content-length: " ^ (string_of_int (String.length s)) ^ "\r\n\r\n" ^ s
+let mime_type fname =
+ match String.sub fname ((String.index fname '.') + 1) 2 with
+ | "ht" -> "text/html; charset=utf-8"
+ | "ic" -> "image/x-icon"
+ | "pn" -> "image/png"
+ | "cs" -> "text/css"
+ | "js" -> "text/javascript"
+ | "sv" -> "image/svg+xml"
+ | _ -> "text/html charset=utf-8"
+
let handle_http_get cmd head msg ck =
if !debug_level > 1 then (
Printf.printf "Http Get Handler\n%s%s\n%!" cmd msg;
@@ -124,20 +137,18 @@
with Not_found -> fname_in1 in
let fname = !html_dir_path ^ fname_in in
if !debug_level > 1 then Printf.printf "SERVING FILE: %s;\n%!" fname;
- if Sys.file_exists fname && not (Sys.is_directory fname) then (
- let content = AuxIO.input_file fname in
- let tp = match String.sub fname ((String.index fname '.') + 1) 2 with
- | "ht" -> "text/html; charset=utf-8"
- | "ic" -> "image/x-icon"
- | "pn" -> "image/png"
- | "cs" -> "text/css"
- | "js" -> "text/javascript"
- | "sv" -> "image/svg+xml"
- | _ -> "text/html charset=utf-8" in
- http_msg true "200 OK" tp [] content
- ) else http_msg true "404 NOT FOUND" "text/html; charset=utf-8" []
- ("<html>\n<head><title>Toss: Page Not Found</title></head>\n" ^
- "<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>")
+ try if not !cache_html then raise Not_found else
+ let content = Hashtbl.find html_cache fname in
+ LOG 1 "Found %s in html cache" fname;
+ http_msg true "200 OK" (mime_type fname) [] content
+ with Not_found ->
+ if Sys.file_exists fname && not (Sys.is_directory fname) then (
+ let content = AuxIO.input_file fname in
+ if !cache_html then Hashtbl.add html_cache fname content;
+ http_msg true "200 OK" (mime_type fname) [] content
+ ) else http_msg true "404 NOT FOUND" "text/html; charset=utf-8" []
+ ("<html>\n<head><title>Toss: Page Not Found</title></head>\n" ^
+ "<body><p>Not found: " ^ fname_in ^ "</p></body>\n</html>")
let handle_http_post msg =
let split_msg = Aux.split_charprop (fun c -> c = '#') msg in
@@ -167,7 +178,10 @@
let handle_http_msg rstate cmd head msg ck =
if String.sub cmd 0 5 = "GET /" then
- Aux.Left (rstate, handle_http_get cmd head msg ck)
+ if !html_req_counter < 50 then ( (* cache a few first requests: no fork *)
+ incr html_req_counter;
+ Aux.Left (rstate, handle_http_get cmd head msg ck)
+ ) else Aux.Right (rstate, fun () -> handle_http_get cmd head msg ck)
else if String.length cmd > 13 && String.sub cmd 0 13 = "POST /Handler" then
Aux.Right (rstate, fun () -> handle_http_post msg)
else try Aux.Left (req_handle rstate
@@ -396,6 +410,8 @@
("-fulltest", Arg.String (fun s -> test_s := s; test_full := true),
"full unit tests for given path, might take longer");
("-noprecache", Arg.Unit (fun ()-> precache := false), "do no pre-caching");
+ ("-nohttpcache", Arg.Unit (fun ()-> cache_html := false),
+ "re-read files from disk on each HTTP GET request");
("-html", Arg.String (fun s -> html_dir_path := s),
"set path to the directory with html files for the client");
("-use-parallel", Arg.Tuple [Arg.Int (fun p -> set_parallel_port p);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|