Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Test::More tests => 4;
- use IO::Handle;
- use Test::Fork;
- pipe( GETPID, SENDPID );
- SENDPID->autoflush(1);
- $^F = fileno(SENDPID)
- if ( $^F < fileno(SENDPID) );
- push my @cpid, fork_ok(
- 1,
- sub {
- close(GETPID);
- $^F = fileno(SENDPID)
- if ( $^F < fileno(SENDPID) );
- my $r =
- system( 'lsof -np $$; echo $$ >&'
- . fileno(SENDPID)
- . '; exec src/ihlt >&2' );
- ok( $r == 2, 'ihlt: quit' );
- }
- );
- close(SENDPID);
- if ( !$cpid[-1] ) {
- warn 'music died.';
- exit(2);
- }
- use IO::Socket::INET;
- # create a connecting socket
- my @sockets;
- for ( 0 .. 2 ) {
- push @sockets,
- new IO::Socket::INET(
- PeerHost => '127.0.0.1',
- PeerPort => '2020',
- Proto => 'tcp',
- );
- unless ($socket) {
- kill 'SIGINT', <GETPID>;
- fail "cannot connect to the server $!\n";
- die;
- }
- pass("$_: connected to the server\n");
- }
- my $response = "";
- # data to send to a server
- $sockets[0]->autoflush(1);
- ok( $sockets[0]->send("Hello world!\n") == 13, 'first msg sent' );
- ok( $sockets[1]->recv( $response, 1024 ) == 13, 'first msg recv' );
- ok( $sockets[2]->recv( $response, 1024 ) == 13, 'first msg recv again' );
- $sockets[2]->autoflush(1);
- ok( $sockets[2]->send("Hello world!\n") == 13, 'first msg sent' );
- ok( $sockets[1]->recv( $response, 1024 ) == 13, 'first msg recv' );
- ok( $sockets[0]->recv( $response, 1024 ) == 13, 'first msg recv again' );
- $sockets[$_]->close() for ( 0 .. 2 );
- kill 'SIGINT', <GETPID>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement