项目作者: NoHomey

项目描述 :
Opens device file in non-blocking ioctl mode only
高级语言: TypeScript
项目地址: git://github.com/NoHomey/open-ioctl.git
创建时间: 2016-07-09T07:46:09Z
项目社区:https://github.com/NoHomey/open-ioctl

开源协议:MIT License

下载


open-ioctl

Opens device file in non-blocking ioctl mode only

npm version
license
Build Status
Code Climate
Test Coverage
Issue Count
TypeScript
Typings

Installation

Install with npm:

  1. $ npm install open-ioctl

Description

Opening ioctl only device drivers made easy.

Opens device file in non-blocking ioctl mode. File is opend with flags 3 | O_NONBLOCK.

Flag 3 means that only ioctl calls can be made for comunication with the device driver (remember read/write operations are expensive this is why open-ioctl was made in first place to make it easer for performance and command oriented device drivers).

Flag O_NONBLOCK means that ioctl calls will not put process and thread from which they came to sleep.

Warning

O_NONBLOCK

O_NONBLOCK: flag is different compared to O_ASYNC (which is recomended to use only in rear an special cases, also you have no access to it in node).
O_NONBLOCK means that all syscalls respectivly ioctl calls will not put the process and thread from which they were made to sleep while the result is awaited. This is perfect for in node process call so no even loop block will occure.

O_ASYNC can’t be used on regular device files only terminals, sockets and pipes also it’s not exported in fs.constants from the ‘fs’ module with a reason! For more information see: Posix open(2), open(3).

Usage

openIoctl(path, callback)

  • path \
  • callback \

path is based on /dev

The callback gets two arguments (err, fd).

  • err \
  • fd \
  1. const { openIoctl } = require('open-ioctl');
  2. const { close } = require('fs');
  3. openIoctl('test_dev', function(err, fd) { // /dev/test_dev
  4. if(err) {
  5. console.log(err);
  6. } else {
  7. console.log(fd);
  8. /* ioctl calls */
  9. close(fd, function(err) {
  10. if(err) {
  11. console.log(err);
  12. }
  13. });
  14. }
  15. });

openIoctlSync(path)

  • path \

Synchronous version of openIoctl(). Returns an integer representing the file descriptor \.

  1. const { openIoctlSync } = require('open-ioctl');
  2. const { closeSync } = require('fs');
  3. var fd = openIoctlSync('test/test_dev'); // /dev/test/test_dev
  4. console.log(fd);
  5. /* ioctl calls */
  6. closeSync(fd);

open device file located outside of /dev

  1. const { openIoctlSync } = require('open-ioctl');
  2. const { closeSync } = require('fs');
  3. var fd = openIoctlSync('../proc/some_dev'); // /proc/some_dev
  4. console.log(fd);
  5. /* ioctl calls */
  6. closeSync(fd);

For full working example code visit: (https://github.com/NoHomey/nodejs-ioctl-example)

Written in TypeScript and TypeScript Ready!