Skip to content

Commit 68776e3

Browse files
committed
work on remote mode
1 parent f80a09e commit 68776e3

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

phpdbg.c

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,26 @@ int phpdbg_open_socket(short port) /* {{{ */
589589
return fd;
590590
} /* }}} */
591591

592+
static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
593+
{
594+
if (streams[0]) {
595+
fclose(streams[0]);
596+
}
597+
598+
if ((*socket)[0]) {
599+
close((*socket)[0]);
600+
}
601+
602+
if (streams[1]) {
603+
fflush(streams[1]);
604+
fclose(streams[1]);
605+
}
606+
607+
if ((*socket)[1]) {
608+
close((*socket)[1]);
609+
}
610+
} /* }}} */
611+
592612
/* don't inline this, want to debug it easily, will inline when done */
593613

594614
int phpdbg_open_sockets(int port[2], int (*listen)[2], int (*socket)[2], FILE* streams[2]) /* {{{ */
@@ -609,6 +629,7 @@ int phpdbg_open_sockets(int port[2], int (*listen)[2], int (*socket)[2], FILE* s
609629
return FAILURE;
610630
}
611631

632+
phpdbg_close_sockets(socket, streams);
612633
{
613634
struct sockaddr_in address;
614635
socklen_t size = sizeof(address);
@@ -622,32 +643,15 @@ int phpdbg_open_sockets(int port[2], int (*listen)[2], int (*socket)[2], FILE* s
622643
(*listen)[1], (struct sockaddr *) &address, &size);
623644
}
624645

646+
dup2((*socket)[0], fileno(stdin));
647+
dup2((*socket)[1], fileno(stdout));
648+
625649
streams[0] = fdopen((*socket)[0], "r");
626650
streams[1] = fdopen((*socket)[1], "w");
627651

628652
return SUCCESS;
629653
} /* }}} */
630654

631-
static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
632-
{
633-
if ((*socket)[0]) {
634-
close((*socket)[0]);
635-
}
636-
637-
if (streams[0]) {
638-
fclose(streams[0]);
639-
}
640-
641-
if (streams[1]) {
642-
fflush(streams[1]);
643-
fclose(streams[1]);
644-
}
645-
646-
if ((*socket)[1]) {
647-
close((*socket)[1]);
648-
}
649-
} /* }}} */
650-
651655
int main(int argc, char **argv) /* {{{ */
652656
{
653657
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
@@ -879,19 +883,14 @@ int main(int argc, char **argv) /* {{{ */
879883
/* setup io here */
880884
if (streams[0] && streams[1]) {
881885
PHPDBG_G(flags) |= PHPDBG_IS_REMOTE;
882-
/* remote console */
883-
PHPDBG_G(io)[PHPDBG_STDIN] = streams[0];
884-
PHPDBG_G(io)[PHPDBG_STDOUT] = streams[1];
885-
PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
886886

887887
signal(SIGPIPE, SIG_IGN);
888-
} else {
889-
/* local console */
890-
PHPDBG_G(io)[PHPDBG_STDIN] = stdin;
891-
PHPDBG_G(io)[PHPDBG_STDOUT] = stdout;
892-
PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
893888
}
894-
889+
890+
PHPDBG_G(io)[PHPDBG_STDIN] = stdin;
891+
PHPDBG_G(io)[PHPDBG_STDOUT] = stdout;
892+
PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
893+
895894
if (exec) { /* set execution context */
896895
PHPDBG_G(exec) = phpdbg_resolve_path(
897896
exec TSRMLS_CC);
@@ -977,9 +976,6 @@ int main(int argc, char **argv) /* {{{ */
977976
/* remote client disconnected */
978977
if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
979978

980-
/* close old streams/sockets */
981-
phpdbg_close_sockets(&socket, streams);
982-
983979
/* renegociate connections */
984980
phpdbg_open_sockets(
985981
listen, &server, &socket, streams);

0 commit comments

Comments
 (0)