# 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(); } } #### === Linux === [root@localhost ~]% sock.pl 14:03:28 -> New Client connected -> FileNo(4) 127.0.0.1:44999 14:03:35 -> Unable to write to -> FileNo(4) 127.0.0.1:44999 14:03:35 -> Removed socket -> FileNo(4) 127.0.0.1:44999 14:03:35 -> 6614 chars / 7 seconds = 944.8571 chars / sec 14:03:45 -> Exit called [root@localhost ~]% [root@localhost ~]% sock.pl 14:03:46 -> New Client connected -> FileNo(4) 127.0.0.1:45000 14:04:06 -> Unable to write to -> FileNo(4) 127.0.0.1:45000 14:04:06 -> Removed socket -> FileNo(4) 127.0.0.1:45000 14:04:06 -> 17046 chars / 20 seconds = 852.3000 chars / sec 14:04:13 -> New Client connected -> FileNo(4) 127.0.0.1:45001 14:04:44 -> Unable to write to -> FileNo(4) 127.0.0.1:45001 14:04:44 -> Removed socket -> FileNo(4) 127.0.0.1:45001 14:04:44 -> 26861 chars / 31 seconds = 866.4839 chars / sec 14:04:59 -> Exit called === Windows === C:\Documents and Settings\liverpole\Desktop>sock 14:49:04 -> New Client connected -> FileNo(4) 192.168.2.2:1204 14:49:12 -> Unable to write to -> FileNo(4) 192.168.2.2:1204 14:49:12 -> Removed socket -> FileNo(4) 192.168.2.2:1204 14:49:12 -> 774 chars / 8 seconds = 96.7500 chars / sec 14:49:16 -> New Client connected -> FileNo(4) 192.168.2.2:1205 14:49:39 -> Unable to write to -> FileNo(4) 192.168.2.2:1205 14:49:39 -> Removed socket -> FileNo(4) 192.168.2.2:1205 14:49:39 -> 2374 chars / 23 seconds = 103.2174 chars / sec 14:49:52 -> New Client connected -> FileNo(4) 127.0.0.1:1209 14:50:12 -> Unable to write to -> FileNo(4) 127.0.0.1:1209 14:50:12 -> Removed socket -> FileNo(4) 127.0.0.1:1209 14:50:12 -> 2024 chars / 20 seconds = 101.2000 chars / sec 14:50:35 -> Exit called