Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > e42472c47bf2868f641c948b8d308473 > files > 18

perl-POE-Component-Server-Syslog-1.200.0-3.mga4.noarch.rpm

#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Component::Server::Syslog;
use Data::Dumper;

POE::Session->create(
	inline_states => {
		_start => sub {
			$_[KERNEL]->sig($_, 'sig') for qw(INT HUP TERM);

			$_[HEAP]->{syslog} = POE::Component::Server::Syslog->spawn(
				Type => 'tcp',
				BindPort => 4095,
				InputState => \&client_input,
				ErrorState => \&client_error,
			);
		},
		
		_stop => sub {},

		sig => sub {
			$_[KERNEL]->call($_[HEAP]->{syslog}, 'shutdown');
			return;
		},
	},
);

POE::Kernel->run();

######################################

sub client_input {
    my $msg = $_[ARG0];
    print Dumper $msg;
}

sub client_error {
    warn "BAD MESSAGE: $_[ARG0]";
}