Skip to content

Commit

Permalink
Changed: clean socket closing
Browse files Browse the repository at this point in the history
Signed-off-by: diva.exchange <[email protected]>
  • Loading branch information
diva-exchange committed Aug 9, 2023
1 parent 67a8cf6 commit 6ffd548
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
12 changes: 7 additions & 5 deletions lib/i2p-sam-datagram.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/i2p-sam-raw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions lib/i2p-sam-stream.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/i2p-sam-datagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ export class I2pSamDatagram extends I2pSamRaw {

static make(c: Configuration): Promise<I2pSamDatagram> {
return new Promise((resolve, reject): void => {
(async (r: I2pSamDatagram): Promise<void> => {
(async (d: I2pSamDatagram): Promise<void> => {
const t: NodeJS.Timer = setTimeout((): void => {
d.close();
reject(new Error('I2pSamDatagram timeout'));
}, r.timeout * 1000);
}, d.timeout * 1000);
try {
await r.open();
await r.initSession();
resolve(r);
await d.open();
await d.initSession();
resolve(d);
} catch (error) {
d.close();
reject(error);
} finally {
clearTimeout(t);
Expand Down
2 changes: 2 additions & 0 deletions src/i2p-sam-raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export class I2pSamRaw extends I2pSam {
return new Promise((resolve, reject): void => {
(async (r: I2pSamRaw): Promise<void> => {
const t: NodeJS.Timer = setTimeout((): void => {
r.close();
reject(new Error('I2pSamRaw timeout'));
}, r.timeout * 1000);
try {
await r.open();
await r.initSession();
resolve(r);
} catch (error) {
r.close();
reject(error);
} finally {
clearTimeout(t);
Expand Down
14 changes: 8 additions & 6 deletions src/i2p-sam-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ export class I2pSamStream extends I2pSam {

static make(c: Configuration): Promise<I2pSamStream> {
return new Promise((resolve, reject): void => {
(async (r: I2pSamStream): Promise<void> => {
(async (s: I2pSamStream): Promise<void> => {
const t: NodeJS.Timer = setTimeout((): void => {
s.close();
reject(new Error('Stream timeout'));
}, r.timeout * 1000);
}, s.timeout * 1000);
try {
await r.open();
await r.initSession('STREAM');
await r.connect();
resolve(r);
await s.open();
await s.initSession('STREAM');
await s.connect();
resolve(s);
} catch (error) {
s.close();
reject(error);
} finally {
clearTimeout(t);
Expand Down

0 comments on commit 6ffd548

Please sign in to comment.