PHP Class Workerman\Connection\TcpConnection

Inheritance: extends Workerman\Connection\ConnectionInterface
Show file Open project: walkor/workerman Class Usage Examples

Public Properties

Property Type Description
$defaultMaxSendBufferSize integer Default send buffer size.
$id integer Connection->id.
$maxPackageSize integer Maximum acceptable packet size.
$maxSendBufferSize integer OnBufferFull callback will be emited When the send buffer is full.
$onBufferDrain callback Emitted when the send buffer becomes empty.
$onBufferFull callback Emitted when the send buffer becomes full.
$onClose callback Emitted when the other end of the socket sends a FIN packet.
$onError callback Emitted when an error occurs with connection.
$onMessage callback Emitted when data is received.
$protocol Workerman\Protocols\ProtocolInterface The format is like this Workerman\\Protocols\\Http.
$worker Workerman\Worker Which worker belong to.

Protected Properties

Property Type Description
$_currentPackageLength integer Current package length.
$_id integer A copy of $worker->id which used to clean up the connection in worker->connections
$_idRecorder integer Id recorder.
$_isPaused boolean Is paused.
$_recvBuffer string Receive buffer.
$_remoteAddress string Remote address.
$_sendBuffer string Send buffer.
$_socket resource Socket
$_status integer Connection status.

Public Methods

Method Description
__construct ( resource $socket, string $remote_address = '' ) Construct.
__destruct ( ) : void Destruct.
baseRead ( resource $socket, boolean $check_eof = true ) : void Base read handler.
baseWrite ( ) : void | boolean Base write handler.
close ( mixed $data = null, boolean $raw = false ) : void Close connection.
consumeRecvBuffer ( integer $length ) : void Remove $length of data from receive buffer.
destroy ( ) : void Destroy connection.
getRemoteIp ( ) : string Get remote IP.
getRemotePort ( ) : integer Get remote port.
getSocket ( ) : resource Get the real socket.
pauseRecv ( ) : void Pauses the reading of data. That is onMessage will not be emitted. Useful to throttle back an upload.
pipe ( TcpConnection $dest ) : void This method pulls all the data out of a readable stream, and writes it to the supplied destination.
resumeRecv ( ) : void Resumes reading after a call to pauseRecv.
send ( string $send_buffer, boolean $raw = false ) : void | boolean | null Sends data on the connection.

Protected Methods

Method Description
bufferIsFull ( ) : boolean Whether send buffer is full.
checkBufferWillFull ( ) : void Check whether the send buffer will be full.

Method Details

__construct() public method

Construct.
public __construct ( resource $socket, string $remote_address = '' )
$socket resource
$remote_address string

__destruct() public method

Destruct.
public __destruct ( ) : void
return void

baseRead() public method

Base read handler.
public baseRead ( resource $socket, boolean $check_eof = true ) : void
$socket resource
$check_eof boolean
return void

baseWrite() public method

Base write handler.
public baseWrite ( ) : void | boolean
return void | boolean

bufferIsFull() protected method

Whether send buffer is full.
protected bufferIsFull ( ) : boolean
return boolean

checkBufferWillFull() protected method

Check whether the send buffer will be full.
protected checkBufferWillFull ( ) : void
return void

close() public method

Close connection.
public close ( mixed $data = null, boolean $raw = false ) : void
$data mixed
$raw boolean
return void

consumeRecvBuffer() public method

Remove $length of data from receive buffer.
public consumeRecvBuffer ( integer $length ) : void
$length integer
return void

destroy() public method

Destroy connection.
public destroy ( ) : void
return void

getRemoteIp() public method

Get remote IP.
public getRemoteIp ( ) : string
return string

getRemotePort() public method

Get remote port.
public getRemotePort ( ) : integer
return integer

getSocket() public method

Get the real socket.
public getSocket ( ) : resource
return resource

pauseRecv() public method

Pauses the reading of data. That is onMessage will not be emitted. Useful to throttle back an upload.
public pauseRecv ( ) : void
return void

pipe() public method

This method pulls all the data out of a readable stream, and writes it to the supplied destination.
public pipe ( TcpConnection $dest ) : void
$dest TcpConnection
return void

resumeRecv() public method

Resumes reading after a call to pauseRecv.
public resumeRecv ( ) : void
return void

send() public method

Sends data on the connection.
public send ( string $send_buffer, boolean $raw = false ) : void | boolean | null
$send_buffer string
$raw boolean
return void | boolean | null

Property Details

$_currentPackageLength protected property

Current package length.
protected int $_currentPackageLength
return integer

$_id protected property

A copy of $worker->id which used to clean up the connection in worker->connections
protected int $_id
return integer

$_idRecorder protected static property

Id recorder.
protected static int $_idRecorder
return integer

$_isPaused protected property

Is paused.
protected bool $_isPaused
return boolean

$_recvBuffer protected property

Receive buffer.
protected string $_recvBuffer
return string

$_remoteAddress protected property

Remote address.
protected string $_remoteAddress
return string

$_sendBuffer protected property

Send buffer.
protected string $_sendBuffer
return string

$_socket protected property

Socket
protected resource $_socket
return resource

$_status protected property

Connection status.
protected int $_status
return integer

$defaultMaxSendBufferSize public static property

Default send buffer size.
public static int $defaultMaxSendBufferSize
return integer

$id public property

Connection->id.
public int $id
return integer

$maxPackageSize public static property

Maximum acceptable packet size.
public static int $maxPackageSize
return integer

$maxSendBufferSize public property

OnBufferFull callback will be emited When the send buffer is full.
public int $maxSendBufferSize
return integer

$onBufferDrain public property

Emitted when the send buffer becomes empty.
public callback $onBufferDrain
return callback

$onBufferFull public property

Emitted when the send buffer becomes full.
public callback $onBufferFull
return callback

$onClose public property

Emitted when the other end of the socket sends a FIN packet.
public callback $onClose
return callback

$onError public property

Emitted when an error occurs with connection.
public callback $onError
return callback

$onMessage public property

Emitted when data is received.
public callback $onMessage
return callback

$protocol public property

The format is like this Workerman\\Protocols\\Http.
public ProtocolInterface,Workerman\Protocols $protocol
return Workerman\Protocols\ProtocolInterface

$worker public property

Which worker belong to.
public Worker,Workerman $worker
return Workerman\Worker