ebb_request_parser.c: deps/ebb/ebb_request_parser.rl
ragel -s -G2 $< -o $@
+PASS="\033[1;32mPASS\033[0m\n"
+FAIL="\033[1;31mFAIL\033[0m\n"
+
+test: node test/test_*
+ @for i in test/test_*; do \
+ if [ -x $$i ]; then \
+ echo "\n\033[1m$$i\033[0m"; \
+ ./$$i && echo $(PASS) || echo $(FAIL); \
+ fi \
+ done
+
clean:
rm -f ebb_request_parser.c
rm -f *.o
+WHEREAS, Evented, asynchornous programming better models reality; and
+
+WHEREAS, Servers organized around event loops are more efficent; and
+
WHEREAS, The usage of threads has complicated computer programming; and
-WHEREAS, V8 javascript comes free of I/O and threads; and
+WHEREAS, Most operating systems do not provide asynchonous file system access.
+
+WHEREAS, Javascript is a language without a concept of I/O or threads; and
+
+WHEREAS, Users familar with using Javascript in the web browser already program using events and callbacks; and
+
+WHEREAS, The V8 javascript comes free of I/O and threads; and
+
+WHEREAS, The V8 javascript compiles Javascript code directly to Assembler; and
-WHEREAS, Most operating systems do not provide asynchonous file system
-access.
+WHEREAS, The libev event loop abstraction provides access to the best event loop interface on each system.
Now, therefore:
printf("%s\n", *value);
fflush(stdout);
- return v8::Undefined();
+ return Undefined();
}
static void
#include "node.h"
#include "node_timer.h"
+#include <assert.h>
using namespace v8;
ev_tstamp after = (double)delay / 1000.0;
+ if (args.Length() > 2)
+ assert(0 && "extra params to setTimeout not yet implemented.");
int argc = 0;
Handle<Value> argv[] = {};
/*
( const Arguments& args
)
{
+ assert(0 && "not implemented");
}
void
--- /dev/null
+require 'net/http'
+require 'tempfile'
+
+$node = File.join(File.dirname(__FILE__), "../node")
+$tf = Tempfile.open("node")
+$tf.puts(DATA.read)
+$tf.close
+
+def assert(x, msg = "")
+ raise(msg) unless x
+end
+
+def assert_equal(x, y, msg = "")
+ assert(x == y, "#{x.inspect} != #{y.inspect} #{msg}")
+end
+
+def wait_for_server(host, port)
+ loop do
+ begin
+ socket = ::TCPSocket.open(host, port)
+ return
+ rescue Errno::ECONNREFUSED
+ $stderr.print "." if $DEBUG
+ $stderr.flush
+ sleep 0.2
+ end
+ end
+end
+
--- /dev/null
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + "/common"
+
+pid = fork do
+ exec($node, $tf.path)
+end
+
+begin
+ wait_for_server("localhost", 8000)
+ connection = Net::HTTP.new("localhost", 8000)
+
+ response, body = connection.get("/")
+ assert_equal(response.code, "200")
+ assert(response.chunked?)
+ assert_equal(body, "\n")
+ assert_equal(response.content_type, "text/plain")
+
+ response, body = connection.post("/", "hello world")
+ assert_equal(response.code, "200")
+ assert(response.chunked?)
+ assert_equal(body, "hello world\n")
+ assert_equal(response.content_type, "text/plain")
+ensure
+ `kill -9 #{pid}`
+end
+
+__END__
+function encode(data) {
+ var chunk = data.toString();
+ return chunk.length.toString(16) + "\r\n" + chunk + "\r\n";
+}
+
+var port = 8000;
+var server = new HTTP.Server("localhost", port);
+
+server.onRequest = function (request) {
+
+ // onBody sends null on the last chunk.
+ request.onBody = function (chunk) {
+ if(chunk) {
+ this.respond(encode(chunk));
+ } else {
+ this.respond(encode("\n"));
+ this.respond("0\r\n\r\n");
+ this.respond(null); // signals end-of-request
+ }
+ }
+ request.respond("HTTP/1.0 200 OK\r\n");
+ request.respond("Content-Type: text/plain\r\n");
+ request.respond("Transfer-Encoding: chunked\r\n");
+ request.respond("\r\n");
+};
+
+log("Running at http://localhost:" + port + "/");