1 path = require("path");
2 exec = require("child_process").exec;
3 http = require("http");
5 port = parseInt(process.env.PORT || 8000);
7 console.log('pid ' + process.pid);
10 for (var i = 0; i < 20*1024; i++) {
16 exec('git rev-list -1 HEAD', function (e, stdout) {
18 console.error("Problem executing: 'git rev-list -1 HEAD'");
21 rev = stdout.replace(/\s/g, '');
24 exec('uname -a', function (e, stdout) {
26 console.error("Problem executing: 'uname -a'");
29 uname = stdout.replace(/[\r\n]/g, '');
37 var server = http.createServer(function (req, res) {
38 var commands = req.url.split("/");
39 var command = commands[1];
41 var arg = commands[2];
44 if (command == "bytes") {
45 var n = parseInt(arg, 10)
47 throw "bytes called with n <= 0"
48 if (stored[n] === undefined) {
49 console.log("create stored[n]");
51 for (var i = 0; i < n; i++) {
57 } else if (command == "buffer") {
58 var n = parseInt(arg, 10)
59 if (n <= 0) throw new Error("bytes called with n <= 0");
60 if (storedBuffer[n] === undefined) {
61 console.log("create storedBuffer[n]");
62 storedBuffer[n] = new Buffer(n);
63 for (var i = 0; i < n; i++) {
64 storedBuffer[n][i] = "C".charCodeAt(0);
67 body = storedBuffer[n];
69 } else if (command == "quit") {
70 res.connection.server.close();
73 } else if (command == "fixed") {
76 } else if (command == "info") {
77 body = 'rev=' + rev + '\nuname="' + uname + '"\n';
84 var content_length = body.length.toString();
86 res.writeHead(status, { "Content-Type": "text/plain",
87 "Content-Length": content_length });
92 server.listen(port, function () {
93 console.log('Listening at http://127.0.0.1:'+port+'/');