Ignore:
Timestamp:
2013/08/26 12:42:34 (11 years ago)
Author:
kimoto
Message:

#2275 PEAR更新
不要なrequire_onceの削除
レガシーなPEARモジュールは使わない
SearchReplace?.phpのパスが間違っているので修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/module/Net/Socket.php

    r20998 r23125  
    55 * PHP Version 4 
    66 * 
    7  * Copyright (c) 1997-2003 The PHP Group 
     7 * Copyright (c) 1997-2013 The PHP Group 
    88 * 
    99 * This source file is subject to version 2.0 of the PHP license, 
     
    2424 * @copyright 1997-2003 The PHP Group 
    2525 * @license   http://www.php.net/license/2_02.txt PHP 2.02 
    26  * @version   CVS: $Id$ 
    2726 * @link      http://pear.php.net/packages/Net_Socket 
    2827 */ 
     
    7877 
    7978    /** 
    80      * Number of seconds to wait on socket connections before assuming 
     79     * Number of seconds to wait on socket operations before assuming 
    8180     * there's no more data. Defaults to no timeout. 
    82      * @var integer $timeout 
    83      */ 
    84     var $timeout = false; 
     81     * @var integer|float $timeout 
     82     */ 
     83    var $timeout = null; 
    8584 
    8685    /** 
     
    101100     * already connected, it disconnects and connects again. 
    102101     * 
    103      * @param string  $addr       IP address or host name. 
     102     * @param string  $addr       IP address or host name (may be with protocol prefix). 
    104103     * @param integer $port       TCP port number. 
    105104     * @param boolean $persistent (optional) Whether the connection is 
    106105     *                            persistent (kept open between requests 
    107106     *                            by the web server). 
    108      * @param integer $timeout    (optional) How long to wait for data. 
     107     * @param integer $timeout    (optional) Connection socket timeout. 
    109108     * @param array   $options    See options for stream_context_create. 
    110109     * 
    111110     * @access public 
    112111     * 
    113      * @return boolean | PEAR_Error  True on success or a PEAR_Error on failure. 
     112     * @return boolean|PEAR_Error  True on success or a PEAR_Error on failure. 
    114113     */ 
    115114    function connect($addr, $port = 0, $persistent = null, 
     
    123122        if (!$addr) { 
    124123            return $this->raiseError('$addr cannot be empty'); 
    125         } elseif (strspn($addr, '.0123456789') == strlen($addr) || 
    126                   strstr($addr, '/') !== false) { 
     124        } else if (strspn($addr, ':.0123456789') == strlen($addr)) { 
     125            $this->addr = strpos($addr, ':') !== false ? '['.$addr.']' : $addr; 
     126        } else { 
    127127            $this->addr = $addr; 
    128         } else { 
    129             $this->addr = @gethostbyname($addr); 
    130128        } 
    131129 
     
    134132        if ($persistent !== null) { 
    135133            $this->persistent = $persistent; 
    136         } 
    137  
    138         if ($timeout !== null) { 
    139             $this->timeout = $timeout; 
    140134        } 
    141135 
     
    146140        $old_track_errors = @ini_set('track_errors', 1); 
    147141 
     142        if ($timeout <= 0) { 
     143            $timeout = @ini_get('default_socket_timeout'); 
     144        } 
     145 
    148146        if ($options && function_exists('stream_context_create')) { 
    149             if ($this->timeout) { 
    150                 $timeout = $this->timeout; 
    151             } else { 
    152                 $timeout = 0; 
    153             } 
    154147            $context = stream_context_create($options); 
    155148 
     
    170163            } 
    171164        } else { 
    172             if ($this->timeout) { 
    173                 $fp = @$openfunc($this->addr, $this->port, $errno, 
    174                                  $errstr, $this->timeout); 
    175             } else { 
    176                 $fp = @$openfunc($this->addr, $this->port, $errno, $errstr); 
    177             } 
     165            $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout); 
    178166        } 
    179167 
     
    188176        @ini_set('track_errors', $old_track_errors); 
    189177        $this->fp = $fp; 
    190  
     178        $this->setTimeout(); 
    191179        return $this->setBlocking($this->blocking); 
    192180    } 
     
    259247     * 
    260248     * @param integer $seconds      Seconds. 
    261      * @param integer $microseconds Microseconds. 
    262      * 
    263      * @access public 
    264      * @return mixed true on success or a PEAR_Error instance otherwise 
    265      */ 
    266     function setTimeout($seconds, $microseconds) 
    267     { 
    268         if (!is_resource($this->fp)) { 
    269             return $this->raiseError('not connected'); 
    270         } 
    271  
    272         return socket_set_timeout($this->fp, $seconds, $microseconds); 
     249     * @param integer $microseconds Microseconds, optional. 
     250     * 
     251     * @access public 
     252     * @return mixed True on success or false on failure or 
     253     *               a PEAR_Error instance when not connected 
     254     */ 
     255    function setTimeout($seconds = null, $microseconds = null) 
     256    { 
     257        if (!is_resource($this->fp)) { 
     258            return $this->raiseError('not connected'); 
     259        } 
     260 
     261        if ($seconds === null && $microseconds === null) { 
     262            $seconds      = (int) $this->timeout; 
     263            $microseconds = (int) (($this->timeout - $seconds) * 1000000); 
     264        } else { 
     265            $this->timeout = $seconds + $microseconds/1000000; 
     266        } 
     267 
     268        if ($this->timeout > 0) { 
     269            return stream_set_timeout($this->fp, (int) $seconds, (int) $microseconds); 
     270        } 
     271        else { 
     272            return false; 
     273        } 
    273274    } 
    274275 
     
    316317        } 
    317318 
    318         return socket_get_status($this->fp); 
     319        return stream_get_meta_data($this->fp); 
    319320    } 
    320321 
     
    322323     * Get a specified line of data 
    323324     * 
    324      * @param int $size ?? 
    325      * 
    326      * @access public 
    327      * @return $size bytes of data from the socket, or a PEAR_Error if 
    328      *         not connected. 
     325     * @param int $size Reading ends when size - 1 bytes have been read, 
     326     *                  or a newline or an EOF (whichever comes first). 
     327     *                  If no size is specified, it will keep reading from 
     328     *                  the stream until it reaches the end of the line. 
     329     * 
     330     * @access public 
     331     * @return mixed $size bytes of data from the socket, or a PEAR_Error if 
     332     *         not connected. If an error occurs, FALSE is returned. 
    329333     */ 
    330334    function gets($size = null) 
     
    371375     * @access public 
    372376     * @return mixed If the socket is not connected, returns an instance of 
    373      *               PEAR_Error 
    374      *               If the write succeeds, returns the number of bytes written 
     377     *               PEAR_Error. 
     378     *               If the write succeeds, returns the number of bytes written. 
    375379     *               If the write fails, returns false. 
     380     *               If the socket times out, returns an instance of PEAR_Error. 
    376381     */ 
    377382    function write($data, $blocksize = null) 
     
    382387 
    383388        if (is_null($blocksize) && !OS_WINDOWS) { 
    384             return @fwrite($this->fp, $data); 
     389            $written = @fwrite($this->fp, $data); 
     390 
     391            // Check for timeout or lost connection 
     392            if (!$written) { 
     393                $meta_data = $this->getStatus(); 
     394 
     395                if (!is_array($meta_data)) { 
     396                    return $meta_data; // PEAR_Error 
     397                } 
     398 
     399                if (!empty($meta_data['timed_out'])) { 
     400                    return $this->raiseError('timed out'); 
     401                } 
     402            } 
     403 
     404            return $written; 
    385405        } else { 
    386406            if (is_null($blocksize)) { 
     
    392412            while ($pos < $size) { 
    393413                $written = @fwrite($this->fp, substr($data, $pos, $blocksize)); 
     414 
     415                // Check for timeout or lost connection 
    394416                if (!$written) { 
     417                    $meta_data = $this->getStatus(); 
     418 
     419                    if (!is_array($meta_data)) { 
     420                        return $meta_data; // PEAR_Error 
     421                    } 
     422 
     423                    if (!empty($meta_data['timed_out'])) { 
     424                        return $this->raiseError('timed out'); 
     425                    } 
     426 
    395427                    return $written; 
    396428                } 
     429 
    397430                $pos += $written; 
    398431            } 
     
    408441     * 
    409442     * @access public 
    410      * @return mixed fputs result, or an error 
     443     * @return mixed fwrite() result, or PEAR_Error when not connected 
    411444     */ 
    412445    function writeLine($data) 
Note: See TracChangeset for help on using the changeset viewer.