cvs: pear /Net_Socket Socket.php

From: Date: Fri, 30 Apr 2004 18:29:30 +0000
Subject: cvs: pear /Net_Socket Socket.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-19040@lists.php.net to get a copy of this message
chagenbu Fri Apr 30 14:29:30 2004 EDT Modified files: /pear/Net_Socket Socket.php Log: Avoid a bunch of redundant is_resource() calls and layers of function calls by using fread/fwrite/fgets directly in methods instead of calling user-exposed read(), write(), gets(), etc. Submitted By: Guillaume Desclaux <guillaume@desclaux.net> http://cvs.php.net/diff.php/pear/Net_Socket/Socket.php?r1=1.11&r2=1.12&ty=u Index: pear/Net_Socket/Socket.php diff -u pear/Net_Socket/Socket.php:1.11 pear/Net_Socket/Socket.php:1.12 --- pear/Net_Socket/Socket.php:1.11 Tue Apr 27 23:07:46 2004 +++ pear/Net_Socket/Socket.php Fri Apr 30 14:29:30 2004 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ // -// $Id: Socket.php,v 1.11 2004/04/28 03:07:46 chagenbu Exp $ +// $Id: Socket.php,v 1.12 2004/04/30 18:29:30 chagenbu Exp $ /** * Generalized Socket class. @@ -285,7 +285,7 @@ function writeLine ($data) { if (is_resource($this->fp)) { - return $this->write($data . "\r\n"); + return fwrite($this->fp, $data . "\r\n"); } return $this->raiseError("not connected"); } @@ -311,7 +311,7 @@ function readByte() { if (is_resource($this->fp)) { - return ord($this->read(1)); + return ord(fread($this->fp, 1)); } return $this->raiseError("not connected"); } @@ -326,7 +326,7 @@ function readWord() { if (is_resource($this->fp)) { - $buf = $this->read(2); + $buf = fread($this->fp, 2); return (ord($buf[0]) + (ord($buf[1]) << 8)); } return $this->raiseError("not connected"); @@ -342,7 +342,7 @@ function readInt() { if (is_resource($this->fp)) { - $buf = $this->read(4); + $buf = fread($this->fp, 4); return (ord($buf[0]) + (ord($buf[1]) << 8) + (ord($buf[2]) << 16) + (ord($buf[3]) << 24)); } @@ -360,7 +360,7 @@ { if (is_resource($this->fp)) { $string = ''; - while (($char = $this->read(1)) != "\x00") { + while (($char = fread($this->fp, 1)) != "\x00") { $string .= $char; } return $string; @@ -378,7 +378,7 @@ function readIPAddress() { if (is_resource($this->fp)) { - $buf = $this->read(4); + $buf = fread($this->fp, 4); return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]), ord($buf[2]), ord($buf[3])); } @@ -399,8 +399,8 @@ if (is_resource($this->fp)) { $line = ''; $timeout = time() + $this->timeout; - while (!$this->eof() && (!$this->timeout || time() < $timeout)) { - $line .= $this->gets($this->lineLength); + while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) { + $line .= fgets($this->fp, $this->lineLength); if (substr($line, -2) == "\r\n" || substr($line, -1) == "\n") { return rtrim($line, "\r\n"); @@ -423,8 +423,9 @@ { if (is_resource($this->fp)) { $data = ''; - while (!$this->eof()) - $data .= $this->read($this->lineLength); + while (!feof($this->fp)) { + $data .= fread($this->fp, $this->lineLength); + } return $data; } return $this->raiseError("not connected");

« previous php.pear.cvs (#19040) next »