1 path = require("path");
2 Buffer = require("buffer").Buffer;
4 port = parseInt(process.env.PORT || 8000);
6 var old = (process.argv[2] == 'old');
8 console.log('pid ' + process.pid);
10 http = require(old ? "http_old" : 'http');
11 if (old) console.log('old version');
14 for (var i = 0; i < 20*1024; i++) {
21 http.createServer(function (req, res) {
22 var commands = req.url.split("/");
23 var command = commands[1];
25 var arg = commands[2];
28 if (command == "bytes") {
29 var n = parseInt(arg, 10)
31 throw "bytes called with n <= 0"
32 if (stored[n] === undefined) {
33 console.log("create stored[n]");
35 for (var i = 0; i < n; i++) {
41 } else if (command == "buffer") {
42 var n = parseInt(arg, 10)
43 if (n <= 0) throw new Error("bytes called with n <= 0");
44 if (storedBuffer[n] === undefined) {
45 console.log("create storedBuffer[n]");
46 storedBuffer[n] = new Buffer(n);
47 for (var i = 0; i < n; i++) {
48 storedBuffer[n][i] = "C".charCodeAt(0);
51 body = storedBuffer[n];
53 } else if (command == "quit") {
54 res.connection.server.close();
57 } else if (command == "fixed") {
65 var content_length = body.length.toString();
68 , { "Content-Type": "text/plain"
69 , "Content-Length": content_length
73 res.write(body, 'ascii');
76 res.end(body, 'ascii');
80 console.log('Listening at http://127.0.0.1:'+port+'/');