#!/usr/bin/perl
my
$port
;
POE::Component::Server::TCP->new
(
Alias
=>
'myserver'
,
Address
=>
'127.0.0.1'
,
Port
=> 0,
Started
=>
sub
{
$port
= (sockaddr_in(
$_
[HEAP]->{listener}->
getsockname
))[0];
},
ClientConnected
=>
sub
{
ok(1,
'SERVER: accepted'
);
},
ClientPreConnect
=>
sub
{
my
$args
= {
SSL_cert_file
=>
'mylib/ircd.crt'
,
SSL_key_file
=>
'mylib/ircd.key'
,
};
my
$socket
=
eval
{ Server_TLSify(
$_
[ARG0],
$args
,
sub
{
my
(
$socket
,
$status
,
$errval
) =
@_
;
pass(
"SERVER: Got callback hook"
);
is(
$status
, 0,
"SERVER: Status received from callback is ERR - $errval"
);
$poe_kernel
->post(
'myserver'
=>
'shutdown'
);
} ) };
ok(!$@,
"SERVER: Server_TLSify $@"
);
return
(
$socket
);
},
ClientDisconnected
=>
sub
{
ok(1,
'SERVER: client disconnected'
);
},
ClientInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
die
"Should have never got any input from the client!"
;
},
ClientError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
diag(
"Got SERVER $syscall error $errno: $error"
)
if
$ENV
{TEST_VERBOSE};
},
);
POE::Component::Client::TCP->new
(
Alias
=>
'myclient'
,
RemoteAddress
=>
'127.0.0.1'
,
RemotePort
=>
$port
,
Connected
=>
sub
{
ok(1,
'CLIENT: connected'
);
$_
[HEAP]->{server}->put(
'garbage in, garbage out'
);
},
ServerInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
$heap
->{server}->put(
'garbage in, garbage out'
);
},
ServerError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
diag(
"Got CLIENT $syscall error $errno: $error"
)
if
$ENV
{TEST_VERBOSE};
},
);
$poe_kernel
->run();
done_testing;