From 6244f7782209ec3bcd1d839e511d21564587d477 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 21 May 2009 12:33:57 +0200 Subject: [PATCH] Beginnings of file i/o docs. Finish up timers. --- src/file.cc | 1 + src/file.js | 2 +- website/node.html | 53 +++++++++++++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/file.cc b/src/file.cc index 95c03efef37..e932542b00a 100644 --- a/src/file.cc +++ b/src/file.cc @@ -58,6 +58,7 @@ File::Initialize (Handle target) NODE_SET_METHOD(fs, "_ffi_rename", FileSystem::Rename); NODE_SET_METHOD(fs, "_ffi_stat", FileSystem::Stat); NODE_SET_METHOD(fs, "strerror", FileSystem::StrError); + fs->Set(String::NewSymbol("STDIN_FILENO"), Integer::New(STDIN_FILENO)); fs->Set(String::NewSymbol("STDOUT_FILENO"), Integer::New(STDOUT_FILENO)); fs->Set(String::NewSymbol("STDERR_FILENO"), Integer::New(STDERR_FILENO)); diff --git a/src/file.js b/src/file.js index 028a3b98037..3b5eb943620 100644 --- a/src/file.js +++ b/src/file.js @@ -8,7 +8,7 @@ File.stat = function (path, callback) { File.exists = function (path, callback) { this._addAction("stat", [path], function (status) { - callback(status == 0); + callback(status == 0); }); } diff --git a/website/node.html b/website/node.html index 474139d8e48..462614659cd 100644 --- a/website/node.html +++ b/website/node.html @@ -131,7 +131,7 @@ puts("Server running at http://127.0.0.1:8000/"); Node is an evented sandbox where users cannot execute blocking I/O. This is already natural for Javascript programmers, as the DOM is almost entirely -asynchronous. The goal is to provide an easy way to create +asynchronous. The goal is a framework to easily create efficient network applications. @@ -182,37 +182,54 @@ always have a capital first letter.
node.debug(string)
A synchronous output function. Will block the process and output the string immediately to stdout. Use with care.
-

Timers

-

Timers allow one to schedule execution of a function for a later time. +

+
setTimeout(callback, delay)
+
To schedule execution of callback after delay + milliseconds. Returns a timeoutId for possible use with + clearTimeout(). -

Timers in Node work as they do in the browser: -setTimeout(), -setInterval(), -clearTimeout(), -clearInterval(). -See Mozilla's - documentation for more information. +

clearTimeout(timeoutId)
+
Prevents said timeout from triggering. + +
setInterval(callback, delay)
+
To schedule the repeated execution of callback every + delay milliseconds. Returns a intervalId for + possible use with clearInterval(). + +
clearInterval(intervalId)
+
Stops a interval from triggering.
+

node.File

File system I/O has always been tricky because there are not any portable -ways of doing non-blocking file I/O. To get around this, Node uses an internal -thread pool to execute file system calls. Internal request queues exist for -each node.File instance so that multiple commands can be issued at -once without worry that they will reach the file system out of order. -Thus the following is safe: -

file.open("/tmp/blah", "w+");
+non-blocking ways to do it. To get around this, Node uses an internal thread pool
+to execute file system calls asynchronously.  
+
+
+

All file I/O calls are rather thin wrappers around standard POSIX functions. +All calls have an optional last callback parameter + + + + +

Internal request queues exist for each file object so multiple commands can +be issued at once without worry that they will reach the file system out of +order. Thus the following is safe: +

+var file = new node.File();
+file.open("/tmp/blah", "w+");
 file.write("hello ");
 file.write("world");
 file.close();
Additionally there is a process-wide queue for all commands which operate on the file system directory structure (like rename and -unlink.) It's important to understand that all of these request queues are +unlink). It's important to understand that all of these request queues are distinct. If, for example, you do
fileA.write("hello");
 fileB.write("world");