Skip to content

Commit 40cf998

Browse files
committed
Fix wrong usage of SetNamedPipeHandleState and log possible errors when switching between PIPE_WAIT and PIPE_NO_WAIT. Indicate logged values are hex not decimal.
1 parent 44fe966 commit 40cf998

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/base/ctrl_socket.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,10 @@ static void xdebug_control_socket_handle(void)
334334
if (result == ERROR_PIPE_CONNECTED) {
335335
// 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_WARN, "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,15 +348,17 @@ 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);
352354
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_WARN, "CTRL-RECV", "Can't (post)set NP handle state to 0x%x: 0x%x", lpMode, GetLastError());
361+
}
358362
}
359363

360364
// All other errors and completed reading should close the socket
@@ -489,7 +493,7 @@ void xdebug_control_socket_setup(void)
489493

490494
if (XG_BASE(control_socket_h) == INVALID_HANDLE_VALUE) {
491495
errno = WSAGetLastError();
492-
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-SOCKET", "Can't create control Named Pipe (%x)", errno);
496+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-SOCKET", "Can't create control Named Pipe (0x%x)", errno);
493497
xdfree(XG_BASE(control_socket_path));
494498
XG_BASE(control_socket_path) = NULL;
495499
return;

0 commit comments

Comments
 (0)