@@ -5,6 +5,7 @@ import * as stream from "stream";
55import { TextEncoder } from "text-encoding" ;
66import { NewSessionMessage , ServerMessage , SessionDoneMessage , SessionOutputMessage , ShutdownSessionMessage , IdentifySessionMessage , ClientMessage , NewConnectionMessage , ConnectionEstablishedMessage , NewConnectionFailureMessage , ConnectionCloseMessage , ConnectionOutputMessage } from "../proto" ;
77import { SendableConnection } from "../common/connection" ;
8+ import { ServerOptions } from "./server" ;
89
910export interface Process {
1011 stdin ?: stream . Writable ;
@@ -22,7 +23,7 @@ export interface Process {
2223 title ?: number ;
2324}
2425
25- export const handleNewSession = ( connection : SendableConnection , newSession : NewSessionMessage , onExit : ( ) => void ) : Process => {
26+ export const handleNewSession = ( connection : SendableConnection , newSession : NewSessionMessage , serverOptions : ServerOptions | undefined , onExit : ( ) => void ) : Process => {
2627 let process : Process ;
2728
2829 const env = { } as any ;
@@ -44,7 +45,15 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
4445 } ;
4546 let proc : cp . ChildProcess ;
4647 if ( newSession . getIsFork ( ) ) {
47- proc = cp . fork ( newSession . getCommand ( ) , newSession . getArgsList ( ) ) ;
48+ if ( ! serverOptions ) {
49+ throw new Error ( "No forkProvider set for bootstrap-fork request" ) ;
50+ }
51+
52+ if ( ! serverOptions . forkProvider ) {
53+ throw new Error ( "No forkProvider set for server options" ) ;
54+ }
55+
56+ proc = serverOptions . forkProvider ( newSession ) ;
4857 } else {
4958 proc = cp . spawn ( newSession . getCommand ( ) , newSession . getArgsList ( ) , options ) ;
5059 }
@@ -107,7 +116,7 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
107116
108117export const handleNewConnection = ( connection : SendableConnection , newConnection : NewConnectionMessage , onExit : ( ) => void ) : net . Socket => {
109118 const id = newConnection . getId ( ) ;
110- let socket : net . Socket ;
119+ let socket : net . Socket ;
111120 let didConnect = false ;
112121 const connectCallback = ( ) => {
113122 didConnect = true ;
@@ -134,7 +143,7 @@ export const handleNewConnection = (connection: SendableConnection, newConnectio
134143 const servMsg = new ServerMessage ( ) ;
135144 servMsg . setConnectionFailure ( errMsg ) ;
136145 connection . send ( servMsg . serializeBinary ( ) ) ;
137-
146+
138147 onExit ( ) ;
139148 }
140149 } ) ;
0 commit comments