example: fix memory leak for simple_http_server

This commit is contained in:
Shuhei Tanuma 2012-08-11 14:43:29 +09:00
parent b77f34833f
commit 8623e5018c

View File

@ -1,4 +1,6 @@
<?php
require "debug_timer.php";
$address = "::1";
$port = 8888;
@ -32,12 +34,13 @@ uv_listen($server, 511, function($server_stream) use (&$parsers, &$clients){
uv_read_start($client, function($client, $nread, $buffer) use (&$parsers, &$clients){
if ($nread < 0) {
uv_shutdown($client, function($client){
uv_shutdown($client, function($client) use (&$parsers, &$clients){
uv_close($client, function($client) use (&$parsers, &$clients){
unset($parsers[(int)$client]);
unset($clients[(int)$client]);
});
});
return;
} else if ($nread == 0) {
if (uv_last_error() == UV::EOF) {
uv_shutdown($client, function($client) use (&$parsers, &$clients){
@ -46,6 +49,7 @@ uv_listen($server, 511, function($server_stream) use (&$parsers, &$clients){
unset($clients[(int)$client]);
});
});
return;
}
} else {
$result = array();
@ -63,6 +67,4 @@ uv_listen($server, 511, function($server_stream) use (&$parsers, &$clients){
});
});
//require "debug_timer.php";
uv_run(uv_default_loop());
uv_run(uv_default_loop());