adds ability to modify maxPollCount

This commit is contained in:
samueleaton 2016-04-28 13:39:14 -06:00
parent 074d6b4920
commit e2de655e84
3 changed files with 59 additions and 6 deletions

View file

@ -63,9 +63,22 @@ autossh({
If you want to dynamically/randomly generate a port number, provide a string `auto` for the `localPort`. If you want to dynamically/randomly generate a port number, provide a string `auto` for the `localPort`.
Port conflicts will automatically be avoided and the generated port will not be in use. The major benefit is that port conflicts will automatically be avoided--the generated port will not have been in use.
See `demo.js` for an example. The generated `localPort` can be accessed from the connection object as `localPort`.
``` javascript
const myAutossh = autossh({
host: '111.22.333.444',
username: 'root',
localPort: 64444,
remotePort: 5432
})
.on('connect', connection => {
console.log('connected: ', connection);
console.log('localPort: ', connection.localPort);
});
```
#### Killing the Autossh Process #### Killing the Autossh Process
@ -103,3 +116,43 @@ autossh({
connection.kill(); connection.kill();
}); });
``` ```
#### Adjusting/Disabling Max Poll Count
When first trying to establish the ssh tunnel, `autoshh` will poll the local port until the connection has been established. The default max poll count is `30`.
**Adjusting the max poll count**
Set the `maxPollCount` property in the object passed to `autossh`:
```javascript
const myAutossh = autossh({
host: '111.22.333.444',
username: 'root',
localPort: 'auto',
remotePort: 5432,
maxPollCount: 50
})
.on('connect', connection => {
console.log('connected: ', connection);
});
```
**Disabling the max poll count**
Set the `maxPollCount` property to `0` or `false` in the object passed to `autossh`:
```javascript
const myAutossh = autossh({
host: '111.22.333.444',
username: 'root',
localPort: 'auto',
remotePort: 5432,
maxPollCount: false
})
.on('connect', connection => {
console.log('connected: ', connection);
});
```
**Warning:** The max poll count is there to prevent `autossh` from infinitely polling the local port. Rather than disabling it, it may be wise to set it to a high number (e.g. `500`).

View file

@ -42,7 +42,7 @@ var AutoSSH = function (_EventEmitter) {
_this.localPort = conf.localPort || 'auto'; _this.localPort = conf.localPort || 'auto';
_this.pollCount = 0; _this.pollCount = 0;
_this.maxPollCount = 30; _this.maxPollCount = conf.maxPollCount || 30;
_this.pollTimeout = 50; _this.pollTimeout = 50;
setImmediate(function () { setImmediate(function () {
@ -109,7 +109,7 @@ var AutoSSH = function (_EventEmitter) {
value: function pollConnection() { value: function pollConnection() {
var _this3 = this; var _this3 = this;
if (this.pollCount >= this.maxPollCount) { if (this.maxPollCount && this.pollCount >= this.maxPollCount) {
this.emit('error', 'Max poll count reached. Aborting...'); this.emit('error', 'Max poll count reached. Aborting...');
return this.kill(); return this.kill();
} }

View file

@ -16,7 +16,7 @@ class AutoSSH extends EventEmitter {
this.localPort = conf.localPort || 'auto'; this.localPort = conf.localPort || 'auto';
this.pollCount = 0; this.pollCount = 0;
this.maxPollCount = 30; this.maxPollCount = conf.maxPollCount || 30;
this.pollTimeout = 50; this.pollTimeout = 50;
setImmediate(() => { setImmediate(() => {
@ -70,7 +70,7 @@ class AutoSSH extends EventEmitter {
/* starts polling the port to see if connection established /* starts polling the port to see if connection established
*/ */
pollConnection() { pollConnection() {
if (this.pollCount >= this.maxPollCount) { if (this.maxPollCount && this.pollCount >= this.maxPollCount) {
this.emit('error', 'Max poll count reached. Aborting...'); this.emit('error', 'Max poll count reached. Aborting...');
return this.kill(); return this.kill();
} }