@@ -309,20 +309,20 @@ static void xdebug_control_socket_handle(void)
309309 int bytes_read ;
310310
311311 if (XG_BASE (control_socket_h ) <= 0 ) {
312- // no NP
312+ /* No Named Pipe */
313313 return ;
314314 }
315315
316316 if (ConnectNamedPipe (XG_BASE (control_socket_h ), NULL )) {
317- // previous disconnect
317+ /* Previous disconnect */
318318 DisconnectNamedPipe (XG_BASE (control_socket_h ));
319319 return ;
320320 }
321321
322322 result = GetLastError ();
323323
324324 if (result == ERROR_PIPE_LISTENING ) {
325- // no clients
325+ /* No clients */
326326 return ;
327327 }
328328
@@ -332,10 +332,12 @@ static void xdebug_control_socket_handle(void)
332332 }
333333
334334 if (result == ERROR_PIPE_CONNECTED ) {
335- // got new client!
335+ /* Got new client */
336336 DWORD lpMode ;
337- lpMode = PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ;
338- SetNamedPipeHandleState (XG_BASE (control_socket_h ), & lpMode , NULL , NULL );
337+ lpMode = PIPE_TYPE_BYTE | PIPE_WAIT ;
338+ if (!SetNamedPipeHandleState (XG_BASE (control_socket_h ), & lpMode , NULL , NULL )) {
339+ xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_ERR , "CTRL-RECV" , "Can't set NP handle state to 0x%x: 0x%x" , lpMode , GetLastError ());
340+ }
339341
340342 memset (buffer , 0 , sizeof (buffer ));
341343 bytes_read = 0 ;
@@ -346,18 +348,20 @@ static void xdebug_control_socket_handle(void)
346348 & bytes_read ,
347349 NULL
348350 )) {
349- xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_WARN , "CTRL-RECV" , "Can't receive from NP: %x" , GetLastError ());
351+ xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_WARN , "CTRL-RECV" , "Can't receive from NP: 0x %x" , GetLastError ());
350352 } else {
351353 xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_INFO , "CTRL-RECV" , "Received: '%s'" , buffer );
352- handle_command (0 , buffer );
354+ handle_command (XG_BASE ( control_socket_h ) , buffer );
353355 FlushFileBuffers (XG_BASE (control_socket_h ));
354356 }
355357
356- lpMode = PIPE_TYPE_BYTE | PIPE_NOWAIT | PIPE_REJECT_REMOTE_CLIENTS ;
357- SetNamedPipeHandleState (XG_BASE (control_socket_h ), & lpMode , NULL , NULL );
358+ lpMode = PIPE_TYPE_BYTE | PIPE_NOWAIT ;
359+ if (!SetNamedPipeHandleState (XG_BASE (control_socket_h ), & lpMode , NULL , NULL )) {
360+ xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_ERR , "CTRL-RECV" , "Can't (post)set NP handle state to 0x%x: 0x%x" , lpMode , GetLastError ());
361+ }
358362 }
359363
360- // All other errors and completed reading should close the socket
364+ /* All other errors and completed reading should close the socket */
361365 DisconnectNamedPipe (XG_BASE (control_socket_h ));
362366}
363367#endif
@@ -471,13 +475,16 @@ void xdebug_control_socket_teardown(void)
471475#elif WIN32
472476void xdebug_control_socket_setup (void )
473477{
478+ char * name = NULL ;
479+
474480 XG_BASE (control_socket_last_trigger ) = xdebug_get_nanotime ();
475481
476- XG_BASE (control_socket_path ) = xdebug_sprintf ("\\\\.\\pipe\\xdebug-ctrl." ZEND_ULONG_FMT , xdebug_get_pid ());
482+ XG_BASE (control_socket_path ) = xdebug_sprintf ("xdebug-ctrl." ZEND_ULONG_FMT , xdebug_get_pid ());
483+ name = xdebug_sprintf ("\\\\.\\pipe\\%s" , XG_BASE (control_socket_path ));
477484
478485 /* Part 1 – create Named Pipe */
479486 XG_BASE (control_socket_h ) = CreateNamedPipeA (
480- XG_BASE ( control_socket_path ) ,
487+ name ,
481488 PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE ,
482489 PIPE_TYPE_BYTE | PIPE_NOWAIT | PIPE_REJECT_REMOTE_CLIENTS ,
483490 1 ,
@@ -489,13 +496,16 @@ void xdebug_control_socket_setup(void)
489496
490497 if (XG_BASE (control_socket_h ) == INVALID_HANDLE_VALUE ) {
491498 errno = WSAGetLastError ();
492- xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_WARN , "CTRL-SOCKET" , "Can't create control Named Pipe (%x)" , errno );
499+ xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_WARN , "CTRL-SOCKET" , "Can't create control Named Pipe (0x %x)" , errno );
493500 xdfree (XG_BASE (control_socket_path ));
494501 XG_BASE (control_socket_path ) = NULL ;
502+
503+ xdfree (name );
495504 return ;
496505 }
497506
498- xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_INFO , "CTRL-OK" , "Control socket set up successfully: '%s'" , XG_BASE (control_socket_path ));
507+ xdebug_log_ex (XLOG_CHAN_CONFIG , XLOG_INFO , "CTRL-OK" , "Control socket set up successfully: '%s'" , name );
508+ xdfree (name );
499509}
500510
501511void xdebug_control_socket_teardown (void )
0 commit comments