But is superfast with the below codesub httpserv { my $socket = shift; my $buf; while(defined($buf = <$socket>)) { # nothing } print $socket "HTTP/1.0 200 OK\n"; print $socket "Cache-Control: no-cache \n"; print $socket "Server: Apache/2.2.23(Fedora)\n"; print $socket "Connection: close \n"; print $socket "Content-Type: text/html; charset=UTF-8\n"; print $socket "\n\n"; # Without this browser doesn't show H +TML Content print $socket "<HTML><HEAD><TITLE>\n"; print $socket "Got your message</TITLE></HEAD>\n"; print $socket "<BODY>Got your message</BODY></HTML>\n"; $socket->close(); }
Observe the last; in the while loop.sub httpserv { my $socket = shift; my $buf; while(defined($buf = <$socket>)) { last; # Without this it is like removing a +utoflush(1), # Without the "last;" the client conn +ection hangs; } print $socket "HTTP/1.0 200 OK\n"; print $socket "Cache-Control: no-cache \n"; print $socket "Server: Apache/2.2.23(Fedora)\n"; print $socket "Connection: close \n"; print $socket "Content-Type: text/html; charset=UTF-8\n"; print $socket "\n\n"; # Without this browser doesn't show H +TML Content print $socket "<HTML><HEAD><TITLE>\n"; print $socket "Got your message</TITLE></HEAD>\n"; print $socket "<BODY>Got your message</BODY></HTML>\n"; $socket->close(); }
In reply to what's with last; by pengwn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |