@@ -33,60 +33,18 @@ export class ControlSocket {
3333 async requestPause ( ctrlSocket : string ) : Promise < void > {
3434 let retval
3535 if ( process . platform === 'linux' ) {
36- retval = await this . executeLinux ( ctrlSocket , 'pause' )
36+ retval = await this . executeCtrlCmd ( `\0 ${ ctrlSocket } y` . padEnd ( 108 , 'x' ) , 'pause' )
3737 } else if ( process . platform === 'win32' ) {
38- retval = await this . executeWindows ( ctrlSocket , 'pause' )
38+ retval = await this . executeCtrlCmd ( ctrlSocket , 'pause' )
3939 } else {
4040 throw new Error ( 'Invalid platform for Xdebug control socket' )
4141 }
4242 retval
4343 return
4444 }
4545
46- private async executeLinux ( ctrlSocket : string , cmd : string ) : Promise < string > {
47- const abs = await import ( 'abstract-socket' )
46+ private async executeCtrlCmd ( ctrlSocket : string , cmd : string ) : Promise < string > {
4847 return new Promise < string > ( ( resolve , reject ) => {
49- // const cs = `\0xdebug-ctrl.${pid}y`.padEnd(108, 'x')
50- const cs = `\0${ ctrlSocket } `
51- try {
52- const s = abs . connect ( cs , ( ) => {
53- s . write ( `${ cmd } \0` )
54- } )
55- s . setTimeout ( 3000 )
56- s . on ( 'timeout' , ( ) => {
57- reject ( new Error ( 'Timed out while reading from Xdebug control socket' ) )
58- s . end ( )
59- } )
60- s . on ( 'data' , data => {
61- s . destroy ( )
62- resolve ( data . toString ( ) )
63- } )
64- s . on ( 'error' , error => {
65- reject (
66- new Error (
67- `Cannot connect to Xdebug control socket: ${ String (
68- error instanceof Error ? error . message : error
69- ) } `
70- )
71- )
72- } )
73- return
74- } catch ( error ) {
75- reject (
76- new Error (
77- `Cannot connect to Xdebug control socket: ${ String (
78- error instanceof Error ? error . message : error
79- ) } `
80- )
81- )
82- return
83- }
84- } )
85- }
86-
87- private async executeWindows ( ctrlSocket : string , cmd : string ) : Promise < string > {
88- return new Promise < string > ( ( resolve , reject ) => {
89- //const s = net.createConnection(`\\\\.\\pipe\\xdebug-ctrl.${pid}`, () => {
9048 const s = net . createConnection ( ctrlSocket , ( ) => {
9149 s . end ( `${ cmd } \0` )
9250 } )
@@ -100,7 +58,6 @@ export class ControlSocket {
10058 resolve ( data . toString ( ) )
10159 } )
10260 s . on ( 'error' , error => {
103- // sadly this happens all the time - even on normal server-side-close, but luckily the promise is already resolved
10461 reject (
10562 new Error (
10663 `Cannot connect to Xdebug control socket: ${ String (
@@ -109,6 +66,7 @@ export class ControlSocket {
10966 )
11067 )
11168 } )
69+ return
11270 } )
11371 }
11472}
0 commit comments