if (command == "bytes") {
var n = parseInt(arg, 10)
if (n <= 0)
- throw "bytes called with n <= 0"
+ throw "bytes called with n <= 0"
if (stored[n] === undefined) {
console.log("create stored[n]");
stored[n] = "";
var content_length = body.length.toString();
- res.writeHead( status
+ res.writeHead( status
, { "Content-Type": "text/plain"
, "Content-Length": content_length
}
def wait(seconds)
n = (seconds / 0.01).to_i
- n.times do
+ n.times do
sleep(0.01)
- #File.read(DIR + '/yahoo.html')
+ #File.read(DIR + '/yahoo.html')
end
end
class SimpleApp
@@responses = {}
-
+
def initialize
@count = 0
end
-
+
def deferred?(env)
false
end
-
+
def call(env)
path = env['PATH_INFO'] || env['REQUEST_URI']
commands = path.split('/')
-
+
@count += 1
if commands.include?('periodical_activity') and @count % 10 != 1
return [200, {'Content-Type'=>'text/plain'}, "quick response!\r\n"]
end
-
+
if commands.include?('fibonacci')
n = commands.last.to_i
raise "fibonacci called with n <= 0" if n <= 0
body = (1..n).to_a.map { |i| fib(i).to_s }.join(' ')
status = 200
-
+
elsif commands.include?('wait')
n = commands.last.to_f
raise "wait called with n <= 0" if n <= 0
wait(n)
body = "waited about #{n} seconds"
status = 200
-
+
elsif commands.include?('bytes')
n = commands.last.to_i
raise "bytes called with n <= 0" if n <= 0
n = 20 * 1024;
body = @@responses[n] || "C"*n
status = 200
-
+
elsif commands.include?('test_post_length')
input_body = ""
while chunk = env['rack.input'].read(512)
- input_body << chunk
+ input_body << chunk
end
if env['CONTENT_LENGTH'].to_i == input_body.length
body = "Content-Length matches input length"
status = 200
else
- body = "Content-Length doesn't matches input length!
+ body = "Content-Length doesn't matches input length!
content_length = #{env['CONTENT_LENGTH'].to_i}
input_body.length = #{input_body.length}"
status = 500
status = 404
body = "Undefined url"
end
-
+
body += "\r\n"
headers = {'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }
[status, headers, [body]]
require 'thin'
require 'ebb'
# Rack::Handler::Mongrel.run(SimpleApp.new, :Port => 8000)
- Thin::Server.start("0.0.0.0", 8000, SimpleApp.new)
+ Thin::Server.start("0.0.0.0", 8000, SimpleApp.new)
# Ebb::start_server(SimpleApp.new, :port => 8000)
end
var Verify = binding.Verify;
var crypto = true;
} catch (e) {
-
+
var crypto = false;
}
return bytesWritten;
};
-
+
var oldRead = self._readImpl;
self._readImpl = function(buf, off, len, calledByIOWatcher) {
assert(self.secure);
if (this.cursor === 0 && this.line.length === 0) {
this.close();
} else if (this.cursor < this.line.length) {
- this.line = this.line.slice(0, this.cursor)
+ this.line = this.line.slice(0, this.cursor)
+ this.line.slice(this.cursor+1, this.line.length)
;
this._refreshLine();
/**
* Used to parse and execute the Node REPL commands.
- *
+ *
* @param {cmd} cmd The command entered to check
- * @returns {Boolean} If true it means don't continue parsing the command
+ * @returns {Boolean} If true it means don't continue parsing the command
*/
REPLServer.prototype.parseREPLKeyword = function (cmd) {
var self = this;
-
+
switch (cmd) {
case ".break":
self.buffered_cmd = '';
};
function trimWhitespace (cmd) {
- var trimmer = /^\s*(.+)\s*$/m,
+ var trimmer = /^\s*(.+)\s*$/m,
matches = trimmer.exec(cmd);
if (matches && matches.length === 2) {
* Converts commands that use var and function <name>() to use the
* local exports.context when evaled. This provides a local context
* on the REPL.
- *
+ *
* @param {String} cmd The cmd to convert
* @returns {String} The converted command
*/
var self = this, matches,
scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m,
scopeFunc = /^\s*function\s*([_\w\$]+)/;
-
+
// Replaces: var foo = "bar"; with: self.context.foo = bar;
matches = scopeVar.exec(cmd);
if (matches && matches.length === 3) {
return "self.context." + matches[1] + matches[2];
}
-
+
// Replaces: function foo() {}; with: foo = function foo() {};
matches = scopeFunc.exec(self.buffered_cmd);
if (matches && matches.length === 2) {
return matches[1] + " = " + self.buffered_cmd;
}
-
+
return cmd;
};
StringDecoder.prototype.write = function (buffer) {
- // If not utf8...
+ // If not utf8...
if (this.encoding !== 'utf8') {
return buffer.toString(this.encoding);
}
}
int gid;
-
+
if (args[0]->IsNumber()) {
gid = args[0]->Int32Value();
} else if (args[0]->IsString()) {
enum encoding e = ParseEncoding(args[1], UTF8);
Local<Integer> length =
- Integer::New(e == UTF8 ? s->Utf8Length() : s->Length());
-
+ Integer::New(e == UTF8 ? s->Utf8Length() : s->Length());
+
return scope.Close(length);
}
static Handle<Value> IsIP(const Arguments& args) {
HandleScope scope;
-
+
if (!args[0]->IsString()) {
return scope.Close(Integer::New(4));
}
delete [] buf;
Local<Value> outString;
- if (out_len==0) {
+ if (out_len==0) {
outString=String::New("");
} else {
if (args.Length() <= 2 || !args[2]->IsString()) {
static Handle<Value> SendFile(const Arguments& args) {
HandleScope scope;
- if (args.Length() < 4 ||
+ if (args.Length() < 4 ||
!args[0]->IsInt32() ||
!args[1]->IsInt32() ||
!args[3]->IsNumber()) {
NODE_SET_METHOD(target, "readlink", ReadLink);
NODE_SET_METHOD(target, "unlink", Unlink);
NODE_SET_METHOD(target, "write", Write);
-
+
NODE_SET_METHOD(target, "chmod", Chmod);
NODE_SET_METHOD(target, "chown", Chown);
// No copying is performed when slicing the buffer, only small reference
// allocations.
-
+
namespace node {
using namespace v8;
String::Utf8Value type(args[0]->ToString());
- Parser *parser;
+ Parser *parser;
if (0 == strcasecmp(*type, "request")) {
parser = new Parser(HTTP_REQUEST);
if (parser->got_exception_) return Local<Value>();
Local<Integer> nparsed_obj = Integer::New(nparsed);
- // If there was a parse error in one of the callbacks
+ // If there was a parse error in one of the callbacks
// TODO What if there is an error on EOF?
if (!parser->parser_.upgrade && nparsed != len) {
Local<Value> e = Exception::Error(String::NewSymbol("Parse Error"));
enum { CHAR, HEX0, HEX1 } state = CHAR;
- int n, m, hexchar;
+ int n, m, hexchar;
size_t in_index = 0, out_index = 0;
char c;
for (; in_index <= l; in_index++) {
HandleScope scope;
int priority = args[0]->Int32Value();
-
+
ev_set_priority(&idle->watcher_, priority);
return Undefined();
}
-//
+//
// var idle = new process.IdleWatcher();
// idle.callback = function () { /* ... */ };
// idle.start();
}
-//
+//
// var io = new process.IOWatcher();
// process.callback = function (readable, writable) { ... };
// io.set(fd, true, false);
memset(&in6, 0, sizeof in6);
int port = first->Int32Value();
- in.sin_port = in6.sin6_port = htons(port);
+ in.sin_port = in6.sin6_port = htons(port);
in.sin_family = AF_INET;
in6.sin6_family = AF_INET6;
}
-// Bind with UNIX
+// Bind with UNIX
// t.bind(fd, "/tmp/socket")
// Bind with TCP
// t.bind(fd, 80, "192.168.11.2")
return ThrowException(ErrnoException(errno, "getsockopt"));
}
- return scope.Close(Integer::New(error));
+ return scope.Close(Integer::New(error));
}
struct sockaddr_storage address_storage;
socklen_t addrlen = sizeof(struct sockaddr_storage);
- ssize_t bytes_read = recvfrom(fd, (char*)buffer->data() + off, len, flags,
+ ssize_t bytes_read = recvfrom(fd, (char*)buffer->data() + off, len, flags,
(struct sockaddr*) &address_storage, &addrlen);
if (bytes_read < 0) {
//
// XXX: Some implementations can send multiple file descriptors in a
// single message. We should be using CMSG_NXTHDR() to walk the
- // chain to get at them all. This would require changing the
+ // chain to get at them all. This would require changing the
// API to hand these back up the caller, is a pain.
int received_fd = -1;
FD_ARG(args[0])
- if (!Buffer::HasInstance(args[1])) {
+ if (!Buffer::HasInstance(args[1])) {
return ThrowException(Exception::TypeError(
String::New("Second argument should be a buffer")));
}
static Handle<Value> IsIP(const Arguments& args) {
HandleScope scope;
-
+
if (!args[0]->IsString()) {
return scope.Close(Integer::New(4));
}
int errorno = args[0]->Int32Value();
String::Utf8Value syscall(args[1]->ToString());
- Local<Value> exception = ErrnoException(errorno, *syscall);
+ Local<Value> exception = ErrnoException(errorno, *syscall);
return scope.Close(exception);
}
}
const int fnIndex = sbIndex + (cFlag == newContext ? 1 : 0);
- Local<String> filename = args.Length() > fnIndex
+ Local<String> filename = args.Length() > fnIndex
? args[fnIndex]->ToString()
: String::New("evalmachine.<anonymous>");
if (!nScript) {
return ThrowException(Exception::Error(
String::New("Must be called as a method of Script.")));
- }
+ }
nScript->script_ = Persistent<v8::Script>::New(script);
result = args.This();
}
target->Set(String::NewSymbol("SignalWatcher"),
constructor_template->GetFunction());
-
+
callback_symbol = NODE_PSYMBOL("callback");
}
ev_signal_init(&watcher_, SignalWatcher::Callback, sig);
watcher_.data = this;
}
-
+
~SignalWatcher() {
ev_signal_stop(EV_DEFAULT_UC_ &watcher_);
}
private:
static void Callback(EV_P_ ev_signal *watcher, int revents);
-
+
void Start();
void Stop();
-
+
ev_signal watcher_;
};
'google.com', // MX, multiple A records
'_xmpp-client._tcp.google.com', // SRV
'oakalynhall.co.uk' // Multiple PTR replies
- ];
+ ];
var records = ['A', 'AAAA', 'MX', 'TXT', 'SRV'];
while (ll--) {
var ip = result[ll];
var reverseCmd = "host " + ip +
- "| cut -d \" \" -f 5-" +
+ "| cut -d \" \" -f 5-" +
"| sed -e 's/\\.$//'";
child_process.exec(reverseCmd, checkReverse(ip));
}
- });
+ });
break;
case "MX":
dns.resolve(myHost, myRecord, function (error, result, ttl, cname) {
var string = "C";
exports.SomeClass = function() {
-
+
};
exports.C = function () {
-var exec = require('child_process').exec,
+var exec = require('child_process').exec,
puts = require('sys').puts;
[0, 1].forEach(function(i) {
have_tls=true;
} catch (e) {
have_tls=false;
-}
+}
if (have_tls) {
var caPem = fs.readFileSync(fixturesDir+"/test_ca.pem");
} catch (e) {
console.log("Not compiled with OPENSSL support.");
process.exit();
-}
+}
var fs = require('fs');
var sys = require('sys');
var iv = '12345678';
var cipher = crypto.createCipheriv("des-ede3-cbc", encryption_key, iv);
-var ciph = cipher.update(plaintext, 'utf8', 'hex');
+var ciph = cipher.update(plaintext, 'utf8', 'hex');
ciph += cipher.final('hex');
var decipher = crypto.createDecipheriv("des-ede3-cbc",encryption_key,iv);
} else {
throw new Error("this shouldn't be called");
}
- });
+ });
}
process.addListener("exit", function () {
e.removeAllListeners("foo")
assert.equal(0, e.listeners("foo").length)
-// Verify that removing callbacks while in emit allows emits to propagate to
+// Verify that removing callbacks while in emit allows emits to propagate to
// all listeners
callbacks_called = [ ];
} else {
console.log(fs.statSync(file).mode);
assert.equal(0777, fs.statSync(file).mode & 0777);
-
+
fs.chmodSync(file, 0644);
assert.equal(0644, fs.statSync(file).mode & 0777);
success_count++;
}
process.addListener('exit', function () {
- assert.equal(expected, errors.length,
+ assert.equal(expected, errors.length,
'Test fs sync exceptions raised, got ' + errors.length + ' expected ' + expected);
});
var ignoreError = false;
if (assertBlock) {
try {
- ignoreError = assertBlock.apply(assertBlock,
+ ignoreError = assertBlock.apply(assertBlock,
Array.prototype.slice.call(arguments));
}
catch (e) {
unlink.push(entry);
assert.equal(fs.realpathSync(entry), expected);
-
+
asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected));
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo
/tmp/node-test-realpath-d1 -> ../node-test-realpath-d2
/tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2
- /tmp/node-test-realpath-f2
+ /tmp/node-test-realpath-f2
-> /node/test/fixtures/nested-index/one/realpath-c
- /node/test/fixtures/nested-index/one/realpath-c
+ /node/test/fixtures/nested-index/one/realpath-c
-> /node/test/fixtures/nested-index/two/realpath-c
/node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js
/node/test/fixtures/cycles/root.js (hard)
});
http.cat("http://localhost:12312/", "utf8", function (err, content) {
- if (err) {
+ if (err) {
console.log("got error (this should happen)");
bad_server_got_error = true;
- }
+ }
});
});
have_openssl=false;
console.log("Not compiled with OPENSSL support.");
process.exit();
-}
+}
var request_number = 0;
var requests_sent = 0;
return o;
};
-// Create a TCP server
+// Create a TCP server
var srv = net.createServer(function(c) {
var data = '';
c.addListener('data', function(d) {
server.addListener('upgrade', function (req, socket, upgradeHead) {
error('got upgrade event');
- // test that throwing an error from upgrade gets
+ // test that throwing an error from upgrade gets
// is uncaught
throw new Error('upgrade error');
});
// wget sends an HTTP/1.0 request with Connection: Keep-Alive
//
-// Sending back a chunked response to an HTTP/1.0 client would be wrong,
-// so what has to happen in this case is that the connection is closed
-// by the server after the entity body if the Content-Length was not
+// Sending back a chunked response to an HTTP/1.0 client would be wrong,
+// so what has to happen in this case is that the connection is closed
+// by the server after the entity body if the Content-Length was not
// sent.
//
-// If the Content-Length was sent, we can probably safely honor the
-// keep-alive request, even though HTTP 1.0 doesn't say that the
-// connection can be kept open. Presumably any client sending this
-// header knows that it is extending HTTP/1.0 and can handle the
-// response. We don't test that here however, just that if the
-// content-length is not provided, that the connection is in fact
+// If the Content-Length was sent, we can probably safely honor the
+// keep-alive request, even though HTTP 1.0 doesn't say that the
+// connection can be kept open. Presumably any client sending this
+// header knows that it is extending HTTP/1.0 and can handle the
+// response. We don't test that here however, just that if the
+// content-length is not provided, that the connection is in fact
// closed.
var server_response = "";
+ " "
+ JSON.stringify(S)
+ " "
- + JSON.stringify(String.fromCharCode(i))
+ + JSON.stringify(String.fromCharCode(i))
+ " "
+ S.charCodeAt(0)
);
have_openssl=false;
console.log("Not compiled with OPENSSL support.");
process.exit();
-}
+}
var caPem = fs.readFileSync(fixturesDir+"/test_ca.pem", 'ascii');
var certPem = fs.readFileSync(fixturesDir+"/test_cert.pem", 'ascii');
};
// Create a pipe
-//
+//
// We establish a listener on the read end of the pipe so that we can
// validate any data sent back by the child. We send the write end of the
// pipe to the child and close it off in our process.
a = JSON.stringify(actual[i]);
assert.equal(e, a, "parse(" + u + ")."+i+" == "+e+"\nactual: "+a);
}
-
+
var expected = u,
actual = url.format(parseTests[u]);
-
+
assert.equal(expected, actual, "format("+u+") == "+u+"\nactual:"+actual);
}
});
-//
+//
// Tests below taken from Chiron
// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js
-//
+//
// Copyright (c) 2002-2008 Kris Kowal <http://cixar.com/~kris.kowal>
// used with permission under MIT License
-//
+//
// Changes marked with @isaacs
var bases = [
['./' , bases[3], 'fred:///s//a/b/'],
['../' , bases[3], 'fred:///s//a/'],
['../g' , bases[3], 'fred:///s//a/g'],
-
+
['../../' , bases[3], 'fred:///s//'],
['../../g' , bases[3], 'fred:///s//g'],
['../../../g', bases[3], 'fred:///s/g'],
assert.equal(e, a,
"resolve("+[relativeTest[1], relativeTest[0]]+") == "+e+
"\n actual="+a);
-});
+});