From 537a2a9cd6e68e9d0aef785759b6d3917fa340a3 Mon Sep 17 00:00:00 2001 From: saul Date: Fri, 12 Apr 2024 14:20:13 +1200 Subject: [PATCH] Use named pipes on windows. --- packages/rpc/src/rpc-client.ts | 6 ++++++ packages/rpc/src/rpc-server.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/rpc/src/rpc-client.ts b/packages/rpc/src/rpc-client.ts index 6e2e06b9..14b5c479 100644 --- a/packages/rpc/src/rpc-client.ts +++ b/packages/rpc/src/rpc-client.ts @@ -1,4 +1,6 @@ import * as net from 'net' +import { platform } from 'os' +import Path from 'path' import * as cborg from 'cborg' import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' @@ -17,6 +19,10 @@ export class RPCClient { private readonly stream = pushable({ objectMode: true }) constructor (path: string) { + if (platform() === 'win32') { + path = Path.join('\\\\.\\pipe', path) + } + this.socket = net.connect({ path }) this.rpc = new JSONRPCClient((request: JSONRPCRequest, options) => { diff --git a/packages/rpc/src/rpc-server.ts b/packages/rpc/src/rpc-server.ts index 49c4b633..d7f10483 100644 --- a/packages/rpc/src/rpc-server.ts +++ b/packages/rpc/src/rpc-server.ts @@ -1,4 +1,6 @@ import * as net from 'net' +import { platform } from 'os' +import Path from 'path' import * as cborg from 'cborg' import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' @@ -32,6 +34,10 @@ export class RPCServer { private readonly options: Required constructor (path: string, options: RPCServerOptions = {}) { + if (platform() === 'win32') { + path = Path.join('\\\\.\\pipe', path) + } + this.path = path this.options = {