9 $self->{'filebits'} = '';
10 $self->{'connections'} = { };
11 $self->{'server'} = '';
12 $self->{'server_fileno'} = '';
18 my $timeoutafter = shift; # in seconds
21 print STDERR
"fakeserver: Loop\n";
23 select( undef, undef, undef, 1 );
25 my ($n, $left) = select( $rout = $filebits, undef, undef, $timeoutafter); # Time out after 15 seconds
27 print STDERR
"fakeserver: Terminating normally\n";
31 my $routs = unpack("b*", $rout);
32 print STDERR
"fakeserver: Select $routs\n";
33 my $pos = index( $routs,'1');
35 $self->HandleFile( $pos );
36 $pos = index( $routs,'1', $pos+1);
43 vec($self->{'filebits'},$self->{'server_fileno'},1) = 0;
50 my $server = IO
::Socket
::INET
->new(Listen
=> 5,
57 die "Could not create socket $!" unless $server;
60 my $server_fileno = fileno($server);
61 vec($filebits,$server_fileno,1) = 1;
63 print STDERR
"fakeserver: Starting $server_fileno\n";
65 open (DATA
, 'closeconnection.dat') or die "couldn't open closeconnection.dat: $!\n";
66 my $n = read(DATA
, $closeconnectionmessage, 100);
69 print STDERR
"fakeserver: read $n <$closeconnectionmessage> ", length($closeconnectionmessage), "\n";
70 $self->{'server'} = $server;
71 $self->{'server_fileno'} = $server_fileno;
78 print STDERR
"fakeserver: SendMessage $message\n";
81 foreach my $fileno (keys %{$self->{'connections'}}) {
82 if ( ${$self->{'connections'}}{$fileno} ) {
83 my $client = ${$self->{'connections'}}{$fileno}{client
};
84 print $client $message;
93 print STDERR
"fakeserver: HandleFile $fileno\n";
94 if ( $fileno == $self->{'server_fileno'} ) {
96 } elsif ( ${$self->{'connections'}}{$fileno} ) {
97 HandleClient
( $fileno );
99 print STDERR
"fakeserver: Weird fileno $fileno\n";
105 my $client = $server->accept();
107 print STDERR
"fakeserver: HandleServer\n";
110 my $fileno = fileno($client);
111 $client->blocking(0);
112 ${$self->{'connections'}}{$fileno}{client
} = $client;
113 ${$self->{'connections'}}{$fileno}{loggedin
} = 0;
114 vec($self->{'filebits'},$fileno,1) = 1;
115 print STDERR
"fakeserver: New client on $fileno\n";
117 print STDERR
"fakeserver: No accept for server, reopen\n";
118 $self->CloseServer();
127 print STDERR
"fakeserver: HandleClient $fileno\n";
129 my $n = recv( ${$self->{'connections'}}{$fileno}{client
}, $receive, 200, 0 );
130 my $rlen = length($receive);
132 if ($receive =~ /^GIOP/) {
133 print STDERR
"fakeserver: Got $rlen byte GIOP message from client $fileno\n";
136 print STDERR
"fakeserver: Got $rlen bytes from client $fileno\n";
138 ${$self->{'connections'}}{$fileno}{receive
} = $receive;
139 my $slen = length($closeconnectionmessage);
140 print STDERR
"fakeserver: Sending $slen bytes GIOP closeconnection to $fileno\n";
142 $n = send(${$self->{'connections'}}{$fileno}{client
}, $closeconnectionmessage, 0);
143 print STDERR
"fakeserver: Sent $n bytes GIOP closeconnection to $fileno\n";
145 print STDERR
"fakeserver: Close client $fileno\n";
146 vec(${$self->{'filebits'}},$fileno,1) = 0;
147 ${$self->{'connections'}}{$fileno}{client
}->close();
148 undef ${$self->{'connections'}}{$fileno};
149 $self->SendMessage( "Close Client" );