nicobn Mon Aug 20 15:59:44 2007 UTC
Modified files:
/phpdoc/en/reference/sockets/functions socket-set-option.xml
Log:
Modified example to handle all errors.
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sockets/functions/socket-set-option.xml?r1=1.13&r2=1.14&diff_format=u
Index: phpdoc/en/reference/sockets/functions/socket-set-option.xml
diff -u phpdoc/en/reference/sockets/functions/socket-set-option.xml:1.13
phpdoc/en/reference/sockets/functions/socket-set-option.xml:1.14
--- phpdoc/en/reference/sockets/functions/socket-set-option.xml:1.13 Mon Aug
20 03:59:58 2007
+++ phpdoc/en/reference/sockets/functions/socket-set-option.xml Mon Aug 20
15:59:43 2007
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.13 $ -->
+<!-- $Revision: 1.14 $ -->
<refentry xmlns="http://docbook.org/ns/docbook"
xml:id="function.socket-set-option">
<refnamediv>
<refname>socket_set_option</refname>
@@ -88,10 +88,24 @@
<![CDATA[
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
-socket_bind($socket, '127.0.0.1', 1223);
-if (socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR) !== 0) {
+if (!is_resource($socket)) {
+ echo 'Unable to create socket: '. socket_strerror(socket_last_error()) .
PHP_EOL;
+}
+
+if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
+ echo 'Unable to set option on socket: '.
socket_strerror(socket_last_error()) . PHP_EOL;
+}
+
+if (!socket_bind($socket, '127.0.0.1', 1223)) {
+ echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) .
PHP_EOL;
+}
+
+$rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR);
+
+if ($rval === false) {
+ echo 'Unable to get socket option: '. socket_strerror(socket_last_error())
. PHP_EOL;
+} else if ($rval !== 0) {
echo 'SO_REUSEADDR is set on socket !' . PHP_EOL;
}
?>