浏览 1821 次
锁定老帖子 主题:erlang如何打开设备文件?
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-03-05
{error,eisdir} Google了下,得到: "The efile driver expects the file to be regular in the sense that operations won't block (i.e. a "fast" device). If one could open e.g a tape drive and write to it, the whole erlang machine will block for several seconds/minutes/hours, which is not especially nice. If one wants to operate on special files, one have to either write a "port program" (which will spin in a separate process) or write a loadable driver, which uses threads or the io multiplexing mechanisms to avoid hanging the emulator." 难道操作设备文件这么麻烦 ?! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-03-05
sw2wolf 写道 > file:open("/dev/urandom", [read,raw]).
{error,eisdir} Google了下,得到: "The efile driver expects the file to be regular in the sense that operations won't block (i.e. a "fast" device). If one could open e.g a tape drive and write to it, the whole erlang machine will block for several seconds/minutes/hours, which is not especially nice. If one wants to operate on special files, one have to either write a "port program" (which will spin in a separate process) or write a loadable driver, which uses threads or the io multiplexing mechanisms to avoid hanging the emulator." 难道操作设备文件这么麻烦 ?! int efile_openfile(Efile_error* errInfo, /* Where to return error codes. */ char* name, /* Name of directory to open. */ int flags, /* Flags to user for opening. */ int* pfd, /* Where to store the file descriptor. */ Sint64 *pSize) /* Where to store the size of the file. */ { 。。。。 if (stat(name, &statbuf) >= 0 && !ISREG(statbuf)) { #if !defined(VXWORKS) && !defined(OSE) /* * For UNIX only, here is some ugly code to allow * /dev/null to be opened as a file. * * Assumption: The i-node number for /dev/null cannot be zero. */ static ino_t dev_null_ino = 0; if (dev_null_ino == 0) { struct stat nullstatbuf; if (stat("/dev/null", &nullstatbuf) >= 0) { dev_null_ino = nullstatbuf.st_ino; } }p den if (!(dev_null_ino && statbuf.st_ino == dev_null_ino)) { #endif errno = EISDIR; return check_error(-1, errInfo); #if !defined(VXWORKS) && !defined(OSE) } #endif } 。。。 } 也就是说如果打开的不是 regular文件 或者/dev/null, 那么文件打开失败! 设计的用意就是怕设备操作block了调度器,因为之前erlang支持smp之前 只有唯一的一个调度器 阻塞了系统就挂了! |
|
返回顶楼 | |