It seems that when I run it w/ perl -d it ends up listening to the console instead of opening a network socket and listening there.
Does anyone out there know a sufficient incantation that will let me play with my code inside the debugger?
I've tried explicitly setting $server->port() and $server->host() to no avail.
I also just figured out how to use the debugger's RemotePort option get the debugging io to occur in another xterm (using nc -l) and the server's IO *still* is connected to the debugging window.
Thanks,
g.
---------------------------------------------------
So, here's an answer. There's something funny about how HTTP::Server::Simple hooks stdin and stdout up to the socket it creates. I'm still trying to figure out if the problem only happens on my FreeBSD-STABLE system, or if it's a more generall bug. In the mean time, the following patch makes things work for me:
--- /usr/local/lib/perl5/site_perl/5.8.8/HTTP/Server/Simple.pm Sat Nov 25 16:15:39 2006
+++ lib/HTTP/Server/Simple.pm Sat Feb 24 14:33:12 2007
@@ -262,8 +262,18 @@
$self->accept_hook if $self->can("accept_hook");
- *STDIN = $self->stdin_handle();
- *STDOUT = $self->stdout_handle();
+ # hooking stdio to the socket using dup2 lets everything work
+ # in the perl debugger.
+ # cons'ed together w/ hints on dup2 usage from the qpsmtpd.
+ # hartzell@alerce.com --- Sat Feb 24 14:23:12 PST 2007
+ # *STDIN = $self->stdin_handle();
+ # *STDOUT = $self->stdout_handle();
+ use POSIX;
+ POSIX::dup2(fileno($self->stdin_handle()), 0)
+ || die "unable to duplicate filehandle to STDIN - $!";
+ POSIX::dup2(fileno($self->stdout_handle()), 1)
+ || die "unable to duplicate filehandle to STDOUT - $!";
+
select STDOUT; # required for HTTP::Server::Simple::Recorder
# XXX TODO glasser: why?
$pkg->process_request;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |