Changeset 1880

Show
Ignore:
Timestamp:
10/07/08 14:00:19 (1 month ago)
Author:
prema
Message:

FIX

  • http response socket reading
  • socket some method visibility modifier
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework/trunk/src/main/php/net/stubbles/peer/http/stubHTTPResponse.php

    r1870 r1880  
    213213    protected function readDefault($readLength) 
    214214    { 
    215         return ($body = $this->socket->read($readLength)); 
     215        $body = $buffer = ''; 
     216        $read = 0; 
     217 
     218        while ($read < $readLength) { 
     219            $buffer  = $this->socket->read($readLength); 
     220            $read   += strlen($buffer); 
     221            $body   .= $buffer; 
     222        } 
     223 
     224        return $body; 
    216225    } 
    217226 
  • framework/trunk/src/main/php/net/stubbles/peer/stubSocket.php

    r1763 r1880  
    7474            return true; 
    7575        } 
    76          
     76 
    7777        if (null == $this->host) { 
    7878            return false; 
    7979        } 
    80          
     80 
    8181        $errno    = 0; 
    8282        $errstr   = ''; 
     
    8686            throw new stubConnectionException('Connecting to ' . $this->host . ':' . $this->port . ' within ' . $this->timeout . ' seconds failed: ' . $errstr . ' (' . $errno . ').'); 
    8787        } 
    88              
     88 
    8989        socket_set_timeout($this->fp, $this->timeout); 
    9090        return true; 
     
    107107     * @param  int  $timeout  timeout for connection in seconds 
    108108     */ 
    109     function setTimeout($timeout) 
     109    public function setTimeout($timeout) 
    110110    { 
    111111        $this->timeout = $timeout; 
     
    128128            throw new stubIllegalStateException('Can not read on unconnected socket.'); 
    129129        } 
    130          
     130 
    131131        $data = fgets($this->fp, $length); 
    132132        if (false === $data) { 
     
    161161            throw new stubIllegalStateException('Can not read on unconnected socket.'); 
    162162        } 
    163          
     163 
    164164        $data = fread($this->fp, $length); 
    165165        if (false === $data) { 
     
    183183            throw new stubIllegalStateException('Can not write on unconnected socket.'); 
    184184        } 
    185          
     185 
    186186        $length = fputs($this->fp, $data, strlen($data)); 
    187187        if (false === $length) { 
     
    237237     * @return  bool 
    238238     */ 
    239     function eof() 
     239    public function eof() 
    240240    { 
    241241        if ($this->isConnected() == true) { 
    242242            return feof($this->fp); 
    243243        } 
    244          
     244 
    245245        return true; 
    246246    } 
  • framework/trunk/src/test/php/net/stubbles/peer/http/stubHTTPResponseTestCase.php

    r1870 r1880  
    310310        $this->mockSocket->expects($this->once()) 
    311311                         ->method('read') 
    312                          ->with($this->equalTo(4096)) 
     312                         ->with($this->equalTo(strlen('foobar'))) 
    313313                         ->will($this->returnValue('foobar')); 
    314         $this->assertEquals('foobar', $this->httpResponse->callReadDefault(4096)); 
     314        $this->assertEquals('foobar', $this->httpResponse->callReadDefault(strlen('foobar'))); 
    315315    } 
    316316