com php-src: Tidy up test for bug72333: ext/openssl/tests/bug74159.phpt

[email protected] (Jakub Zelenka)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    8e5d080d54766ea5dd8c1bd8ac6c1f7dcd6524c6
Author:    Jakub Zelenka <[email protected]>         Sat, 11 Mar 2017 19:38:26 +0000
Parents:   f0e67d1a56d03383067ce04d9109dc9c83b37e03
Branches:  PHP-7.0

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=8e5d080d54766ea5dd8c1bd8ac6c1f7dcd6524c6

Log:
Tidy up test for bug72333

Bugs:
https://bugs.php.net/72333

Changed paths:
  M  ext/openssl/tests/bug74159.phpt


Diff:
diff --git a/ext/openssl/tests/bug74159.phpt b/ext/openssl/tests/bug74159.phpt
index 2aaa68b..aa51a46 100644
--- a/ext/openssl/tests/bug74159.phpt
+++ b/ext/openssl/tests/bug74159.phpt
@@ -4,103 +4,108 @@ Bug #74159: Writing a large buffer to non-blocking encrypted streams fails
 <?php
 if (!extension_loaded("openssl")) die("skip openssl not loaded");
 if (!function_exists("proc_open")) die("skip no proc_open");
+?>
 --FILE--
 <?php
+// the server code is doing many readings in a short interval which is
+// not really reliable on more powerful machine but cover different
+// scenarios which might be useful. More reliable test is bug72333.phpt
 $serverCode = <<<'CODE'
-    $serverUri = "ssl://127.0.0.1:64321";
-    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
-    $serverCtx = stream_context_create(['ssl' => [
-        'local_cert' => __DIR__ . '/bug54992.pem',
-        'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER,
-    ]]);
+    $serverUri = "ssl://127.0.0.1:10012";
+	$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
+	$serverCtx = stream_context_create(['ssl' => [
+	    'local_cert' => __DIR__ . '/bug54992.pem',
+		'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER,
+	]]);
 
     $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
-    phpt_notify();
+	phpt_notify();
 
     $client = stream_socket_accept($server, 1);
 
     if (!$client) {
-        exit();
-    }
+	    exit();
+	}
 
     $data = '';
-    while (strlen($data) < 0xfffff) {
-        $buffer = fread($client, 8192);
-        if (empty($buffer)) {
-            exit();
-        }
-        $data .= $buffer;
-        usleep(100);
-    }
-    
+	while (strlen($data) < 0xfffff) {
+	    $buffer = fread($client, 8192);
+		if (empty($buffer)) {
+		    exit();
+		}
+		$data .= $buffer;
+		usleep(100);
+	}
+
     fclose($client);
 CODE;
 
 $clientCode = <<<'CODE'
     function streamRead($stream) : int {
-        return strlen(fread($stream, 8192));
-    }
+	    return strlen(fread($stream, 8192));
+	}
 
     function streamWrite($stream, $data) : int {
-        return fwrite($stream, $data);
-    }
+	    return fwrite($stream, $data);
+	}
 
     function waitForWrite(...$streams) : bool {
-        $read = null;
-        $except = null;
-        while($streams && !($n = stream_select($read, $streams, $except, 1)));
-        return $n > 0;
-    }
+	    $read = null;
+		$except = null;
+		while($streams && !($n = stream_select($read, $streams, $except, 1)));
+		return $n > 0;
+	}
 
     function waitForRead(...$streams) : bool {
-        $write = null;
-        $except = null;
-        while ($streams && !($n = stream_select($streams, $write, $except, 1)));
-        return $n > 0;
-    }
+	    $write = null;
+		$except = null;
+		while ($streams && !($n = stream_select($streams, $write, $except, 1)));
+		return $n > 0;
+	}
 
     set_error_handler(function ($errno, $errstr) {
-        exit("$errstr\n");
-    });
+	    exit("$errstr\n");
+	});
 
-    $serverUri = "tcp://127.0.0.1:64321";
-    $clientFlags = STREAM_CLIENT_CONNECT;
-    $clientCtx = stream_context_create(['ssl' => [
-        'verify_peer' => true,
-        'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'peer_name' => 'bug54992.local',
-    ]]);
+    $serverUri = "tcp://127.0.0.1:10012";
+	$clientFlags = STREAM_CLIENT_CONNECT;
+	$clientCtx = stream_context_create(['ssl' => [
+	    'verify_peer' => true,
+		'cafile' => __DIR__ . '/bug54992-ca.pem',
+		'peer_name' => 'bug54992.local',
+	]]);
 
     phpt_wait();
 
     $fp = stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx);
 
     stream_set_blocking($fp, false);
-    while (0 === ($n = stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)));
+	while (0 === ($n = stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)));
 
     $data = str_repeat("a", 0xfffff);
-    $written = 0;
-    $total = $written;
-    while(!empty($data)) {
-        $written = streamWrite($fp, $data);
-        $total += $written;
-        $data = substr($data, $written);
-        waitForWrite($fp);
-    }
-    printf("Written %d bytes\n", $total);
+	$written = 0;
+	$total = $written;
+	while(!empty($data)) {
+	    $written = streamWrite($fp, $data);
+		$total += $written;
+		$data = substr($data, $written);
+		waitForWrite($fp);
+	}
+	printf("Written %d bytes\n", $total);
 
     while(waitForRead($fp)) {
-        streamRead($fp);
-        if (feof($fp)) {
-            break;
-        }
-    }
+	    streamRead($fp);
+		if (feof($fp)) {
+		    break;
+		}
+	}
 
     exit("DONE\n");
 CODE;
 
 include 'ServerClientTestCase.inc';
 ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
+?>
 --EXPECTF--
 Written 1048575 bytes
 DONE
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.