mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 07:00:59 +01:00
Rename TCP classes to sit in node hierarchy.
This commit is contained in:
parent
de6036669d
commit
31ba3cde17
48
node.html
48
node.html
@ -30,7 +30,7 @@ body {
|
||||
}
|
||||
#toc a { color: #777; }
|
||||
|
||||
h1, h2, h3 { color: inherit; }
|
||||
h1, h2, h3 { color: #aaf; }
|
||||
|
||||
h1 {
|
||||
margin: 2em 0;
|
||||
@ -42,7 +42,6 @@ h1 {
|
||||
h1 a { color: inherit; }
|
||||
|
||||
h2 {
|
||||
margin: 2em 0;
|
||||
font-size: 45px;
|
||||
line-height: inherit;
|
||||
font-weight: bold;
|
||||
@ -58,13 +57,18 @@ h3 {
|
||||
pre, code {
|
||||
font-family: monospace;
|
||||
font-size: 13pt;
|
||||
color: #eae;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding-left: 2em;
|
||||
}
|
||||
|
||||
dl {
|
||||
}
|
||||
|
||||
dt {
|
||||
color: #f55;
|
||||
color: #aaf;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@ -76,6 +80,11 @@ dd {
|
||||
a { color: #cd5; text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
.highlight {
|
||||
background: #733;
|
||||
padding: 0.2em 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
<title>node.js</title>
|
||||
<body>
|
||||
@ -104,10 +113,11 @@ a:hover { text-decoration: underline; }
|
||||
|
||||
<h1><a href="http://tinyclouds.org/node">Node</a></h1>
|
||||
|
||||
<p id="introduction"> Node is a purely evented I/O framework for <a
|
||||
href="http://code.google.com/p/v8/">V8 javascript</a>. For example, this is a
|
||||
simple web server which responds with "Hello World" after waiting two
|
||||
seconds:
|
||||
<p id="introduction"> Node is a purely asynchronous I/O framework for <a
|
||||
href="http://code.google.com/p/v8/">V8 javascript</a>.
|
||||
|
||||
<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">
|
||||
new node.http.Server(function (msg) {
|
||||
setTimeout(function () {
|
||||
@ -351,7 +361,8 @@ msg.sendHeader( 200
|
||||
|
||||
<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>
|
||||
include("mjsunit");
|
||||
|
||||
@ -362,14 +373,17 @@ function onLoad () {
|
||||
<p>Here the module <code>mjsunit</code> has provided the function
|
||||
<code>assertEquals()</code>.
|
||||
|
||||
<p> The file <code>mjsunit.js</code> must be in the same directory for this
|
||||
to work. The <code>include()</code> function will take all the exported
|
||||
objects from the file and put them into the global namespace. Because file
|
||||
loading does not happen instantaniously, 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> The module file, <code>mjsunit.js</code>, must be in the same directory
|
||||
as <code>foo.js</code> for <code>include()</code> to work. The
|
||||
<code>include()</code> function will insert all the exported objects from the
|
||||
module into the global namespace.
|
||||
|
||||
<p> To export an object, add to the special object <code>exports</code>.
|
||||
<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 class="highlight">exports</code>.
|
||||
Let's look at how <code>mjsunit.js</code> does this
|
||||
|
||||
<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)) {
|
||||
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
|
||||
<code>require()</code>. Instead of loading the exported objects into the
|
||||
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:
|
||||
<pre>
|
||||
var mjsunit = require("mjsunit");
|
||||
|
@ -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, "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)
|
||||
@ -357,7 +357,7 @@ Acceptor::Initialize (Handle<Object> target)
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "listen", v8Listen);
|
||||
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)
|
||||
|
@ -271,8 +271,10 @@ main (int argc, char *argv[])
|
||||
|
||||
File::Initialize(g);
|
||||
|
||||
Acceptor::Initialize(g);
|
||||
Connection::Initialize(g);
|
||||
Local<Object> tcp = Object::New();
|
||||
node->Set(String::New("tcp"), tcp);
|
||||
Acceptor::Initialize(tcp);
|
||||
Connection::Initialize(tcp);
|
||||
|
||||
Local<Object> http = Object::New();
|
||||
node->Set(String::New("http"), http);
|
||||
|
@ -57,9 +57,9 @@ function Pinger (socket) {
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
var server = new TCPServer(Ponger);
|
||||
var server = new node.tcp.Server(Ponger);
|
||||
server.listen(port);
|
||||
|
||||
var client = new TCPConnection(Pinger);
|
||||
var client = new node.tcp.Connection(Pinger);
|
||||
client.connect(port);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
p({hello: "world"});
|
||||
new node.http.Server(function (msg) {
|
||||
setTimeout(function () {
|
||||
// setTimeout(function () {
|
||||
msg.sendHeader(200, [["Content-Type", "text/plain"]]);
|
||||
msg.sendBody("Hello World");
|
||||
msg.finish();
|
||||
}, 2000);
|
||||
// }, 1);
|
||||
}).listen(8000, "localhost");
|
Loading…
Reference in New Issue
Block a user