Show
Ignore:
Timestamp:
01/04/09 08:20:43 (3 years ago)
Author:
xammy
Message:

Fixed some bugs due to changes in Tango API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/VerboseThread.d

    r24 r34  
    1 import fcgi.Thread; 
    2 import fcgi.Connection; 
    3 import fcgi.Request; 
     1import fcgi.Thread; 
     2import fcgi.Connection; 
     3import fcgi.Request; 
    44 
    5 import  tango.text.convert.Layout; 
    6 import  tango.io.Buffer; 
    7 import  tango.io.Print; 
    8 import  tango.io.Stdout; 
     5import tango.io.stream.Format; 
    96 
    107public int run (FastCGIRequest request) 
    118{ 
    12     static int counter = 0; 
     9        static int counter = 0; 
    1310 
    14     auto stdout = new Print!(char) (new Layout!(char) (), request.stdout); 
     11        auto stdout = new FormatOutput !(char) (request.stdout); 
    1512 
    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>"); 
    1815 
    19     // some counters 
    20     synchronized 
    21         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"); 
    2320 
    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    
     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       
    3431 
    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) 
    4435        { 
    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                } 
    4745        } 
    48     } 
    4946 
    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") (); 
     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") (); 
    5754 
    58     return 0; 
     55        return 0; 
    5956} 
    6057 
    61 int main(char[][] args) 
     58int main (char[][] args) 
    6259{ 
    63     FastCGIConnection connection = new FastCGIConnection (); 
     60        FastCGIConnection connection = new FastCGIConnection (); 
    6461 
    65     return FastCGIThread.loop (connection, &run, true, 10); 
     62        return FastCGIThread.loop (connection, &run, true, 10); 
    6663}