Browse Source

Rename TCP classes to sit in node hierarchy.

v0.7.4-release
Ryan 16 years ago
parent
commit
31ba3cde17
  1. 48
      node.html
  2. 4
      src/net.cc
  3. 6
      src/node.cc
  4. 4
      test/test-pingpong.js
  5. 4
      test_http.js

48
node.html

@ -30,7 +30,7 @@ body {
} }
#toc a { color: #777; } #toc a { color: #777; }
h1, h2, h3 { color: inherit; } h1, h2, h3 { color: #aaf; }
h1 { h1 {
margin: 2em 0; margin: 2em 0;
@ -42,7 +42,6 @@ h1 {
h1 a { color: inherit; } h1 a { color: inherit; }
h2 { h2 {
margin: 2em 0;
font-size: 45px; font-size: 45px;
line-height: inherit; line-height: inherit;
font-weight: bold; font-weight: bold;
@ -58,13 +57,18 @@ h3 {
pre, code { pre, code {
font-family: monospace; font-family: monospace;
font-size: 13pt; font-size: 13pt;
color: #eae;
}
pre {
padding-left: 2em;
} }
dl { dl {
} }
dt { dt {
color: #f55; color: #aaf;
font-weight: bold; font-weight: bold;
} }
@ -76,6 +80,11 @@ dd {
a { color: #cd5; text-decoration: none; } a { color: #cd5; text-decoration: none; }
a:hover { text-decoration: underline; } a:hover { text-decoration: underline; }
.highlight {
background: #733;
padding: 0.2em 0;
}
</style> </style>
<title>node.js</title> <title>node.js</title>
<body> <body>
@ -104,10 +113,11 @@ a:hover { text-decoration: underline; }
<h1><a href="http://tinyclouds.org/node">Node</a></h1> <h1><a href="http://tinyclouds.org/node">Node</a></h1>
<p id="introduction"> Node is a purely evented I/O framework for <a <p id="introduction"> Node is a purely asynchronous I/O framework for <a
href="http://code.google.com/p/v8/">V8 javascript</a>. For example, this is a href="http://code.google.com/p/v8/">V8 javascript</a>.
simple web server which responds with "Hello World" after waiting two
seconds: <p>This is an example of a web server written with Node which responds with
"Hello World" after waiting two seconds:
<pre class="sh_javascript"> <pre class="sh_javascript">
new node.http.Server(function (msg) { new node.http.Server(function (msg) {
setTimeout(function () { setTimeout(function () {
@ -351,7 +361,8 @@ msg.sendHeader( 200
<h3 id="modules">Modules</h3> <h3 id="modules">Modules</h3>
<p>Node has simple module loading. Here is an example of loading a module: <p>Node has simple module loading. Here is an example. This is the file
<code>foo.js</code>:
<pre> <pre>
include("mjsunit"); include("mjsunit");
@ -362,14 +373,17 @@ function onLoad () {
<p>Here the module <code>mjsunit</code> has provided the function <p>Here the module <code>mjsunit</code> has provided the function
<code>assertEquals()</code>. <code>assertEquals()</code>.
<p> The file <code>mjsunit.js</code> must be in the same directory for this <p> The module file, <code>mjsunit.js</code>, must be in the same directory
to work. The <code>include()</code> function will take all the exported as <code>foo.js</code> for <code>include()</code> to work. The
objects from the file and put them into the global namespace. Because file <code>include()</code> function will insert all the exported objects from the
loading does not happen instantaniously, and because Node has a policy of module into the global namespace.
never blocking, the callback <code>onLoad()</code> is provided to notify the
user when all the exported functions are completely loaded. <p> Because file loading does not happen instantaneously, and because Node
has a policy of never blocking, the callback <code>onLoad()</code> is
provided to notify the user when all the exported functions are completely
loaded.
<p> To export an object, add to the special object <code>exports</code>. <p> To export an object, add to the special object <code class="highlight">exports</code>.
Let's look at how <code>mjsunit.js</code> does this Let's look at how <code>mjsunit.js</code> does this
<pre> <pre>
@ -381,7 +395,7 @@ function deepEquals (a, b) {
// ... // ...
} }
exports.assertEquals = function (expected, found, name_opt) { <span class="highlight">exports</span>.assertEquals = function (expected, found, name_opt) {
if (!deepEquals(found, expected)) { if (!deepEquals(found, expected)) {
fail(expected, found, name_opt); fail(expected, found, name_opt);
} }
@ -393,7 +407,7 @@ exported and remain private to the module.
<p> In addition to <code>include()</code> a module can use <p> In addition to <code>include()</code> a module can use
<code>require()</code>. Instead of loading the exported objects into the <code>require()</code>. Instead of loading the exported objects into the
global namespace, it will return a namespace object. Again, the members of global namespace, it will return a namespace object. Again, the members of
the namespace object can only be guarenteed to exist after the the namespace object can only be guaranteed to exist after the
<code>onLoad()</code> callback is made. For example: <code>onLoad()</code> callback is made. For example:
<pre> <pre>
var mjsunit = require("mjsunit"); var mjsunit = require("mjsunit");

4
src/net.cc

@ -57,7 +57,7 @@ Connection::Initialize (v8::Handle<v8::Object> target)
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fullClose", v8FullClose); NODE_SET_PROTOTYPE_METHOD(constructor_template, "fullClose", v8FullClose);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", v8ForceClose); NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", v8ForceClose);
target->Set(String::NewSymbol("TCPConnection"), constructor_template->GetFunction()); target->Set(String::NewSymbol("Connection"), constructor_template->GetFunction());
} }
Connection::Connection (Handle<Object> handle, Handle<Function> protocol_class) Connection::Connection (Handle<Object> handle, Handle<Function> protocol_class)
@ -357,7 +357,7 @@ Acceptor::Initialize (Handle<Object> target)
NODE_SET_PROTOTYPE_METHOD(constructor_template, "listen", v8Listen); NODE_SET_PROTOTYPE_METHOD(constructor_template, "listen", v8Listen);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", v8Close); NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", v8Close);
target->Set(String::NewSymbol("TCPServer"), constructor_template->GetFunction()); target->Set(String::NewSymbol("Server"), constructor_template->GetFunction());
} }
Acceptor::Acceptor (Handle<Object> handle, Handle<Function> protocol_class, Handle<Object> options) Acceptor::Acceptor (Handle<Object> handle, Handle<Function> protocol_class, Handle<Object> options)

6
src/node.cc

@ -271,8 +271,10 @@ main (int argc, char *argv[])
File::Initialize(g); File::Initialize(g);
Acceptor::Initialize(g); Local<Object> tcp = Object::New();
Connection::Initialize(g); node->Set(String::New("tcp"), tcp);
Acceptor::Initialize(tcp);
Connection::Initialize(tcp);
Local<Object> http = Object::New(); Local<Object> http = Object::New();
node->Set(String::New("http"), http); node->Set(String::New("http"), http);

4
test/test-pingpong.js

@ -57,9 +57,9 @@ function Pinger (socket) {
} }
function onLoad() { function onLoad() {
var server = new TCPServer(Ponger); var server = new node.tcp.Server(Ponger);
server.listen(port); server.listen(port);
var client = new TCPConnection(Pinger); var client = new node.tcp.Connection(Pinger);
client.connect(port); client.connect(port);
} }

4
test/test_http.js → test_http.js

@ -1,8 +1,8 @@
p({hello: "world"}); p({hello: "world"});
new node.http.Server(function (msg) { new node.http.Server(function (msg) {
setTimeout(function () { // setTimeout(function () {
msg.sendHeader(200, [["Content-Type", "text/plain"]]); msg.sendHeader(200, [["Content-Type", "text/plain"]]);
msg.sendBody("Hello World"); msg.sendBody("Hello World");
msg.finish(); msg.finish();
}, 2000); // }, 1);
}).listen(8000, "localhost"); }).listen(8000, "localhost");
Loading…
Cancel
Save