TYPO3  7.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
HTTP_Request2_SocketWrapper Class Reference
Inheritance diagram for HTTP_Request2_SocketWrapper:
HTTP_Request2_SOCKS5

Public Member Functions

 __construct ($address, $timeout, array $contextOptions=array())
 
 __destruct ()
 
 read ($length)
 
 readLine ($bufferSize, $localTimeout=null)
 
 write ($data)
 
 eof ()
 
 setDeadline ($deadline, $timeout)
 
 enableCrypto ()
 

Protected Member Functions

 checkTimeout ()
 
 connectionWarningsHandler ($errno, $errstr)
 

Protected Attributes

 $connectionWarnings = array()
 
 $socket
 
 $deadline
 
 $timeout
 

Detailed Description

Definition at line 39 of file SocketWrapper.php.

Constructor & Destructor Documentation

__construct (   $address,
  $timeout,
array  $contextOptions = array() 
)

Class constructor, tries to establish connection

Parameters
string$addressAddress for stream_socket_client() call, e.g. 'tcp://localhost:80'
int$timeoutConnection timeout (seconds)
array$contextOptionsContext options
Exceptions
HTTP_Request2_LogicException
HTTP_Request2_ConnectionException

Definition at line 76 of file SocketWrapper.php.

References $timeout.

__destruct ( )

Destructor, disconnects socket

Definition at line 117 of file SocketWrapper.php.

Member Function Documentation

checkTimeout ( )
protected

Throws an Exception if stream timed out

Exceptions
HTTP_Request2_MessageException

Definition at line 264 of file SocketWrapper.php.

References HTTP_Request2_Exception\TIMEOUT.

Referenced by read(), readLine(), and write().

connectionWarningsHandler (   $errno,
  $errstr 
)
protected

Error handler to use during stream_socket_client() call

One stream_socket_client() call may produce multiple PHP warnings (especially OpenSSL-related), we keep them in an array to later use for the message of HTTP_Request2_ConnectionException

Parameters
int$errnoerror level
string$errstrerror message
Returns
bool

Definition at line 289 of file SocketWrapper.php.

enableCrypto ( )

Turns on encryption on a socket

Exceptions
HTTP_Request2_ConnectionException

Definition at line 240 of file SocketWrapper.php.

eof ( )

Tests for end-of-file on a socket

Returns
bool

Definition at line 216 of file SocketWrapper.php.

read (   $length)

Wrapper around fread(), handles global request timeout

Parameters
int$lengthReads up to this number of bytes
Returns
string Data read from socket
Exceptions
HTTP_Request2_MessageExceptionIn case of timeout

Definition at line 130 of file SocketWrapper.php.

References checkTimeout().

Referenced by HTTP_Request2_SOCKS5\__construct(), HTTP_Request2_SOCKS5\connect(), and HTTP_Request2_SOCKS5\performAuthentication().

readLine (   $bufferSize,
  $localTimeout = null 
)

Reads until either the end of the socket or a newline, whichever comes first

Strips the trailing newline from the returned data, handles global request timeout. Method idea borrowed from Net_Socket PEAR package.

Parameters
int$bufferSizebuffer size to use for reading
int$localTimeouttimeout value to use just for this call (used when waiting for "100 Continue" response)
Returns
string Available data up to the newline (not including newline)
Exceptions
HTTP_Request2_MessageExceptionIn case of timeout

Definition at line 153 of file SocketWrapper.php.

References checkTimeout(), elseif, and HTTP_Request2_Exception\TIMEOUT.

setDeadline (   $deadline,
  $timeout 
)

Sets request deadline

Parameters
int$deadlineException will be thrown if request continues past this time
int$timeoutOriginal request timeout value, to use in Exception message

Definition at line 229 of file SocketWrapper.php.

References $deadline, and $timeout.

Referenced by HTTP_Request2_Adapter_Socket\connect().

write (   $data)

Wrapper around fwrite(), handles global request timeout

Parameters
string$dataString to be written
Returns
int
Exceptions
HTTP_Request2_MessageException

Definition at line 197 of file SocketWrapper.php.

References checkTimeout().

Referenced by HTTP_Request2_SOCKS5\__construct(), HTTP_Request2_SOCKS5\connect(), and HTTP_Request2_SOCKS5\performAuthentication().

Member Data Documentation

$connectionWarnings = array()
protected

Definition at line 45 of file SocketWrapper.php.

$deadline
protected

Definition at line 57 of file SocketWrapper.php.

Referenced by setDeadline().

$socket
protected

Definition at line 51 of file SocketWrapper.php.

$timeout
protected

Definition at line 63 of file SocketWrapper.php.

Referenced by HTTP_Request2_SOCKS5\__construct(), __construct(), and setDeadline().