dave hj~sub accept_messages { my $self = shift; unless ($self->{daemon}) { my ($localaddr, $localport) = split /:/, $self->{address}; $self->{daemon} = new HTTP::Daemon ( LocalAddr => $localaddr, LocalPort => $localport ); ref $self->{daemon} or $self->_debug("Could not create HTTP::Daemon +$! $@", 3); $self->{daemon}->timeout($self->{timeout}) if $self->{timeout}; $self->{daemon}->listen($self->{queue}) if $self->{queue}; # tried s +etting this to 15. no joy. } local $SIG{PIPE} = sub { $self->_debug('PIPE WHILE ACCEPTING MESSAGE'); }; CONNECTION: while (1) { my $conn = $self->{daemon}->accept; # blocks return undef unless $conn; my $req = $conn->get_request; unless ($req) { $self->_debug( 'Problem reading from connection: ' . $conn->reason ); next CONNECTION; } if ($req->method ne 'POST') { my $r = new HTTP::Response (405,'POST method only' ); $conn->send_response($r); $conn->close; next CONNECTION; } elsif (my $content = $req->content) { my $r = new HTTP::Response(200, 'OK'); $conn->send_response($r); $conn->close; return $content; } } } sub transport_message { my $self = shift; my $message_string = shift; my $peer = shift; my $headers = new HTTP::Headers; $headers->date(time); $headers->content_type('text/plain'); $headers->server('Net::Distributed'); my $request = new HTTP::Request ( 'POST', "http://" . $peer->address, $headers, $message_string ); unless ($self->{UserAgent}) { $self->{UserAgent} = new LWP::UserAgent; $self->{UserAgent}->agent ("Net::Distributed::Transport/$VERSION"); $self->{UserAgent}->from ($self->{email}); $self->{UserAgent}->parse_head(0); $self->{UserAgent}->timeout($self->{send_timeout}); } my $ua = $self->{UserAgent}; local $SIG{PIPE} = sub { $self->_debug('PIPE WHILE SENDING MESSAGE'); }; my $response = $ua->request($request); if ($response->is_success) { return 1; # of course, there may be problems further down the line } else { $self->_debug("Got " . $response->status_line . " from " . $peer->ad +dress, 0); return 0; } }
In reply to Re: (tye)Re: HTTP::Daemon and broken pipes
by dash2
in thread HTTP::Daemon and broken pipes
by dash2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |