|
jsio
jsio module
jsio moduleThis module is based on Netscape Portable Runtime (NSPR) that provides a platform-neutral API for system level and libc like functions. NSPR API is used in the Mozilla client, many of Netscape/AOL/iPlanet's and other software offerings. Static functions
This function listen for a readable, writable or exception event on each descriptor in descriptorArray. When an event occurs, the function tries to call the corresponding property (function) on the descriptor.
Returns true if the descriptor can be read without blocking.
Returns true if the descriptor can be write without blocking.
Returns the milliseconds value of NSPR's free-running interval timer.
Returns the microseconds value of NSPR's free-running interval timer.
Sleeps milliseconds milliseconds.
Retrieve the value of the given environment variable.
Provides, depending on platform, a random value. The length of the random value is dependent on platform and the platform's ability to provide a random value at that moment.
Tests the value of the semaphore. If the value of the semaphore is > 0, the value of the semaphore is decremented and the function returns. If the value of the semaphore is 0, the function blocks until the value becomes > 0, then the semaphore is decremented and the function returns.
Increments the value of a specified semaphore.
This function starts a new process optionaly using the array argv for arguments or <undefined>. If waitExit is true, the function waits the end of the process and returns its exit code. If waitExit is not true, the function immediately returns an array that contains an input pipe and an output pipe to the current process stdin and stdout. Static properties
Is the host name with the domain name (if any).
Is the amount of physical RAM in the system in bytes.
Returns an object that contains an architecture, a name and a release property.
Is the current process priority among the following values:
is the current working directory. jsio::Descriptor classMethods
Close the descriptor.
Read amount bytes of data from the current descriptor. If amount is ommited, the whole available data is read. If the descriptor is exhausted (eof or disconnected), this function returns <undefined>.
If the whole data cannot be written, Write returns that have not be written.
Sync any buffered data for a fd to its backing device. Properties
Determine the amount of data in bytes available for reading on the descriptor.
see constants. Static functions
Constants
Native Interface
jsio::Directory classThis class manages directory I/O Functions. Methods
Open the directory.
Close the specified directory.
Reads an item of the current directory and go to the next.
Create the directory given in the constructor.
Removes the directory given in the constructor. Properties
Check if the directory exists.
Returns the name of the directory. Static functions
Read all entries of a directory at once. Constants
Do not skip any files. Skip the directory entry "." representing the current directory. Skip the directory entry ".." representing the parent directory. Skip both "." and ".." ( same as Directory.SKIP_DOT | Directory.SKIP_DOT_DOT ) Skip hidden files. On Windows platforms and the Mac OS, this value identifies files with the "hidden" attribute set. On Unix platform, this value identifies files whose names begin with a period ("."). Examplevar dir = new Directory( 'c:/tmp' );
dir.Open();
for ( var entry; ( entry = dir.Read() ); ) {
var file = new File(dir.name+'/'+entry);
Print( entry + ' ('+ file.info.type +')', '\n');
}Examplefunction RecursiveDir(path) {
var testList = [];
(function(path) {
var dir = new Directory(path);
dir.Open();
for ( var entry; ( entry = dir.Read(Directory.SKIP_BOTH) ); ) {
var file = new File(dir.name+'/'+entry);
switch ( file.info.type ) {
case File.FILE_DIRECTORY:
arguments.callee(file.name);
break;
case File.FILE_FILE:
testList.push(file.name);
break;
}
}
dir.Close();
})(path);
return testList;
}
Print( RecursiveDir('jshost').join('\n') );jsio::File class jsio::Descriptor
Methods
Open a file for reading, writing, or both.
Moves read-write file offset.
Delete a file from the filesystem. The operation may fail if the file is open.
Lock or unlock a file for exclusive access. state can be <true> or <false>.
Move the file to another directory. Properties
Get or set the current position of the file pointer. Same as Seek() function used with SEEK_SET.
Get or set the content of the file. If the file does not exist, content is <undefined>. Setting content with <undefined> deletes the file.
Contains the name of the file. Changing this value will rename or move the file.
Contains true if the file exists.
This property works with opened and closed files. Contains an object that has the following properties: Static properties
Is a jsio::File that represents the standard input.
Is a jsio::File that represents the standard output.
Is a jsio::File that represents the standard error. Constants
Native Interface
ExampleLoadModule('jsstd');
LoadModule('jsio');
try {
var file = new File('file_test.txt');
if ( file.exist ) {
file.Open( File.RDONLY );
Print( 'file content:\n' + file.Read() );
file.Close();
}
} catch ( ex if ex instanceof IoError ) {
Print( 'IOError: ' + ex.text, '\n' );
} catch( ex ) {
throw ex;
}jsio::MemoryMapped class
Creates a new memory-mapped object using the given opened file descriptor. Properties
is the file descriptor used to construct this object. Native Interface
Examplevar f = new File('directory.cpp');
f.Open("r");
var m = new MemoryMapped(f);
Print(m);jsio::Pipe classjsio::Semaphore classjsio::SharedMemory classThis class manages shared memory between two or more process.
Creates a named shared memory area of size bytes using mode linux-like rights. Methods
Write data at offset in the shared memory.
Read length bytes from offset in the shared memory.
Clears the content of the shared memory.
Close the shared memory. Properties
Read or write the whole content of the shared memory. Setting <undefined> as value clears the memory area. Native Interface
ExempleLoadModule('jsstd');
LoadModule('jsio');
var mem1 = new SharedMemory( 'mytest', 100 );
mem1.Write('foo');
var mem2 = new SharedMemory( 'mytest', 100 );
Print( mem2.Read(3), '\n' );jsio::Socket class jsio::DescriptorSocket class is used to create a non-blocking TCP socket.
Type can be Socket.TCP or Socket.UDP. Methods
Shut down part of a full-duplex connection on a socket.
Bind an ip address to a socket. ip is the address to which the socket will be bound. If address is ommited, any address is will match.
Listen for connections on a socket. backlogSize specifies the maximum length of the queue of pending connections.
Accept a connection on a socket. This function returns a connected jsio::Socket.
Initiate a connection on a socket.
Send a specified number of bytes from an unconnected socket. See. Static functions.
Receive all data from socket which may or may not be connected. See. Static functions.
Sends a complete file pointed by fileDescriptor across a socket. Properties
Test if a nonblocking connect has completed. Is <true> if the socket is connected.
Check if the socket connection is closed.
The time to linger on close if data present. A value of zero means no linger.
Don't delay send to coalesce packets.
Allow local address reuse.
Keep connections alive.
Receive buffer size.
Send buffer size.
Maximum segment size.
Non-blocking (network) I/O.
Enable broadcast.
IP multicast loopback.
Get name of the connected peer. Return the network address for the connected peer socket.
Get port of the connected peer. Return the port for the connected peer socket.
Get socket name. Return the network address for this socket.
Get socket port. Return the port for this socket. Static functions
Lookup a host by name and returns the results in a javascript array.
see Socket::SendTo
see Socket::RecvFrom Constants
Native Interface
jsio::IoError classYou cannot construct this class. Its aim is to throw as an exception on any NSPR runtime error. Properties
|
Sign in to add a comment
