Changeset 34
- Timestamp:
- 01/04/09 08:20:43 (3 years ago)
- Files:
-
- trunk/SimpleApp.d (modified) (1 diff)
- trunk/SimpleLoop.d (modified) (1 diff)
- trunk/VerboseApp.d (modified) (2 diffs)
- trunk/VerboseLoop.d (modified) (2 diffs)
- trunk/VerboseThread.d (modified) (1 diff)
- trunk/fcgi/Protocol.d (modified) (1 diff)
- trunk/fcgi/Request.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/SimpleApp.d
r24 r34 3 3 import fcgi.Request; 4 4 5 import tango.io.stream.Format; 5 6 import tango.text.convert.Layout; 6 import tango.io.Print;7 import tango.io.Buffer;8 7 9 8 class MyApp : FastCGIApplication 10 9 { 11 private Print!(char) stdout; 12 private Print!(char) stderr; 10 11 private FormatOutput!(char) stdout; 12 private FormatOutput!(char) stderr; 13 13 14 14 this (int id, FastCGIRequest request) 15 15 { 16 16 auto layout = new Layout!(char) (); 17 stdout = new Print!(char) (layout, request.stdout); 18 stderr = new Print!(char) (layout, request.stderr); 17 18 stdout = new FormatOutput!(char) (layout, request.stdout); 19 stderr = new FormatOutput!(char) (layout, request.stderr); 19 20 } 20 21 trunk/SimpleLoop.d
r27 r34 1 1 import fcgi.Request; 2 import fcgi.Connection;2 //import fcgi.Connection; 3 3 4 4 int main (char[][] args) trunk/VerboseApp.d
r24 r34 3 3 import fcgi.Request; 4 4 5 import tango.io.stream.Format; 5 6 import tango.text.convert.Layout; 6 import tango.io.Print;7 import tango.io.Buffer;8 7 9 8 class MyApp : FastCGIApplication 10 9 { 11 private Print!(char) stdout;12 private Print!(char) stderr;10 private FormatOutput!(char) stdout; 11 private FormatOutput!(char) stderr; 13 12 private static int counter = 0; 14 13 … … 16 15 { 17 16 auto layout = new Layout!(char) (); 18 stdout = new Print!(char) (layout, request.stdout); 19 stderr = new Print!(char) (layout, request.stderr); 17 18 stdout = new FormatOutput!(char) (layout, request.stdout); 19 stderr = new FormatOutput!(char) (layout, request.stderr); 20 20 21 } 21 22 trunk/VerboseLoop.d
r24 r34 2 2 import fcgi.Connection; 3 3 4 import tango.text.convert.Layout; 5 import tango.io.Buffer; 6 import tango.io.Print; 7 import tango.io.Stdout; 4 import tango.io.stream.Format; 8 5 9 6 int main (char[][] args) … … 13 10 int counter = 0; 14 11 15 Stdout = new Print!(char) (new Layout!(char) (),request.stdout);12 auto Stdout = new FormatOutput!(char) (request.stdout); 16 13 while ( request.accept () ) 17 14 { 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 } trunk/fcgi/Protocol.d
r14 r34 13 13 module fcgi.Protocol; 14 14 15 import tango.io.Buffer;16 15 import tango.io.protocol.Reader; 17 16 import tango.io.protocol.Writer; trunk/fcgi/Request.d
r32 r34 20 20 private import fcgi.Exception; 21 21 22 private import tango.io.Buffer;23 22 private import tango.io.Console; 24 23 private import tango.math.Math;
