12 print STDERR
"fakeserver: Loop\n";
14 select( undef, undef, undef, 1 );
16 ($n, $left) = select( $rout = $filebits, undef, undef, 15 ); # Time out after 15 seconds
18 print STDERR
"fakeserver: Terminating normally\n";
22 my $routs = unpack("b*", $rout);
23 print STDERR
"fakeserver: Select $routs\n";
24 my $pos = index( $routs,'1');
27 $pos = index( $routs,'1', $pos+1);
32 local( $message ) = @_;
34 print STDERR
"fakeserver: SendMessage $message\n";
37 foreach $fileno (keys %connections) {
38 if ( $connections{$fileno} ) {
39 my $client = $connections{$fileno}{client
};
40 print $client $message;
47 local( $fileno ) = @_;
49 print STDERR
"fakeserver: HandleFile $fileno\n";
50 if ( $fileno == $server_fileno ) {
52 } elsif ( $connections{$fileno} ) {
53 HandleClient
( $fileno );
55 print STDERR
"fakeserver: Weird fileno $fileno\n";
60 my $client = $server->accept();
62 print STDERR
"fakeserver: HandleServer\n";
65 my $fileno = fileno($client);
67 $connections{$fileno}{client
} = $client;
68 $connections{$fileno}{loggedin
} = 0;
69 vec($filebits,$fileno,1) = 1;
70 # print $client "Welcome $fileno\r\n";
71 # my $n = send($client, $closeconnectionmessage, 0);
72 print STDERR
"fakeserver: New client on $fileno\n";
73 # SendMessage( "New Client" );
75 print STDERR
"fakeserver: No accept for server, reopen\n";
82 local( $fileno ) = @_;
84 print STDERR
"fakeserver: HandleClient $fileno\n";
85 $n = recv( $connections{$fileno}{client
}, $receive, 200, 0 );
86 $rlen = length($receive);
88 if ($receive =~ /^GIOP/) {
89 print STDERR
"fakeserver: Got $rlen byte GIOP message from client $fileno\n";
92 print STDERR
"fakeserver: Got $rlen bytes from client $fileno\n";
94 $connections{$fileno}{receive
} = $receive;
95 $slen = length($closeconnectionmessage);
96 print STDERR
"fakeserver: Sending $slen bytes GIOP closeconnection to $fileno\n";
98 $n = send($connections{$fileno}{client
}, $closeconnectionmessage, 0);
99 print STDERR
"fakeserver: Sent $n bytes GIOP closeconnection to $fileno\n";
101 print STDERR
"fakeserver: Close client $fileno\n";
102 vec($filebits,$fileno,1) = 0;
103 $connections{$fileno}{client
}->close();
104 undef $connections{$fileno};
105 SendMessage
( "Close Client" );
111 vec($filebits,$server_fileno,1) = 0;
118 $server = IO
::Socket
::INET
->new(Listen
=> 5,
125 die "Could not create socket $!" unless $server;
127 $server->blocking(0);
128 $server_fileno = fileno($server);
129 vec($filebits,$server_fileno,1) = 1;
131 print STDERR
"fakeserver: Starting $server_fileno\n";
133 open (DATA
, 'closeconnection.dat') or die "couldn't open closeconnection.dat: $!\n";
134 my $n = read(DATA
, $closeconnectionmessage, 100);
137 print STDERR
"fakeserver: read $n <$closeconnectionmessage> ", length($closeconnectionmessage), "\n";