root/trunk/VerboseThread.d

Revision 24, 1.5 kB (checked in by xammy, 10 months ago)

Moved examles from trunk/examples to trunk/

Line 
1 import  fcgi.Thread;
2 import  fcgi.Connection;
3 import  fcgi.Request;
4
5 import  tango.text.convert.Layout;
6 import  tango.io.Buffer;
7 import  tango.io.Print;
8 import  tango.io.Stdout;
9
10 public int run (FastCGIRequest request)
11 {
12     static int counter = 0;
13
14     auto stdout = new Print!(char) (new Layout!(char) (), request.stdout);
15
16     stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>");
17     stdout ("<body>");
18
19     // some counters
20     synchronized
21         counter++;
22     stdout ("<h1> Hello world </h1><br>") ("Request #") (counter) ("<br><br>\n");
23
24     // Write IP
25     auto ip = ("REMOTE_ADDR" in request.args);
26     if (ip)
27     {
28         stdout ("Your IP is ") (*ip) ("<br><br>\n");
29     }
30     else
31     {
32         stdout ("Cannot extract IP :(<br><br>\n");
33     }
34
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)
44         {
45             stdout ("\"<br><br>");
46             break;
47         }
48     }
49
50     // Write all arguments
51     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") ();
57
58     return 0;
59 }
60
61 int main(char[][] args)
62 {
63     FastCGIConnection connection = new FastCGIConnection ();
64
65     return FastCGIThread.loop (connection, &run, true, 10);
66 }
Note: See TracBrowser for help on using the browser.