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}); # send_timeout normally 5 secs } my $ua = $self->{UserAgent}; 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->address, 0); return 0; } } #### 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}; # normally timeout is 20 } local $SIG{PIPE} = sub { warn 'PIPE WHILE READING'; undef $self->{daemon}; }; 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; } } }