nicobn          Thu Aug 16 19:00:00 2007 UTC

  Modified files:              
    /phpdoc/en/reference/sockets/functions      socket-set-block.xml 
                                                socket-set-nonblock.xml 
  Log:
  Added better examples and wrote a little explanation on what blocking is
  
  
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sockets/functions/socket-set-block.xml?r1=1.8&r2=1.9&diff_format=u
Index: phpdoc/en/reference/sockets/functions/socket-set-block.xml
diff -u phpdoc/en/reference/sockets/functions/socket-set-block.xml:1.8 
phpdoc/en/reference/sockets/functions/socket-set-block.xml:1.9
--- phpdoc/en/reference/sockets/functions/socket-set-block.xml:1.8      Wed Jun 
20 22:25:25 2007
+++ phpdoc/en/reference/sockets/functions/socket-set-block.xml  Thu Aug 16 
19:00:00 2007
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.8 $ -->
+<!-- $Revision: 1.9 $ -->
 <refentry xmlns="http://docbook.org/ns/docbook"; 
xml:id="function.socket-set-block">
  <refnamediv>
   <refname>socket_set_block</refname>
@@ -13,8 +13,14 @@
    
<methodparam><type>resource</type><parameter>socket</parameter></methodparam>
   </methodsynopsis>
   <para>
-   The <function>socket_set_block</function> function removes the O_NONBLOCK 
flag
-   on the socket specified by the <parameter>socket</parameter> parameter.
+   The <function>socket_set_block</function> function removes the 
+   <constant>O_NONBLOCK</constant> flag on the socket specified by the 
+   <parameter>socket</parameter> parameter.
+  </para>
+  <para>
+   When an operation (e.g. receive, send, connect, accept, ...) is performed 
on 
+   a blocking socket, the script will pause its execution until it receives
+   a signal or it can perform the operation.
   </para>
  </refsect1>
 
@@ -26,6 +32,8 @@
      <term><parameter>socket</parameter></term>
      <listitem>
       <para>
+       A valid socket resource created with <function>socket_create</function>
+       or <function>socket_accept</function>.
       </para>
      </listitem>
     </varlistentry>
@@ -44,31 +52,23 @@
   &reftitle.examples;
   <para>
    <example>
-    <title><function>socket_set_block</function> example</title>
+    <title><function>socket_set_nonblock</function> example</title>
     <programlisting role="php">
 <![CDATA[
 <?php
+$socket = socket_create_listen(1223);
+socket_set_block($socket);
 
-$port = 9090;
-if (($socket = socket_create_listen($port)) === false) {
-    echo "socket_create_listen() failed. Reason: 
".socket_strerror(socket_last_error());
-}
-
-if (socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1) === false) {
-    echo "socket_set_option() failed. Reason: 
".socket_strerror(socket_last_error($socket));
-}
-
-if (socket_set_nonblock($socket) === false) { // $socket is now nonblocking
-    echo "socket_set_nonblock() failed. Reason: 
".socket_strerror(socket_last_error($socket));
-}
-
-if (socket_set_block($socket) === false) {     // $socket is now blocking
-    echo "socket_set_block() failed. Reason: ". 
socket_strerror(socket_last_error($socket));
-}
-
+socket_accept($socket);
 ?>
 ]]>
     </programlisting>
+    <para>
+     This example creates a listening socket on all interfaces on port 1223 and
+     sets the socket to <constant>O_BLOCK</constant> mode. 
+     <function>socket_accept</function> will hang until there is a connection
+     to accept.
+    </para>
    </example>
   </para>
  </refsect1>
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml?r1=1.11&r2=1.12&diff_format=u
Index: phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml
diff -u phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml:1.11 
phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml:1.12
--- phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml:1.11  Wed Jun 
20 22:25:25 2007
+++ phpdoc/en/reference/sockets/functions/socket-set-nonblock.xml       Thu Aug 
16 19:00:00 2007
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.11 $ -->
+<!-- $Revision: 1.12 $ -->
 <refentry xmlns="http://docbook.org/ns/docbook"; 
xml:id="function.socket-set-nonblock">
  <refnamediv>
   <refname>socket_set_nonblock</refname>
@@ -13,8 +13,15 @@
    
<methodparam><type>resource</type><parameter>socket</parameter></methodparam>
   </methodsynopsis>
   <para>
-   The <function>socket_set_nonblock</function> function sets the O_NONBLOCK 
flag
-   on the socket specified by the <parameter>socket</parameter> parameter.
+   The <function>socket_set_nonblock</function> function sets the 
+   <constant>O_NONBLOCK</constant> flag on the socket specified by
+   the <parameter>socket</parameter> parameter.
+  </para>
+  <para>
+   When an operation (e.g. receive, send, connect, accept, ...) is performed 
on 
+   a non-blocking socket, the script not pause its execution until it receives 
a 
+   signal or it can perform the operation. Rather, if the operation would 
result
+   in a block, the called function will fail.
   </para>
  </refsect1>
 
@@ -26,6 +33,8 @@
      <term><parameter>socket</parameter></term>
      <listitem>
       <para>
+       A valid socket resource created with <function>socket_create</function>
+       or <function>socket_accept</function>.
       </para>
      </listitem>
     </varlistentry>
@@ -48,21 +57,19 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-$port = 9090;
-if (($socket = socket_create_listen($port)) === false) {
-    echo "socket_create_listen() failed. Reason: 
".socket_strerror(socket_last_error());
-}
-
-if (socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1) === false) {
-    echo "socket_set_option() failed. Reason: 
".socket_strerror(socket_last_error($socket));
-}
-
-if (socket_set_nonblock($socket) === false) {
-    echo "socket_set_nonblock() failed. Reason: 
".socket_strerror(socket_last_error($socket));
-}
+$socket = socket_create_listen(1223);
+socket_set_nonblock($socket);
+
+socket_accept($socket);
 ?>
 ]]>
     </programlisting>
+    <para>
+     This example creates a listening socket on all interfaces on port 1223 and
+     sets the socket to <constant>O_NONBLOCK</constant> mode. 
+     <function>socket_accept</function> will immediately fail unless there is a
+     pending connection exactly at this moment.
+    </para>
    </example>
   </para>
  </refsect1>

Reply via email to