mirror of
https://github.com/vale981/autossh
synced 2025-03-04 17:01:41 -05:00
adds ability to modify maxPollCount
This commit is contained in:
parent
074d6b4920
commit
e2de655e84
3 changed files with 59 additions and 6 deletions
57
README.md
57
README.md
|
@ -63,9 +63,22 @@ autossh({
|
|||
|
||||
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
|
||||
|
||||
|
@ -103,3 +116,43 @@ autossh({
|
|||
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`).
|
4
index.js
4
index.js
|
@ -42,7 +42,7 @@ var AutoSSH = function (_EventEmitter) {
|
|||
_this.localPort = conf.localPort || 'auto';
|
||||
|
||||
_this.pollCount = 0;
|
||||
_this.maxPollCount = 30;
|
||||
_this.maxPollCount = conf.maxPollCount || 30;
|
||||
_this.pollTimeout = 50;
|
||||
|
||||
setImmediate(function () {
|
||||
|
@ -109,7 +109,7 @@ var AutoSSH = function (_EventEmitter) {
|
|||
value: function pollConnection() {
|
||||
var _this3 = this;
|
||||
|
||||
if (this.pollCount >= this.maxPollCount) {
|
||||
if (this.maxPollCount && this.pollCount >= this.maxPollCount) {
|
||||
this.emit('error', 'Max poll count reached. Aborting...');
|
||||
return this.kill();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class AutoSSH extends EventEmitter {
|
|||
this.localPort = conf.localPort || 'auto';
|
||||
|
||||
this.pollCount = 0;
|
||||
this.maxPollCount = 30;
|
||||
this.maxPollCount = conf.maxPollCount || 30;
|
||||
this.pollTimeout = 50;
|
||||
|
||||
setImmediate(() => {
|
||||
|
@ -70,7 +70,7 @@ class AutoSSH extends EventEmitter {
|
|||
/* starts polling the port to see if connection established
|
||||
*/
|
||||
pollConnection() {
|
||||
if (this.pollCount >= this.maxPollCount) {
|
||||
if (this.maxPollCount && this.pollCount >= this.maxPollCount) {
|
||||
this.emit('error', 'Max poll count reached. Aborting...');
|
||||
return this.kill();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue