99网
您的当前位置:首页Native Client - Application - The nacl_io Library

Native Client - Application - The nacl_io Library

来源:99网

nacl_io is a utility library that provides implementations of standard C APIs such as POSIX I/O (stdio.h) and BSD sockets (sys/socket.h). Its primary function is to allow code that uses these standard APIs to be compiled and used in a Native Client module. The library is included as part of Native Client SDK and is implemented in on top of Pepper API.

Since Native Client modules cannot access the host machine’s file system directly, nacl_io provides several alternative filesystem types which can be used by the application. For example, the Chrome browser supports the  which provides access to a protected area of the local file system. This filesystem can be accessed by an HTML page using JavaScript commands, and also by a Native Client module using the Pepper .

With nacl_io a Native Client application can mount an HTML5 filesystem and access it via standard POSIX I/O function such as fopenfseekfreadfwrite, and fclose, or their low level UNIX counterparts openlseek,readwrite and close. As well as the HTML5 file system, nacl_io provides several other file system types which are described in the table below:

File System Description
memfsAn in-memory file system
html5fsAn HTML5 local file system, which can be persistent or temporary
httpMaps files on a remote webserver into the local filesystem.
devA file system containing special files (e.g.: /dev/null)

Using nacl_io is mostly just a matter of using the standard POSIX C library functions. However, there are some steps required to initialize the library and setup the filesystem mounts. In general the following steps will be needed to use nacl_io in a NaCl application:

Unlike most input/output for nacl_io, internal logging writes directly to the stderr stream of the NaCl process. It deliberately bypasses the standard library functions implemented in nacl_io to avoid circular calls to itself.

The demo application launches a Native Client module that mounts three file systems and displays a set of controls that let you work with them:

因篇幅问题不能全部显示,请点此查看更多更全内容