Changeset 10063
- Timestamp:
- 12/01/08 15:34:58 (1 month ago)
- Files:
-
- trunk/jaws/html/libraries/pear/Net/Socket.php (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jaws/html/libraries/pear/Net/Socket.php
r8996 r10063 1 1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Stig Bakken <ssb@php.net> | 17 // | Chuck Hagenbuch <chuck@horde.org> | 18 // +----------------------------------------------------------------------+ 19 // 20 // $Id: Socket.php,v 1.38 2008/02/15 18:24:17 chagenbu Exp $ 2 /** 3 * Net_Socket 4 * 5 * PHP Version 4 6 * 7 * Copyright (c) 1997-2003 The PHP Group 8 * 9 * This source file is subject to version 2.0 of the PHP license, 10 * that is bundled with this package in the file LICENSE, and is 11 * available at through the world-wide-web at 12 * http://www.php.net/license/2_02.txt. 13 * If you did not receive a copy of the PHP license and are unable to 14 * obtain it through the world-wide-web, please send a note to 15 * license@php.net so we can mail you a copy immediately. 16 * 17 * Authors: Stig Bakken <ssb@php.net> 18 * Chuck Hagenbuch <chuck@horde.org> 19 * 20 * @category Net 21 * @package Net_Socket 22 * @author Stig Bakken <ssb@php.net> 23 * @author Chuck Hagenbuch <chuck@horde.org> 24 * @copyright 1997-2003 The PHP Group 25 * @license http://www.php.net/license/2_02.txt PHP 2.02 26 * @version CVS: $Id: Socket.php,v 1.40 2008/12/01 15:25:01 chagenbu Exp $ 27 * @link http://pear.php.net/packages/Net_Socket 28 */ 21 29 22 30 require_once 'PEAR.php'; 23 31 24 define('NET_SOCKET_READ', 1);32 define('NET_SOCKET_READ', 1); 25 33 define('NET_SOCKET_WRITE', 2); 26 34 define('NET_SOCKET_ERROR', 4); … … 29 37 * Generalized Socket class. 30 38 * 31 * @version 1.1 32 * @author Stig Bakken <ssb@php.net> 33 * @author Chuck Hagenbuch <chuck@horde.org> 39 * @category Net 40 * @package Net_Socket 41 * @author Stig Bakken <ssb@php.net> 42 * @author Chuck Hagenbuch <chuck@horde.org> 43 * @copyright 1997-2003 The PHP Group 44 * @license http://www.php.net/license/2_02.txt PHP 2.02 45 * @link http://pear.php.net/packages/Net_Socket 34 46 */ 35 class Net_Socket extends PEAR {36 47 class Net_Socket extends PEAR 48 { 37 49 /** 38 50 * Socket file pointer. … … 83 95 * already connected, it disconnects and connects again. 84 96 * 85 * @param string $addr IP address or host name.86 * @param integer $port TCP port number.87 * @param boolean $persistent (optional) Whether the connection is88 * persistent (kept open between requests89 * by the web server).90 * @param integer $timeout (optional) How long to wait for data.91 * @param array $options See options for stream_context_create.97 * @param string $addr IP address or host name. 98 * @param integer $port TCP port number. 99 * @param boolean $persistent (optional) Whether the connection is 100 * persistent (kept open between requests 101 * by the web server). 102 * @param integer $timeout (optional) How long to wait for data. 103 * @param array $options See options for stream_context_create. 92 104 * 93 105 * @access public … … 95 107 * @return boolean | PEAR_Error True on success or a PEAR_Error on failure. 96 108 */ 97 function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null) 109 function connect($addr, $port = 0, $persistent = null, 110 $timeout = null, $options = null) 98 111 { 99 112 if (is_resource($this->fp)) { … … 125 138 126 139 $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen'; 127 $errno = 0; 128 $errstr = ''; 140 $errno = 0; 141 $errstr = ''; 142 129 143 $old_track_errors = @ini_set('track_errors', 1); 144 130 145 if ($options && function_exists('stream_context_create')) { 131 146 if ($this->timeout) { … … 138 153 // Since PHP 5 fsockopen doesn't allow context specification 139 154 if (function_exists('stream_socket_client')) { 140 $flags = $this->persistent ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT; 155 $flags = STREAM_CLIENT_CONNECT; 156 157 if ($this->persistent) { 158 $flags = STREAM_CLIENT_PERSISTENT; 159 } 160 141 161 $addr = $this->addr . ':' . $this->port; 142 $fp = stream_socket_client($addr, $errno, $errstr, $timeout, $flags, $context); 162 $fp = stream_socket_client($addr, $errno, $errstr, 163 $timeout, $flags, $context); 143 164 } else { 144 $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context); 165 $fp = @$openfunc($this->addr, $this->port, $errno, 166 $errstr, $timeout, $context); 145 167 } 146 168 } else { 147 169 if ($this->timeout) { 148 $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout); 170 $fp = @$openfunc($this->addr, $this->port, $errno, 171 $errstr, $this->timeout); 149 172 } else { 150 173 $fp = @$openfunc($this->addr, $this->port, $errno, $errstr); … … 153 176 154 177 if (!$fp) { 155 if ($errno == 0 && isset($php_errormsg)) {178 if ($errno == 0 && !strlen($errstr) && isset($php_errormsg)) { 156 179 $errstr = $php_errormsg; 157 180 } … … 200 223 * is data for blocking sockets. 201 224 * 202 * @param boolean $mode True for blocking sockets, false for nonblocking. 225 * @param boolean $mode True for blocking sockets, false for nonblocking. 226 * 203 227 * @access public 204 228 * @return mixed true on success or a PEAR_Error instance otherwise … … 219 243 * expressed in the sum of seconds and microseconds 220 244 * 221 * @param integer $seconds Seconds. 222 * @param integer $microseconds Microseconds. 245 * @param integer $seconds Seconds. 246 * @param integer $microseconds Microseconds. 247 * 223 248 * @access public 224 249 * @return mixed true on success or a PEAR_Error instance otherwise … … 237 262 * See php's stream_set_write_buffer for more information. 238 263 * 239 * @param integer $size Write buffer size. 264 * @param integer $size Write buffer size. 265 * 240 266 * @access public 241 267 * @return mixed on success or an PEAR_Error object otherwise … … 266 292 * 267 293 * @access public 268 * @return mixed Array containing information about existing socket resource or a PEAR_Error instance otherwise 294 * @return mixed Array containing information about existing socket 295 * resource or a PEAR_Error instance otherwise 269 296 */ 270 297 function getStatus() … … 279 306 /** 280 307 * Get a specified line of data 308 * 309 * @param int $size ?? 281 310 * 282 311 * @access public … … 299 328 * beforehand, this is definitely the way to go. 300 329 * 301 * @param integer $size The number of bytes to read from the socket. 330 * @param integer $size The number of bytes to read from the socket. 331 * 302 332 * @access public 303 333 * @return $size bytes of data from the socket, or a PEAR_Error if … … 316 346 * Write a specified amount of data. 317 347 * 318 * @param string $data Data to write. 319 * @param integer $blocksize Amount of data to write at once. 320 * NULL means all at once. 321 * 322 * @access public 323 * @return mixed If the socket is not connected, returns an instance of PEAR_Error 348 * @param string $data Data to write. 349 * @param integer $blocksize Amount of data to write at once. 350 * NULL means all at once. 351 * 352 * @access public 353 * @return mixed If the socket is not connected, returns an instance of 354 * PEAR_Error 324 355 * If the write succeeds, returns the number of bytes written 325 356 * If the write fails, returns false. … … 338 369 } 339 370 340 $pos = 0;371 $pos = 0; 341 372 $size = strlen($data); 342 373 while ($pos < $size) { … … 355 386 * Write a line of data to the socket, followed by a trailing "\r\n". 356 387 * 388 * @param string $data Data to write 389 * 357 390 * @access public 358 391 * @return mixed fputs result, or an error … … 445 478 446 479 $string = ''; 447 while (($char = @fread($this->fp, 1)) != "\x00") {480 while (($char = @fread($this->fp, 1)) != "\x00") { 448 481 $string .= $char; 449 482 } … … 485 518 486 519 $line = ''; 520 487 521 $timeout = time() + $this->timeout; 522 488 523 while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) { 489 524 $line .= @fgets($this->fp, $this->lineLength); … … 525 560 * with a timeout specified by tv_sec and tv_usec. 526 561 * 527 * @param integer $state Which of read/write/error to check for.528 * @param integer $tv_sec Number of seconds for timeout.529 * @param integer $tv_usec Number of microseconds for timeout.562 * @param integer $state Which of read/write/error to check for. 563 * @param integer $tv_sec Number of seconds for timeout. 564 * @param integer $tv_usec Number of microseconds for timeout. 530 565 * 531 566 * @access public … … 539 574 } 540 575 541 $read = null;542 $write = null;576 $read = null; 577 $write = null; 543 578 $except = null; 544 579 if ($state & NET_SOCKET_READ) { … … 551 586 $except[] = $this->fp; 552 587 } 553 if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) { 588 if (false === ($sr = stream_select($read, $write, $except, 589 $tv_sec, $tv_usec))) { 554 590 return false; 555 591 } … … 571 607 * Turns encryption on/off on a connected socket. 572 608 * 573 * @param bool $enabled Set this parameter to true to enable encryption 574 * and false to disable encryption. 575 * @param integer $type Type of encryption. See 576 * http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values. 577 * 578 * @access public 579 * @return false on error, true on success and 0 if there isn't enough data and the 580 * user should try again (non-blocking sockets only). A PEAR_Error object 581 * is returned if the socket is not connected 609 * @param bool $enabled Set this parameter to true to enable encryption 610 * and false to disable encryption. 611 * @param integer $type Type of encryption. See stream_socket_enable_crypto() 612 * for values. 613 * 614 * @see http://se.php.net/manual/en/function.stream-socket-enable-crypto.php 615 * @access public 616 * @return false on error, true on success and 0 if there isn't enough data 617 * and the user should try again (non-blocking sockets only). 618 * A PEAR_Error object is returned if the socket is not 619 * connected 582 620 */ 583 621 function enableCrypto($enabled, $type) … … 589 627 return @stream_socket_enable_crypto($this->fp, $enabled, $type); 590 628 } else { 591 return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0'); 629 $msg = 'Net_Socket::enableCrypto() requires php version >= 5.1.0'; 630 return $this->raiseError($msg); 592 631 } 593 632 }
