Changeset 34 for trunk/VerboseThread.d
- Timestamp:
- 01/04/09 08:20:43 (3 years ago)
- Files:
-
- trunk/VerboseThread.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/VerboseThread.d
r24 r34 1 import fcgi.Thread;2 import fcgi.Connection;3 import fcgi.Request;1 import fcgi.Thread; 2 import fcgi.Connection; 3 import fcgi.Request; 4 4 5 import tango.text.convert.Layout; 6 import tango.io.Buffer; 7 import tango.io.Print; 8 import tango.io.Stdout; 5 import tango.io.stream.Format; 9 6 10 7 public int run (FastCGIRequest request) 11 8 { 12 static int counter = 0;9 static int counter = 0; 13 10 14 auto stdout = new Print!(char) (new Layout!(char) (),request.stdout);11 auto stdout = new FormatOutput !(char) (request.stdout); 15 12 16 stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>");17 stdout ("<body>");13 stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>"); 14 stdout ("<body>"); 18 15 19 // some counters20 synchronized21 counter++;22 stdout ("<h1> Hello world </h1><br>") ("Request #") (counter) ("<br><br>\n");16 // some counters 17 synchronized 18 counter++; 19 stdout ("<h1> Hello world </h1><br>") ("Request #") (counter) ("<br><br>\n"); 23 20 24 // Write IP25 auto ip = ("REMOTE_ADDR" in request.args);26 if (ip)27 {28 stdout ("Your IP is ") (*ip) ("<br><br>\n");29 }30 else31 {32 stdout ("Cannot extract IP :(<br><br>\n");33 }21 // Write IP 22 auto ip = ("REMOTE_ADDR" in request.args); 23 if (ip) 24 { 25 stdout ("Your IP is ") (*ip) ("<br><br>\n"); 26 } 27 else 28 { 29 stdout ("Cannot extract IP :(<br><br>\n"); 30 } 34 31 35 // Write stdin 36 stdout ("Data: \"") (); 37 while (1) 38 { 39 char[10] string; 40 int rd = request.stdin.read(string); 41 if (rd > 0) 42 stdout(string[0 .. rd]); 43 if (rd != string.length) 32 // Write stdin 33 stdout ("Data: \"") (); 34 while (1) 44 35 { 45 stdout ("\"<br><br>"); 46 break; 36 char[10] string; 37 int rd = request.stdin.read (string); 38 if (rd > 0) 39 stdout (string [0 .. rd]); 40 if (rd != string.length) 41 { 42 stdout ("\"<br><br>"); 43 break; 44 } 47 45 } 48 }49 46 50 // Write all arguments51 stdout ("\nYour environment:<br>\n");52 foreach (key, value; request.args)53 {54 stdout ("request.args[\"")(key) ("\"] = \"") (value) ("\"<br>\n");55 }56 stdout ("</body>\n") ();47 // Write all arguments 48 stdout ("\nYour environment:<br>\n"); 49 foreach (key, value; request.args) 50 { 51 stdout ("request.args[\"") (key) ("\"] = \"") (value) ("\"<br>\n"); 52 } 53 stdout ("</body>\n") (); 57 54 58 return 0;55 return 0; 59 56 } 60 57 61 int main (char[][] args)58 int main (char[][] args) 62 59 { 63 FastCGIConnection connection = new FastCGIConnection ();60 FastCGIConnection connection = new FastCGIConnection (); 64 61 65 return FastCGIThread.loop (connection, &run, true, 10);62 return FastCGIThread.loop (connection, &run, true, 10); 66 63 }
