Skip to content

test to function stream_socket_sendto(); #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions ext/standard/tests/streams/stream_socket_sendto.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--TEST--
int stream_socket_sendto ( resource $socket , string $data [, int $flags = 0 [, string $address ]] );
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br> - @phpsp - sao paulo - br
--SKIPIF--
<?php
if (getenv("SKIP_ONLINE_TESTS")) { die('skip: online test'); }
?>
--FILE--
<?php
$serverUri = "tcp://127.0.0.1:31854";
$serverUrl = "http://php.net";
$stringSocket = "out of band data.";
$stringFWrite = "normal data to transmit";
$sock = stream_socket_server($serverUri, $errno, $errstr);

if (is_resource($sock)) {
fwrite($sock, $stringFWrite);
var_dump(stream_socket_sendto());
var_dump(stream_socket_sendto($sock));
var_dump(stream_socket_sendto($sock, $stringSocket));
var_dump(stream_socket_sendto($sock, $stringSocket, STREAM_OOB));
var_dump(stream_socket_sendto($sock, $stringSocket, STREAM_OOB, $serverUri));
var_dump(stream_socket_sendto($sock, $stringSocket, STREAM_OOB, $serverUrl));
} else {
die("Test stream_socket_enable_crypto has failed; Unable to connect: {$errstr} ({$errno})");
}
?>
--CLEAN--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention, but the entire --CLEAN-- section is not needed, as I explained in another PR, then its run in a separate script after, so the variables do no longer exists, if anything, this should be done in --FILE--, but php already does this once the script ends :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the removal of the --CLEAN-- section, then this PR is fine, thanks for your work!

<?php
fclose($sock);
unset($sock);
unset($serverUri);
unset($serverUrl);
unset($stringSocket);
unset($errno);
unset($errstr);
?>

--EXPECTF--
Notice: fwrite(): send of %i bytes failed with errno=%i Broken pipe in %s on line %i

Warning: stream_socket_sendto() expects at least %i parameters, %i given in %s on line %i
bool(%s)

Warning: stream_socket_sendto() expects at least %i parameters, %i given in %s on line %i
bool(%s)

Warning: stream_socket_sendto(): Broken pipe
in %s on line %i
int(%i)

Warning: stream_socket_sendto(): Broken pipe
in %s on line %i
int(%i)

Warning: stream_socket_sendto(): php_network_getaddresses: getaddrinfo failed: Name or service not known in %s on line %i

Warning: stream_socket_sendto(): Failed to resolve %s: php_network_getaddresses: getaddrinfo failed: Name or service not known in %s on line %i

Warning: stream_socket_sendto(): Failed to parse %s into a valid network address in %s on line %i
bool(%s)

Warning: stream_socket_sendto(): php_network_getaddresses: getaddrinfo failed: Name or service not known in %s on line %i

Warning: stream_socket_sendto(): Failed to resolve %s: php_network_getaddresses: getaddrinfo failed: Name or service not known in %s on line %i

Warning: stream_socket_sendto(): Failed to parse %s into a valid network address in %s on line %i
bool(%s)