1 path = require("path");
2 Buffer = require("buffer").Buffer;
4 port = parseInt(process.env.PORT || 8000);
6 var console.log = require("sys").console.log;
8 var old = (process.argv[2] == 'old');
10 console.log('pid ' + process.pid);
12 http = require(old ? "http_old" : 'http');
13 if (old) console.log('old version');
16 for (var i = 0; i < 20*1024; i++) {
23 http.createServer(function (req, res) {
24 var commands = req.url.split("/");
25 var command = commands[1];
27 var arg = commands[2];
30 if (command == "bytes") {
31 var n = parseInt(arg, 10)
33 throw "bytes called with n <= 0"
34 if (stored[n] === undefined) {
35 console.log("create stored[n]");
37 for (var i = 0; i < n; i++) {
43 } else if (command == "buffer") {
44 var n = parseInt(arg, 10)
45 if (n <= 0) throw new Error("bytes called with n <= 0");
46 if (storedBuffer[n] === undefined) {
47 console.log("create storedBuffer[n]");
48 storedBuffer[n] = new Buffer(n);
49 for (var i = 0; i < n; i++) {
50 storedBuffer[n][i] = "C".charCodeAt(0);
53 body = storedBuffer[n];
55 } else if (command == "quit") {
56 res.connection.server.close();
59 } else if (command == "fixed") {
67 var content_length = body.length.toString();
70 , { "Content-Type": "text/plain"
71 , "Content-Length": content_length
75 res.write(body, 'ascii');
78 res.end(body, 'ascii');
82 console.log('Listening at http://127.0.0.1:'+port+'/');