MCPcopy
hub / github.com/claude-code-best/claude-code / connectUds

Method connectUds

src/utils/pipeTransport.ts:413–461  ·  view source on GitHub ↗
(timeoutMs: number)

Source from the content-addressed store, hash-verified

411 }
412
413 private async connectUds(timeoutMs: number): Promise<void> {
414 const { access } = await import('fs/promises')
415 const deadline = Date.now() + timeoutMs
416 const retryDelayMs = 300
417
418 // Wait for socket file to exist (Unix only)
419 if (process.platform !== 'win32') {
420 while (Date.now() < deadline) {
421 try {
422 await access(this.socketPath)
423 break
424 } catch {
425 if (Date.now() + retryDelayMs >= deadline) {
426 throw new Error(
427 `Pipe "${this.targetName}" not found at ${this.socketPath}. Is the server running?`,
428 )
429 }
430 await new Promise(r => setTimeout(r, retryDelayMs))
431 }
432 }
433 }
434
435 return new Promise((resolve, reject) => {
436 const timer = setTimeout(
437 () => {
438 reject(
439 new Error(
440 `Connection to pipe "${this.targetName}" timed out after ${timeoutMs}ms`,
441 ),
442 )
443 },
444 Math.max(deadline - Date.now(), 1000),
445 )
446
447 const socket = createConnection({ path: this.socketPath }, () => {
448 clearTimeout(timer)
449 this.socket = socket
450 this.setupSocketListeners(socket)
451 this.emit('connected')
452 resolve()
453 })
454
455 socket.on('error', err => {
456 clearTimeout(timer)
457 socket.destroy()
458 reject(err)
459 })
460 })
461 }
462
463 private setupSocketListeners(socket: Socket): void {
464 attachNdjsonFramer<PipeMessage>(socket, msg => {

Callers 1

connectMethod · 0.95

Calls 7

setupSocketListenersMethod · 0.95
nowMethod · 0.80
maxMethod · 0.80
resolveFunction · 0.70
onMethod · 0.65
emitMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected