Ifevent : Network interface event

更新时间:
2024-05-15
下载文档

Ifevent : Network interface event

This module provides network interface event listening service.

User can use the following code to import the Ifevent module.

var Ifevent = require('router/ifevent');

Support

The following shows Ifevent module APIs available for each permissions.

 User ModePrivilege Mode
Ifevent 
Ifevent.open 
ifevent.close 
ifevent.clear 

Ifevent Class

new Ifevent()

  • Returns: {Object} Returns ifevent object.

Create a network interface event listener.

Example

var ifevent = new Ifevent();

Ifevent.open()

  • Returns: {Object} Returns ifevent object.

Same as new Ifevent(), but returns undefined with no exception.

Ifevent Object

The ifevent object inherits from EventEmitter, and the on() method can be used to add processing callbacks for different events.

ifevent.close()

Close this ifevent and reclaiming file descriptors. Due to the addition of asynchronous events, you must call this function manually when this object is no longer used.

ifevent.on(event, fn)

  • event {Integer} Network interface event.
  • fn {Function} Network interface event callback.
    • ifname {String} Network interface.

Add response functions for different network interface events.

event contains the following types of events:

  • Common event:
eventDescription
Ifevent.IF_ADDNetwork interface was added
Ifevent.IF_REMOVENetwork interface was removed
Ifevent.IF_UPNetwork interface is enabled
Ifevent.IF_DOWNNetwork interface is disabled
Ifevent.IF_LINKUPNetwork interface is connected
Ifevent.IF_LINKDOWNNetwork interface is disconnected
Ifevent.IF_ADDRESSNetwork interface address changed
Ifevent.IF_CONFLICTNetwork interface address conflict
Ifevent.IF_AUTH_FAILNetwork interface authentication failed
  • Point-to-point network event:
eventDescription
Ifevent.IF_PPP_DEADConnection dead
Ifevent.IF_PPP_INITInitializing connection
Ifevent.IF_PPP_AUTHStart user authentication
Ifevent.IF_PPP_RUNConnection establishment
Ifevent.IF_PPP_DISCONNDisconnecting
Ifevent.IF_PPP_TIMEOUTConnection timeout

Example

var ifevent = Ifevent.open();
ifevent.on(Ifevent.IF_AUTH_FAIL, function(ifname) {
  console.log('Interface:', ifname, 'authentication failed!');
});
iosched.forever();

ifevent.on(ifname, fn)

  • ifname {String} Network interface.
  • fn {Function} Network interface event callback.
    • event {Integer} Network interface event.

Add response functions for one network interface's all events.

Example

var ifevent = Ifevent.open();
ifevent.on('en1', function(event) {
  // Network interface: en1 has a event.
});

ifevent.on('all', fn)

  • 'all' {String} All events.
  • fn {Function} Network interface event callback.
    • ifname {String} Network interface.
    • event {Integer} Network interface event.

Example

var ifevent = Ifevent.open();
ifevent.on('all', function(ifname, event) {
  // Network interface: ifname has a event.
});

ifevent.on('error', fn)

  • 'error' {String} An error occured.
  • fn {Function} Network interface event callback.
    • error {Error} error information.

If an error occured an error event is emitted with the error information. System will automatically call ifevent.close() later.

Example

var ifevent = Ifevent.open();
ifevent.on('error', function(error)) {
  // check error information
}

ifevent.clear()

Clear all unreceived event information.

Example

var ifevent = Ifevent.open();
ifevent.clear();
文档内容是否对您有所帮助?
有帮助
没帮助