Skip to content

Commit

Permalink
feat(daemon): Add TCP connect to Node powers
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored and kumavis committed Feb 13, 2024
1 parent d0a9168 commit 82c45af
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ export const makeSocketPowers = ({ net }) => {
cancelled,
);

const connectPort = ({ port, host, cancelled }) =>
new Promise((resolve, reject) => {
const conn = net.connect(port, host, err => {
if (err) {
reject(err);
return;
}
const reader = makeNodeReader(conn);
const writer = makeNodeWriter(conn);
const closed = new Promise(close => conn.on('close', close));
resolve({
reader,
writer,
closed,
});
});
});

/**
* @param {object} args
* @param {string} args.path
Expand All @@ -263,7 +281,7 @@ export const makeSocketPowers = ({ net }) => {
return connections;
};

return { servePort, servePath };
return { servePort, servePath, connectPort };
};

/**
Expand All @@ -275,7 +293,7 @@ export const makeSocketPowers = ({ net }) => {
*/
export const makeNetworkPowers = ({ http, ws, net }) => {
const { servePortHttp } = makeHttpPowers({ http, ws });
const { servePort, servePath } = makeSocketPowers({ net });
const { servePort, servePath, connectPort } = makeSocketPowers({ net });

const connectionNumbers = (function* generateNumbers() {
let n = 0;
Expand Down Expand Up @@ -338,6 +356,7 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
servePortHttp,
servePort,
servePath,
connectPort,
makePrivatePathService,
makePrivateHttpService,
});
Expand Down

0 comments on commit 82c45af

Please sign in to comment.