# Global variables (added $total_chars and $start_time) my $time_zone_inc=10; my $total_chars = 0; my $start_time; my %sock_client_hash; my $cc=48; # Subroutines (added start_timer() and stop_timer()) sub start_timer() { $start_time = time; $total_chars = 0; } sub stop_timer() { my $stop_time = time; my $nsecs = $stop_time - $start_time; my $cps = sprintf "%.4f", $total_chars / $nsecs; log_event("$total_chars chars / $nsecs seconds = $cps chars / sec\n"); } # Added call to start_timer() sub new_socket { my $newclientsock=shift; $newclientsock = $server_sock ->accept; $sel->add($newclientsock); my ($ip,$peer_port)=sock_attrs($newclientsock); $sock_client_hash{$newclientsock->fileno}{ip}=$ip; $sock_client_hash{$newclientsock->fileno}{port}=$peer_port; my $fileNo=$newclientsock->fileno; log_event("New Client connected -> FileNo($fileNo) $ip:$peer_port\n"); start_timer(); } # Added increment of $total_chars sub gen_chars { my($wrs) = $_[0]; if($cc==58) { $cc=65; }elsif($cc==91) { $cc=97; }elsif($cc==123) { $cc=48; } $wrs->send(chr($cc)) or close_socket($wrs); $cc++; ++$total_chars; } # Added call to stop_timer() sub close_socket { my $socket=$_[0]; my $sock_ip=$sock_client_hash{$socket->fileno}{ip}; my $sock_peer_port=$sock_client_hash{$socket->fileno}{port}; my $fileNo=$socket->fileno; log_event("Unable to write to -> FileNo($fileNo) $sock_ip:$sock_peer_port\n"); if(defined ($socket)) { $sel->remove($socket); $socket->close; log_event("Removed socket -> FileNo($fileNo) $sock_ip:$sock_peer_port\n"); stop_timer(); } }