AppServ | AppServRequest | CustomError | CustomException | Dir | DirEnt | Errno | Event | FD | FS | File | GD | GDFont | GDImage | PG | PGCancel | PGConn | PGDataResult | PGNotifies | PGPrintOpt | PGResult | RecvQ | SendQ | Stat | Syslog
Provided by js-appserv(8) only. Allows the JS application to access properties and control functions in order to serve clients as it wishes. See the mmserver2(3) manual page for internal details, on which js-appserv(8) is based. js-appserv(8) consists of a processes pool-based server written in C which delegates control to a JavaScript application to serve the clients.
The application should provide the following functions:
void child_init_hook(void); - To be invoked when a new child process is created in the pool.
void child_exit_hook(void); - To be invoked when the child process exists. Note that a process may serve multiple connections before exiting.
void child_sigalrm_hook(void); - Invoked when a SIGALRM signal is received. Controlled via AppServ.alarm().
void request_handler(req::AppServRequest); - Function to handle the client in normal conditions.
void reject_handler(req::AppServRequest, reason::Number); - Function to handle the client in resource exceeded conditions. Allows to provide a protocol-friendly response before the connection gets closed. reason specifies the reason for the rejection, and may be one of AppServ.REASON_CACHE_SIZE, AppServ.REASON_CONCURRENCY or AppServ.REASON_RATE.
void request_close_hook(req::AppServRequest); - Invoked when the connection to the client is about to be closed, always.
void request_interrupt_hook(req::AppServRequest); - If the server is configured to interrupt currently served clients when the SIGHUP or SIGKILL signals are received, this function is invoked.
Constructors | Static Properties | Static Methods | Properties | Methods
REASON_CACHE_SIZE | REASON_CONCURRENCY | REASON_RATE
REASON_CACHE_SIZE::Number (ro) (Static Properties)
The address cache size for this socket was exceeded.
REASON_CONCURRENCY::Number (ro) (Static Properties)
The address exceeded its allowed maximum number of concurrent connections.
REASON_RATE::Number (ro) (Static Properties)
The address exceeded its allowed connections rate.
Number alarm(seconds::Number); (Static Methods)
An alarm(3) clone internally impemented using setitimer(3). Unlike alarm(3), always returns 0. Useful to observe timeouts.
Number
0.
seconds::Number
Number of seconds before timeout occurs, causing the SIGALRM handler function to be invoked. 0 disables any timer. Otherwise resets any previously existing timer tothe new timeout.
Client request object. Holds necessary information about the client to communicate with it. Provided as an argument to the request_handler() and reject_handler() user functions.
Constructors | Static Properties | Static Methods | Properties | Methods
client_address_concurrency | client_address_hostname | client_address_name | client_port | client_socket | packet_data | server_socket | server_socket_address_name | server_socket_family | server_socket_port | server_socket_type
client_address_concurrency::Number (ro) (Properties)
Number of simultaneous current connections for this address.
client_address_hostname::String (ro) (Properties)
Hostname of the client's address.
client_address_name::String (ro) (Properties)
Address of the client.
client_port::Number (ro) (Properties)
IP port of the client.
client_socket::Number (ro) (Properties)
Unix file descriptor number of the client socket. This is used to serve the client.
packet_data::String (ro) (Properties)
If serving UDP clients, the first received packet.
server_socket::Number (ro) (Properties)
Unix file descriptor number of the server listening socket. Usually only useful to bind UDP sockets.
server_socket_address_name::String (ro) (Properties)
Address the server socket was bound to.
server_socket_family::Number (ro) (Properties)
server_socket_port::Number (ro) (Properties)
IP port of the server socket the client was accepted on.
server_socket_type::Number (ro) (Properties)
Extends Error
This class extends the system Error class as should normally be done. However, when doing so the stack backtrace becomes unavailable, possibly as the result of a SpiderMonkey bug. Thus, it is recommended to use CustomException instead.
Constructors | Static Properties | Static Methods | Properties | Methods
void CustomError(name::String, errnum::Number, message::String); (Constructors)
This constructor may be invoked as a method or as a constructor, that is, using the new keyword or without it.
name::String
The name or type of error. Examples are SyntaxError and TypeError.
errnum::Number
Numeric error code to associate to this error object. This can reflect the internal errno error, but does not have to. It is recommended to use codes from errno(2) when possible.
message::String
Associated message to describe the error and provide more details. Has no formal structure. The backtrace often provides enough context information, yet this may convey useful other details. May optionally map to the corresponding text of an errno code.
This actually creates an Error system object and then adds custom properties to this. This allows the stack backtrace to be available which is most useful.
Unlike CustomError, this does not extend the system Error class. This means that the code cannot use instanceof to determine the type of exception/error. Instead, conditionals such as x.name == 'IOException' may be used instead.
The C classes invoke customexception_throw() to generate the same object and also preserve the stack backtrace.
Constructors | Static Properties | Static Methods | Properties | Methods
void CustomException(name::String, errnum::Number, message::String); (Constructors)
This constructor may be invoked as a method or as a constructor, that is, using the new keyword or without it.
name::String
The name or type of error. Examples are SyntaxError and TypeError, or IOException.
errnum::Number
Numeric error code to associate to this error object. This can reflect the internal errno error, but does not have to. It is recommended to use codes from errno(2) when possible.
message::String
Associated message to describe the error and provide more details. Has no formal structure. The backtrace often provides enough context information, yet this may convey useful other details. May optionally map to the corresponding text of an errno code.
A C opendir(3) and friends wrapper class. Allows to iterate over directory entries. Also see FD.fstat(). Note that deleting a Dir object also closes the directory.
Constructors | Static Properties | Static Methods | Properties | Methods
void Dir(path::String); (Constructors)
Creates a Dir object opening a directory.
path::String
Path to directory to be opened.
IOException
Object holds details.
SecurityException
Path was not allowed access to.
DT_BLK | DT_CHR | DT_DIR | DT_FIFO | DT_LNK | DT_REG | DT_SOCK | DT_UNKNOWN
DT_BLK::Number (ro) (Static Properties)
File is a block device.
DT_CHR::Number (ro) (Static Properties)
File is a character device.
DT_DIR::Number (ro) (Static Properties)
File is a directory.
DT_FIFO::Number (ro) (Static Properties)
File is a FIFO.
DT_LNK::Number (ro) (Static Properties)
File is a link.
DT_REG::Number (ro) (Static Properties)
File is a regular file.
DT_SOCK::Number (ro) (Static Properties)
File is a unix socket.
DT_UNKNOWN::Number (ro) (Static Properties)
Unknown file type.
close | read | rewind | seek | tell
Number close(void); (Methods)
Closes the stream.
Number
status 0 on success, or an errno value on failure (see the Errno class for details).
DirEnt|null read(void); (Methods)
Iterating over directory entries, returns the next entry.
DirEnt|null
Returns a DirEnt object which holds information about the file. null is returned after the last entry has been retreived.
void rewind(void); (Methods)
Rewinds/resets stream position to the initial location.
void seek(loc::Number); (Methods)
Return to a previous location.
loc::Number
Location to return to. Note that only previous positions returned by former calls to Dir.tell() are valid to pass to this method.
Number tell(void); (Methods)
Reports current position in stream.
Number
Current position, for use with Dir.seek().
Represents a directory entry. Not an actual class per say, but an untyped object, holding properties. These are returned by Dir.read().
Constructors | Static Properties | Static Methods | Properties | Methods
fileno::Number (ro) (Properties)
File number of entry.
name::String (ro) (Properties)
File name.
type::Number (ro) (Properties)
File type.
This class allows to work with C and unix native error codes. It simply consists of a wrapper around strerror(3) and errno(2).
Constructors | Static Properties | Static Methods | Properties | Methods
EACCES | EADDRINUSE | EADDRNOTAVAIL | EAFNOSUPPORT | EAGAIN | EALREADY | EBADF | EBADMSG | EBUSY | ECANCELED | ECONNABORTED | ECONNREFUSED | ECONNRESET | EDESTADDRREQ | EDQUOT | EEXIST | EFBIG | EFTYPE | EHOSTDOWN | EHOSTUNREACH | EINPROGRESS | EINTR | EINVAL | EIO | EISCONN | EISDIR | ELOOP | EMFILE | EMLINK | EMSGSIZE | ENAMETOOLONG | ENETDOWN | ENETRESET | ENETUNREACH | ENFILE | ENOBUFS | ENODATA | ENODEV | ENOENT | ENOLCK | ENOMSG | ENOSPC | ENOSYS | ENOTBLK | ENOTCONN | ENOTDIR | ENOTEMPTY | ENOTSOCK | ENOTSUP | ENOTTY | ENXIO | EOPNOTSUPP | EPERM | EPFNOSUPPORT | EPIPE | EPROTONOSUPPORT | EPROTOTYPE | EROFS | ESHUTDOWN | ESPIPE | ESTALE | ETIME | ETIMEDOUT | ETXTBSY | EXDEV
EACCES::Number (ro) (Static Properties)
EADDRINUSE::Number (ro) (Static Properties)
EADDRNOTAVAIL::Number (ro) (Static Properties)
EAFNOSUPPORT::Number (ro) (Static Properties)
EAGAIN::Number (ro) (Static Properties)
EALREADY::Number (ro) (Static Properties)
EBADF::Number (ro) (Static Properties)
EBADMSG::Number (ro) (Static Properties)
EBUSY::Number (ro) (Static Properties)
ECANCELED::Number (ro) (Static Properties)
ECONNABORTED::Number (ro) (Static Properties)
ECONNREFUSED::Number (ro) (Static Properties)
ECONNRESET::Number (ro) (Static Properties)
EDESTADDRREQ::Number (ro) (Static Properties)
EDQUOT::Number (ro) (Static Properties)
EEXIST::Number (ro) (Static Properties)
EFBIG::Number (ro) (Static Properties)
EFTYPE::Number (ro) (Static Properties)
EHOSTDOWN::Number (ro) (Static Properties)
EHOSTUNREACH::Number (ro) (Static Properties)
EINPROGRESS::Number (ro) (Static Properties)
EINTR::Number (ro) (Static Properties)
EINVAL::Number (ro) (Static Properties)
EIO::Number (ro) (Static Properties)
EISCONN::Number (ro) (Static Properties)
EISDIR::Number (ro) (Static Properties)
ELOOP::Number (ro) (Static Properties)
EMFILE::Number (ro) (Static Properties)
EMLINK::Number (ro) (Static Properties)
EMSGSIZE::Number (ro) (Static Properties)
ENAMETOOLONG::Number (ro) (Static Properties)
ENETDOWN::Number (ro) (Static Properties)
ENETRESET::Number (ro) (Static Properties)
ENETUNREACH::Number (ro) (Static Properties)
ENFILE::Number (ro) (Static Properties)
ENOBUFS::Number (ro) (Static Properties)
ENODATA::Number (ro) (Static Properties)
ENODEV::Number (ro) (Static Properties)
ENOENT::Number (ro) (Static Properties)
ENOLCK::Number (ro) (Static Properties)
ENOMSG::Number (ro) (Static Properties)
ENOSPC::Number (ro) (Static Properties)
ENOSYS::Number (ro) (Static Properties)
ENOTBLK::Number (ro) (Static Properties)
ENOTCONN::Number (ro) (Static Properties)
ENOTDIR::Number (ro) (Static Properties)
ENOTEMPTY::Number (ro) (Static Properties)
ENOTSOCK::Number (ro) (Static Properties)
ENOTSUP::Number (ro) (Static Properties)
ENOTTY::Number (ro) (Static Properties)
ENXIO::Number (ro) (Static Properties)
EOPNOTSUPP::Number (ro) (Static Properties)
EPERM::Number (ro) (Static Properties)
EPFNOSUPPORT::Number (ro) (Static Properties)
EPIPE::Number (ro) (Static Properties)
EPROTONOSUPPORT::Number (ro) (Static Properties)
EPROTOTYPE::Number (ro) (Static Properties)
EROFS::Number (ro) (Static Properties)
ESHUTDOWN::Number (ro) (Static Properties)
ESPIPE::Number (ro) (Static Properties)
ESTALE::Number (ro) (Static Properties)
ETIME::Number (ro) (Static Properties)
ETIMEDOUT::Number (ro) (Static Properties)
ETXTBSY::Number (ro) (Static Properties)
EXDEV::Number (ro) (Static Properties)
String strerror(code::Number); (Static Methods)
Returns string describing an error code.
String
String describing the supplied code.
code::Number
Error code to translate.
This class allows to use efficient OS primitives for events, through the event(3) library. For instance, on BSD systems, kqueue(2) is used internally, which not only is a system which exceeds dramatically the performance of poll(2), but also supports a number of event types other than for file descriptor polling.
Currently, only file descriptor polling is supported in JS using FD objects. There are however plans to eventually support signal and timer events as well.
This is a callback driven system. This means that you must register descriptors and events you're interested in as well as which JS functions to execute, and call a dispatch function. Very much like unix signal handling. This allows the main processing loop to remain in C.
Constructors | Static Properties | Static Methods | Properties | Methods
EVLOOP_NONBLOCK | EVLOOP_ONCE | EV_PERSIST | EV_READ | EV_SIGNAL | EV_TIMEOUT | EV_WRITE | SIGABRT | SIGALRM | SIGBUS | SIGCHLD | SIGCONT | SIGEMT | SIGFPE | SIGHUP | SIGILL | SIGINFO | SIGINT | SIGIO | SIGKILL | SIGPIPE | SIGPROF | SIGPWR | SIGQUIT | SIGSEGV | SIGSTOP | SIGSYS | SIGTERM | SIGTRAP | SIGTSTP | SIGTTIN | SIGTTOU | SIGURG | SIGUSR1 | SIGUSR2 | SIGVTALRM | SIGWINCH | SIGXCPU | SIGXFSZ
EVLOOP_NONBLOCK::Number (ro) (Static Properties)
EVLOOP_ONCE::Number (ro) (Static Properties)
EV_PERSIST::Number (ro) (Static Properties)
EV_READ::Number (ro) (Static Properties)
EV_SIGNAL::Number (ro) (Static Properties)
EV_TIMEOUT::Number (ro) (Static Properties)
EV_WRITE::Number (ro) (Static Properties)
SIGABRT::Number (ro) (Static Properties)
SIGALRM::Number (ro) (Static Properties)
SIGBUS::Number (ro) (Static Properties)
SIGCHLD::Number (ro) (Static Properties)
SIGCONT::Number (ro) (Static Properties)
SIGEMT::Number (ro) (Static Properties)
SIGFPE::Number (ro) (Static Properties)
SIGHUP::Number (ro) (Static Properties)
SIGILL::Number (ro) (Static Properties)
SIGINFO::Number (ro) (Static Properties)
SIGINT::Number (ro) (Static Properties)
SIGIO::Number (ro) (Static Properties)
SIGKILL::Number (ro) (Static Properties)
SIGPIPE::Number (ro) (Static Properties)
SIGPROF::Number (ro) (Static Properties)
SIGPWR::Number (ro) (Static Properties)
SIGQUIT::Number (ro) (Static Properties)
SIGSEGV::Number (ro) (Static Properties)
SIGSTOP::Number (ro) (Static Properties)
SIGSYS::Number (ro) (Static Properties)
SIGTERM::Number (ro) (Static Properties)
SIGTRAP::Number (ro) (Static Properties)
SIGTSTP::Number (ro) (Static Properties)
SIGTTIN::Number (ro) (Static Properties)
SIGTTOU::Number (ro) (Static Properties)
SIGURG::Number (ro) (Static Properties)
SIGUSR1::Number (ro) (Static Properties)
SIGUSR2::Number (ro) (Static Properties)
SIGVTALRM::Number (ro) (Static Properties)
SIGWINCH::Number (ro) (Static Properties)
SIGXCPU::Number (ro) (Static Properties)
SIGXFSZ::Number (ro) (Static Properties)
addFD | delFD | dispatch | initializedFD | loop | loopExit | onceFD | pendingFD | setFD
Number addFD(fd::FD, timeout::Number|null); (Static Methods)
Permits to activate an FD object which parameters were previously set using Event.setFD(), adding it into the polling set. Note that unless the event were configured with the EV_PERSIST flag, descriptors should be added again to the set after an event occurs (this can be done in the callback function).
Number
0 on success or an errno code on error.
fd::FD
Descriptor to add to the set.
timeout::Number|null
Timeout in milliseconds after which an EV_TIMEOUT event should be generated, or null to wait indefinitely.
Number delFD(fd::FD); (Static Methods)
Removes a descriptor from the polling set. This is usually used when they are added using the EV_PERSIST flag. Otherwise descriptors are removed from the set automatically as an event occurs.
Number
0 on success or an errno code on error.
fd::FD
Descriptor to remove from the polling set.
Number dispatch(void); (Static Methods)
Invokes the event poller and dispatcher. This method never returns unless an error occurs. Descriptors and/or other type of objects and events must previously have been configured and added.
Number
An errno error code.
Boolean initializedFD(fd::FD); (Static Methods)
Tells weither or not the specified descriptor was configured using Event.setFD().
Boolean
true or false.
fd::FD
Event to verify initialization status of.
Number loop(flags::Number); (Static Methods)
Similar to Event.dispatch(), although this function returns after events are dispatched.
Number
flags::Number
Supported flags consist of Event.EVLOOP_ONCE, causing only a single event to be dispatched before returning, and Event.EVLOOP_NONBLOCK which permits the function to return even if no events could immediately be dispatched. These may be ORed, or 0 may be supplied.
void loopExit(timeout::Number); (Static Methods)
Very similar to Event.loop() except that a timeout is supplied specifying when to return.
timeout::Number
Timeout in milliseconds.
Number onceFD(fd::FD, event::Number, function::Function, udata::Object|null, timeout::Number|null); (Static Methods)
This is equivalent to configuring a descriptor using FD.setFD() and then adding it using FD.addFD() without the EV_PERSIST flag. Supported at EV_TIMEOUT, EV_READ and EV_WRITE. The callback function is scheduled to be executed only once.
Number
0 on success, or an errno code on error.
fd::FD
Descriptor to poll events for.
event::Number
ORed event types which are interesting.
function::Function
Callback function to be invoked when the event occurs. See Event.setFD() for the function signature.
udata::Object|null
Optional user data object reference to be passed to the callback for state persistency. null may be used if none is wanted.
timeout::Number|null
Timeout in milliseconds to poll for, or null to wait indefinitely.
Boolean pendingFD(fd::FD, event::Number, timeout::Object|null); (Static Methods)
Verifies if an event specified for a descriptor is pending to run.
Boolean
true if the event is pending, false otherwise.
fd::FD
Descriptor to verify for pending events.
event::Number
Event(s) to verify pending status of.
timeout::Object|null
If not null and Event.EV_TIMEOUT is as parts of event, two properties will be added to the supplied object, namely: tv_sec::Number, in seconds and tv_usec::Number in microseconds, telling in how long the event is set to expire.
void setFD(fd::FD, event::Number, function::Function, udata::Object|null); (Static Methods)
Allows to specify which type of events are to be watched for, as well as the callback function which should serve them, for an FD object. Note that it is possible to reconfigure a descriptor differently as needed.
fd::FD
File descriptor object to work on.
event::Number
Events we're interested in catching for the descriptor.
function::Function
Function to be invoked when an event occurs. The function signature is as follows:
Boolean function(fd::FD, event::Number, udata::Object);
Where fd consists of the descriptor for which there was an event, event consists of an ORed mask of received events for the descriptor, and udata is the object reference passed to the Event.setFD() method (which may be null).
udata::Object|null
User data object reference which may be passed to the function if wanted to keep a persistent state. This is provided for usefullness and compatibility with the C interface, although in JavaScript the wanted properties for state may simply be added to the FD object and accessed there in callback functions. You may pass null to this argument.
Implements support for unix file descriptor objects. Blocking, non-blocking modes are provided, as well as libevent(3) and poll(2) support. IPv4 sockets also are along with socket options. XXX Other address families should eventually be supported, although js-appserv(8) supports them already.
The static properties of this class map to the C equivalent integers. These are required for a number of functions which are basically C function mappings as well, other than having been reorganized to be more OO friendly.
Constructors | Static Properties | Static Methods | Properties | Methods
void FD(void); (Constructors)
Creates an FD object, but does not initialize it as a socket or file descriptor yet.
AF_INET | F_GETFL | F_SETFL | LOCK_EX | LOCK_NB | LOCK_SH | LOCK_UN | O_CREAT | O_NONBLOCK | O_RDONLY | O_RDWR | O_TRUNC | O_WRONLY | POLLERR | POLLHUP | POLLIN | POLLNVAL | POLLOUT | POLLPRI | POLLRDBAND | POLLRDNORM | POLLWRBAND | POLLWRNORM | SEEK_CUR | SEEK_END | SEEK_SET | SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE | SHUT_RD | SHUT_RDRW | SHUT_RW | SOCK_DGRAM | SOCK_STREAM | SO_BROADCAST | SO_DONTROUTE | SO_ERROR | SO_KEEPALIVE | SO_LINGER | SO_OOBINLINE | SO_RCVBUF | SO_RCVLOWAT | SO_RCVTIMEO | SO_REUSEADDR | SO_REUSEPORT | SO_SNDBUF | SO_SNDLOWAT | SO_SNDTIMEO | SO_TYPE | STDERR_FILENO | STDIN_FILENO | STDOUT_FILENO | S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFMT | S_IFREG | S_IFSOCK | S_IFWHT | S_IRGRP | S_IROTH | S_IRUSR | S_IRWXG | S_IRWXO | S_IRWXU | S_ISGID | S_ISUID | S_ISVTX | S_IWOTH | S_IWUSR | S_IXGRP | S_IXOTH | S_IXUSR | TCP_NODELAY | UF_APPEND | UF_IMMUTABLE | UF_NODUMP | UF_OPAQUE
AF_INET::Number (ro) (Static Properties)
F_GETFL::Number (ro) (Static Properties)
F_SETFL::Number (ro) (Static Properties)
LOCK_EX::Number (ro) (Static Properties)
LOCK_NB::Number (ro) (Static Properties)
LOCK_SH::Number (ro) (Static Properties)
LOCK_UN::Number (ro) (Static Properties)
O_CREAT::Number (ro) (Static Properties)
O_NONBLOCK::Number (ro) (Static Properties)
O_RDONLY::Number (ro) (Static Properties)
O_RDWR::Number (ro) (Static Properties)
O_TRUNC::Number (ro) (Static Properties)
O_WRONLY::Number (ro) (Static Properties)
POLLERR::Number (ro) (Static Properties)
POLLHUP::Number (ro) (Static Properties)
POLLIN::Number (ro) (Static Properties)
POLLNVAL::Number (ro) (Static Properties)
POLLOUT::Number (ro) (Static Properties)
POLLPRI::Number (ro) (Static Properties)
POLLRDBAND::Number (ro) (Static Properties)
POLLRDNORM::Number (ro) (Static Properties)
POLLWRBAND::Number (ro) (Static Properties)
POLLWRNORM::Number (ro) (Static Properties)
SEEK_CUR::Number (ro) (Static Properties)
SEEK_END::Number (ro) (Static Properties)
SEEK_SET::Number (ro) (Static Properties)
SF_APPEND::Number (ro) (Static Properties)
SF_ARCHIVED::Number (ro) (Static Properties)
SF_IMMUTABLE::Number (ro) (Static Properties)
SHUT_RD::Number (ro) (Static Properties)
SHUT_RDRW::Number (ro) (Static Properties)
SHUT_RW::Number (ro) (Static Properties)
SOCK_DGRAM::Number (ro) (Static Properties)
SOCK_STREAM::Number (ro) (Static Properties)
SO_BROADCAST::Number (ro) (Static Properties)
SO_DONTROUTE::Number (ro) (Static Properties)
SO_ERROR::Number (ro) (Static Properties)
SO_KEEPALIVE::Number (ro) (Static Properties)
SO_LINGER::Number (ro) (Static Properties)
SO_OOBINLINE::Number (ro) (Static Properties)
SO_RCVBUF::Number (ro) (Static Properties)
SO_RCVLOWAT::Number (ro) (Static Properties)
SO_RCVTIMEO::Number (ro) (Static Properties)
SO_REUSEADDR::Number (ro) (Static Properties)
SO_REUSEPORT::Number (ro) (Static Properties)
SO_SNDBUF::Number (ro) (Static Properties)
SO_SNDLOWAT::Number (ro) (Static Properties)
SO_SNDTIMEO::Number (ro) (Static Properties)
SO_TYPE::Number (ro) (Static Properties)
STDERR_FILENO::Number (ro) (Static Properties)
STDIN_FILENO::Number (ro) (Static Properties)
STDOUT_FILENO::Number (ro) (Static Properties)
S_IFBLK::Number (ro) (Static Properties)
S_IFCHR::Number (ro) (Static Properties)
S_IFDIR::Number (ro) (Static Properties)
S_IFIFO::Number (ro) (Static Properties)
S_IFLNK::Number (ro) (Static Properties)
S_IFMT::Number (ro) (Static Properties)
S_IFREG::Number (ro) (Static Properties)
S_IFSOCK::Number (ro) (Static Properties)
S_IFWHT::Number (ro) (Static Properties)
S_IRGRP::Number (ro) (Static Properties)
S_IROTH::Number (ro) (Static Properties)
S_IRUSR::Number (ro) (Static Properties)
S_IRWXG::Number (ro) (Static Properties)
S_IRWXO::Number (ro) (Static Properties)
S_IRWXU::Number (ro) (Static Properties)
S_ISGID::Number (ro) (Static Properties)
S_ISUID::Number (ro) (Static Properties)
S_ISVTX::Number (ro) (Static Properties)
S_IWOTH::Number (ro) (Static Properties)
S_IWUSR::Number (ro) (Static Properties)
S_IXGRP::Number (ro) (Static Properties)
S_IXOTH::Number (ro) (Static Properties)
S_IXUSR::Number (ro) (Static Properties)
TCP_NODELAY::Number (ro) (Static Properties)
UF_APPEND::Number (ro) (Static Properties)
UF_IMMUTABLE::Number (ro) (Static Properties)
UF_NODUMP::Number (ro) (Static Properties)
UF_OPAQUE::Number (ro) (Static Properties)
Array poll(set::Object|Array, timeout::Number); (Static Methods)
Synchronous I/O multiplexing. Waits until a delay expires or until an event occurs on the specified set of FD objects, returning another set of FD objects for which events occurred. Note that a more efficient system exists which can be used via the Event class.
Array
Array of FD objects with pending events (empty array in case of timeout). The revents property of every FD object holds the events which occurred.
set::Object|Array
Object holding FD objects to poll(2) for. The events property of every FD object must have events to poll for.
timeout::Number
Timeout in milliseconds or -1.
IOException
Object holds details.
client_addr | client_port | errno | events | fd | mode | path | revents
client_addr::String (ro) (Properties)
Client's remote IP address if any.
client_port::Number (ro) (Properties)
Client's remote IP port if any.
errno::Number (ro) (Properties)
Associated error number if any.
events::Number (rw) (Properties)
FD.POLL* events we are interested in.
fd::Number (ro) (Properties)
Internal unix C file descriptor number.
mode::Number (ro) (Properties)
Modes file was open with if any.
path::String (ro) (Properties)
Path to open file if any.
revents::Number (ro) (Properties)
FD.POLL* received events after FD.poll() call.
accept | bind | close | connect | fchmod | fchown | fcntl | fdatasync | flock | fstat | ftruncate | get | getsockopt | listen | lseek | open | put | read | set | setsockopt | shutdown | socket | write
FD accept(void); (Methods)
Attempts to accept a connection. The object must already be a bound socket which is listening.
FD
New client descriptor object.
IOException
Object holds details.
void bind(address::String, port::Number); (Methods)
Binds the descriptor to the specified address and port. Note that it must be a socket.
address::String
IPv4 address or mask (0.0.0.0 for all local interfaces).
port::Number
Port number.
IOException
Exception object holds details.
Number close(void); (Methods)
Closes the descriptor wrapped by the object. Note that deleting an FD object also closes the file descriptor, unless it was associated using FD.set().
Number
0 on success or Errno.* on error (FD.errno property also set).
void connect(address::String, port::Number); (Methods)
Attempts connection to the specified destination. If a hostname is given instead of an IPv4 address, it is resolved. Note that the object must be a socket.
address::String
Destination address or host.
port::Number
Destination port.
IOException
Exception object holds details.
void fchmod(mode::Number); (Methods)
Set file permissions mode.
mode::Number
ORed octal mode to set (FD.*, see fchmod(2)).
IOException
Object holds details.
SecurityException
Mode not permitted by application access.
void fchown(user::String|Number, group::String|Number); (Methods)
Set file owner and/or group.
user::String|Number
User name String or UID Number (-1 to not change).
group::String|Number
Group name String or GID Number (-1 to not change).
IOException
Object holds details.
Number fcntl(command::Number, flags::Number); (Methods)
File descriptor control. We only support commands FD.F_GETFL and FD.F_SETFL, with flags FD.O_NONBLOCK and FD.O_APPEND. See fcntl(2).
Number
State of the previous flags (supported only).
command::Number
Command (FD.F_GETFL or FD.F_SETFL).
flags::Number
ORed flags (FD.O_NONBLOCK, FD.O_APPEND).
void fdatasync(void); (Methods)
Synchronize the data of a file. Useful when necessary to ensure that the written data really is on disk.
IOException
Object holds details
void flock(op::Number); (Methods)
Apply or remove an advisory lock on an open file. See flock(2) for more information.
op::Number
Operation to perform (FD.LOCK_*).
IOException
Object holds details.
Stat fstat(void); (Methods)
Query status of open file.
Stat
The returned object holds properties about the file. See fstat(2) for more information.
IOException
Object holds details.
void ftruncate(size::Number); (Methods)
Truncates file to specified size.
size::Number
Size to truncate file to.
IOException
Error truncating file.
null|String get(void); (Methods)
Reads data from the socket if any and returns it. The internal buffer size is at most 4KB.
null|String
null on EOF or a String with the read data.
IOException
Exception object holds details.
Number getsockopt(name::Number); (Methods)
Gets current socket options. Unlike BSD/POSIX getsockopt(2), always returns a single integer value (-1 in case of SO_LINGER disabled, or the number of seconds assined to wait if enabled).
Number
Current option value.
name::Number
Option to retreive the value of (FD.SO_*).
void listen(concurrency::Number); (Methods)
Listens to the already bound FD.SOCK_STREAM socket.
concurrency::Number
Number of connections to queue.
IOException
Object has details.
Number lseek(offset::Number, whence::Number); (Methods)
Reposition read/write file offset.
Number
New file offset relative to beginning of file
offset::Number
Offset to seek to.
whence::Number
How to seek (FD.SEEK_SET, FD.SEEK_CUR, FD.SEEK_END), see lseek(2) for more information.
IOException
Object holds details.
void open(path::String, flags::Number, mode::Number); (Methods)
Opens a file with specified flags and mode like open(2).
path::String
Path to file to open.
flags::Number
Flags as for open(2) (FD.O_*).
mode::Number
Permission mode as for open(2).
IOException
Details in exception object.
SecurityException
Path not allowed.
void open(path::String, flags::Number); (Methods)
Opens a file with specified flags and a default mode.
path::String
Path to file to open.
flags::Number
Flags as for open(2) (FD.O_*).
IOException
Details in exception object.
SecurityException
Path not allowed.
Number put(data::*); (Methods)
Writes a string to the descriptor. Converts the value to a String as necessary.
Number
Number of bytes written.
data::*
Value to write.
IOException
Details in exception object.
String|null read(size::Number); (Methods)
Reads data from the descriptor in a binary-safe way, up to the maximum number of specified bytes.
String|null
Data that could be read, or null on EOF.
size::Number
Maximum read buffer size to use.
IOException
Object holds details.
void set(descriptor::Number); (Methods)
Associates FD object to an existing internal C file descriptor.
descriptor::Number
File descriptor to wrap FD around.
IOException
Details in exception object.
void setsockopt(name::Number, value::Number); (Methods)
Sets socket options. Unlike BSD/POSIX setsockopt(2), always requires a single integer value (-1 in the case of FD.SO_LINGER to disable it, or the number of seconds to linger to enable it).
name::Number
Option to change (FD.SO_*).
value::Number
Value to change option to.
Number shutdown(how::Number); (Methods)
Shut down part of a full-duplex connection. The socket must already be connected.
Number
0 on success or errno code on error (Error.*).
how::Number
What to shut down (FD.*), see shutdown(2).
void socket(domain::Integer, type::Integer, protocol::Integer); (Methods)
Sets up the FD object as an IPv4 socket. Currently, only FD.AF_INET, FD.SOCK_DGRAM and FD.SOCK_STREAM are supported. Like C socket(2).
domain::Integer
FD.AF_INET only for now.
type::Integer
Type of socket (FD.SOCK_DGRAM or FD.SOCK_STREAM only for now).
protocol::Integer
Usually 0.
IOException
Exception object holds details.
Number write(data::String); (Methods)
Writes the contents of the supplied String to the descriptor. Binary safe.
Number
Number of bytes which could be written.
data::String
Data to write to the descriptor.
IOException
Object holds details.
This class wraps around various file system related unix system calls.
Constructors | Static Properties | Static Methods | Properties | Methods
chdir | chmod | chown | creat | getcwd | lchown | mkdir | mkfifo | mknod | rename | rmdir | stat | symlink | truncate | unlink
void chdir(path::String); (Static Methods)
Change current directory.
path::String
Path to directory to change to.
IOException
Object holds details.
SecurityException
Application forbidden access to path.
void chmod(path::String, mode::Number); (Static Methods)
Change permission mode of a file.
path::String
Path to file to affect.
mode::Number
Permission mode to set.
IOException
Object holds details.
SecurityException
Application forbidden to access path.
void chown(path::String, owner::String|Number, group::String|Number); (Static Methods)
Change owner and/or group of a file. Follow symbolic links.
path::String
Path to file to work on.
owner::String|Number
User name or numeric uid of owner to set, or -1 to leave unchanged.
group::String|Number
Group name or numeric gid of group to set, or -1 to leave unchanged.
IOException
Object holds details.
SecurityException
Application not allowed access to path or to use symbolic-link following functions.
void creat(path::String, mode::Number); Deprecated (Static Methods)
Create a new file.
path::String
Path to new file to be created.
mode::Number
Permissions mode to set for new file.
IOException
Object holds details.
SecurityException
Application forbidden access.
String getcwd(void); (Static Methods)
Get current directory.
String
Path of current working directory.
void lchown(path::String, owner::String|Number, group::String|Number); (Static Methods)
Change owner and/or group of a file. Does not follow symbolic links.
path::String
Path to file to work on.
owner::String|Number
User name or numeric uid of owner to set, or -1 to leave unchanged.
group::String|Number
Group name or numeric gid of group to set, or -1 to leave unchanged.
IOException
Object holds details.
SecurityException
Application not allowed access to path.
void mkdir(path::String, mode::Number); (Static Methods)
Create a new directory.
path::String
Path to directory to create.
mode::Number
Permission mode for new directory.
IOException
Object holds details.
SecurityException
Application not allowed access to path.
void mkfifo(path::String, mode::Number); (Static Methods)
Create a FIFO special file.
path::String
Path to new file.
mode::Number
Permissions mode for new file.
IOException
Object holds details.
SecurityException
Application forbidden operation.
void mknod(path::String, mode::Number, dev::Number); (Static Methods)
Create a new special file.
path::String
Path to new file.
mode::Number
Permissions mode to set for new file.
dev::Number
Device information.
IOException
Object holds details.
SecurityException
Application forbidden operation.
void rename(path1::String, path2::String); (Static Methods)
Rename a file or directory (path1 to path2).
path1::String
Path to file to rename.
path2::String
Path to new name.
IOException
Object holds details.
SecurityException
Application forbidden access.
void rmdir(path::String); (Static Methods)
Delete an empty directory.
path::String
Path to directory to be deleted.
IOException
Object holds details.
SecurityException
Application forbidden access to path.
Stat stat(path::String); (Static Methods)
Obtain information on file. Follows symbolic links.
Stat
Object holding information about the file.
path::String
Path to file to get information about.
IOException
Object holds details.
SecurityException
Application forbidden access to path, or application is now allowed to use functions which follow symbolic links.
Stat stat(path::String); (Static Methods)
Obtain information on file. Does not follow symbolic links, information about the link is returned instead.
Stat
Object holding information about the file.
path::String
Path to file to get information about.
IOException
Object holds details.
SecurityException
Application forbidden access to path.
void symlink(path1::String, path2::String); (Static Methods)
Create a symbolic link (path2 to path1).
path1::String
Destination path name.
path2::String
Link path name.
IOException
Object holds details.
SecurityException
Application forbidden operation.
void truncate(path::String, size::Number); (Static Methods)
Sets size of a file.
path::String
Path to file to affect.
size::Number
New size to set for file.
IOException
Object holds details.
SecurityException
Application forbidden access.
void unlink(path::String); (Static Methods)
Delete a file.
path::String
Path to file to delete.
IOException
Object holds details.
SecurityException
Application forbidden access.
This class consists of a wrapper around C stdio. When it is initialized by the system, three File objects are also created as first-level objects: stdin, stdout and stderr.
Because various C libraries also work with C FILE objects, it was important to implement support for stdio. For instance, the GD and PG classes support it.
Constructors | Static Properties | Static Methods | Properties | Methods
void File(path::String, mode::String); (Constructors)
Opens the specified file in the specified mode.
path::String
Path to file that is to be opened.
mode::String
mode is identical to C stdio fopen(3) modes, namely: r, r+, w+, a and a+.
IOException
Object holds details.
SecurityException
Forbidden path.
void File(descriptor::Number, mode::String); (Constructors)
Instead of opening a file, bind the File object to a unix file descriptor.
descriptor::Number
The file descriptor may be one of File.STDIN_FILENO, File.STDOUT_FILENO, File.STDERR_FILENO or any other open descriptor from an FD object obtained via its FD.fd property.
mode::String
Same as for the other constructor.
IOException
Object holds details.
SEEK_CUR | SEEK_END | SEEK_SET | STDERR_FILENO | STDIN_FILENO | STDOUT_FILENO | _IOFBF | _IOLBF | _IONBF
SEEK_CUR::Number (ro) (Static Properties)
Seek at offset from the current position.
SEEK_END::Number (ro) (Static Properties)
Seek from the end of file.
SEEK_SET::Number (ro) (Static Properties)
Seek at absolute position from beginning of file.
STDERR_FILENO::Number (ro) (Static Properties)
Unix descriptor 2.
STDIN_FILENO::Number (ro) (Static Properties)
Unix descriptor 0.
STDOUT_FILENO::Number (ro) (Static Properties)
Unix descriptor 1.
_IOFBF::Number (ro) (Static Properties)
Fully buffered.
_IOLBF::Number (ro) (Static Properties)
Line buffered.
_IONBF::Number (ro) (Static Properties)
Unbuffered.
popen | remove | strerror | tmpfile
FD popen(command::String, mode::String); (Static Methods)
Allows to execute a wanted command and to read and/or write to its standard input and output file handles. Returns a new FD object to this effect.
FD
New FD object to interract with the command.
command::String
Command to execute.
mode::String
Mode to open the file handle in. Same modes as stdio or File.constructors.FD.
IOException
Object holds details.
SecurityException
Application not allowed to execute external commands.
void remove(path::String); (Static Methods)
Deletes the specified file.
path::String
Path to the file to delete.
IOException
Object holds details.
SecurityException
Application forbidden to access path in write mode.
String strerror(errno::Number); (Static Methods)
Translate error number to readable form.
String
Translation of supplied error code to string.
errno::Number
Error number to translate.
String strerror(void); (Static Methods)
Translate error number to readable form.
String
Translation of system C/unix errno to string.
FD tmpfile(void); (Static Methods)
Creates a temporary file and returns a new FD object which can be used to write and read from it, in mode w+. When this descriptor is closed the file is automatically deleted.
FD
New FD object to interact with the new temporary file.
IOException
Object holds details.
clearerr | close | eof | error | fileno | flush | getc | gets | purge | putc | read | reopen | rewind | seek | setvbuf | tell | ungetc | write
void clearerr(void); (Methods)
Clears any pending error condition from File handle.
IOException
Details in object.
Number close(void); (Methods)
Closes the file. This file object becomes invalid.
Number
0 on success or an errno error code.
Boolean eof(void); (Methods)
Returns End Of File status of the File handle.
Boolean
true if EOF was reached; false otherwise.
IOExc