PHP Class PHPDaemon\Network\IOStream

Author: Vasily Zorin ([email protected])
Inheritance: use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog, use trait PHPDaemon\Traits\EventHandlers, use trait PHPDaemon\Traits\EventLoopContainer
ファイルを表示 Open project: kakserpom/phpdaemon Class Usage Examples

Public Properties

Property Type Description
$pool Associated pool

Protected Properties

Property Type Description
$EOL EOL
$EOLS EOLS_* switch
$alive Alive?
$bev EventBufferEvent
$bevConnect Is bevConnect used?
$ctx Context
$ctxMode Defines context-related flag
$ctxname Context name
$fd File descriptor
$finished Finished?
$freed Freed?
$highMark Default high mark. Maximum number of bytes in buffer
$inited Initialized?
$lowMark Default low mark. Minimum number of bytes in buffer
$onWriteOnce Stack of callbacks called when writing is done
$priority Priority
$ready Ready?
$ssl SSL?
$state Current state
$timedout Timeout?
$timeout Timeout
$timeoutRead Read timeout
$timeoutWrite Write timeout
$url URL
$wRead Should we can onReadEv() in next onWriteEv()?
$writing Writing?

Public Methods

Method Description
__construct ( resource $fd = null, object $pool = null ) IOStream constructor
__get ( string $name ) : mixed Getter
close ( ) : void Close the connection
drain ( integer $n ) : boolean Drains buffer
drainIfMatch ( string $str ) : boolean | null Drains buffer it matches the string
finish ( ) : void Finish the session. You should not worry about buffers, they are going to be flushed properly
freezeInput ( boolean $at_front = true ) : boolean Freeze input
freezeOutput ( boolean $at_front = true ) : boolean Freeze output
getBev ( ) : EventBufferEvent Get EventBufferEvent
getFd ( ) : resource Get file descriptor
getInputLength ( ) : integer Returns length of input buffer
gracefulShutdown ( ) : boolean Called when the worker is going to shutdown
isFinished ( ) : boolean Finished?
isFreed ( ) : boolean Freed?
look ( integer $n, integer $o ) : string | false Read from buffer without draining
lookExact ( integer $n, integer $o ) : string | false Reads exact $n bytes of buffer without draining
moveToBuffer ( EventBuffer $dest, integer $n ) : integer | false Moves arbitrary number of bytes from input buffer to given buffer
onReadEv ( object $bev ) : void Called when the connection has got new data
onStateEv ( object $bev, integer $events ) : void Called when the connection state changed
onWrite ( ) : void Called when the connection is ready to accept new data
onWriteEv ( object $bev ) : void Called when the connection is ready to accept new data
onWriteOnce ( callable $cb ) : void Push callback which will be called only once, when writing is available next time
prependInput ( string $str ) : boolean Prepends data to input buffer
prependOutput ( string $str ) : boolean Prepends data to output buffer
read ( integer $n ) : string | false Read data from the connection's buffer
readExact ( integer $n ) : string | false Reads exact $n bytes from buffer
readLine ( integer $eol = null ) : string | null Reads line from buffer
readUnlimited ( ) : string Reads all data from the connection's buffer
search ( string $what, integer $start, integer $end ) : integer Searches first occurence of the string in input buffer
setContext ( object $ctx, integer $mode ) : void Sets context mode
setFd ( resource $fd, object $bev = null ) : void Sets fd
setPriority ( integer $p ) : void Sets priority
setTimeout ( integer $rw ) : void Set timeout
setTimeouts ( integer $read, integer $write ) : void Set timeouts
setWatermark ( integer | null $low = null, integer | null $high = null ) : void Sets watermark
substr ( integer $o, integer $n ) : string | false Read from buffer without draining
unfreezeInput ( boolean $at_front = true ) : boolean Unfreeze input
unfreezeOutput ( boolean $at_front = true ) : boolean Unfreeze output
unsetFd ( ) : void Unsets pointers of associated EventBufferEvent and File descriptr
write ( string $data ) : boolean Send data to the connection. Note that it just writes to buffer that flushes at every baseloop
writeFromBuffer ( EventBuffer $src, integer $n ) : integer | false Moves arbitrary number of bytes from given buffer to output buffer
writeln ( string $data ) : boolean Send data and appending \n to connection. Note that it just writes to buffer flushed at every baseloop

Protected Methods

Method Description
init ( ) : void Constructor
log ( string $m ) : void Send message to log
onFinish ( ) : void Called when the session finished
onRead ( ) : void Called when new data received
onReady ( ) : void Called when the stream is handshaked (at low-level), and peer is ready to recv. data

Method Details

__construct() public method

IOStream constructor
public __construct ( resource $fd = null, object $pool = null )
$fd resource File descriptor. Optional
$pool object Pool. Optional

__get() public method

Getter
public __get ( string $name ) : mixed
$name string Name
return mixed

close() public method

Close the connection
public close ( ) : void
return void

drain() public method

Drains buffer
public drain ( integer $n ) : boolean
$n integer Numbers of bytes to drain
return boolean Success

drainIfMatch() public method

Drains buffer it matches the string
public drainIfMatch ( string $str ) : boolean | null
$str string Data
return boolean | null Success

finish() public method

Finish the session. You should not worry about buffers, they are going to be flushed properly
public finish ( ) : void
return void

freezeInput() public method

Freeze input
public freezeInput ( boolean $at_front = true ) : boolean
$at_front boolean At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen
return boolean Success

freezeOutput() public method

Freeze output
public freezeOutput ( boolean $at_front = true ) : boolean
$at_front boolean At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen
return boolean Success

getBev() public method

Get EventBufferEvent
public getBev ( ) : EventBufferEvent
return EventBufferEvent

getFd() public method

Get file descriptor
public getFd ( ) : resource
return resource File descriptor

getInputLength() public method

Returns length of input buffer
public getInputLength ( ) : integer
return integer

gracefulShutdown() public method

Called when the worker is going to shutdown
public gracefulShutdown ( ) : boolean
return boolean Ready to shutdown?

init() protected method

Constructor
protected init ( ) : void
return void

isFinished() public method

Finished?
public isFinished ( ) : boolean
return boolean

isFreed() public method

Freed?
public isFreed ( ) : boolean
return boolean

log() protected method

Send message to log
protected log ( string $m ) : void
$m string Message
return void

look() public method

Read from buffer without draining
public look ( integer $n, integer $o ) : string | false
$n integer Number of bytes to read
$o integer Offset
return string | false

lookExact() public method

Reads exact $n bytes of buffer without draining
public lookExact ( integer $n, integer $o ) : string | false
$n integer Number of bytes to read
$o integer Offset
return string | false

moveToBuffer() public method

Moves arbitrary number of bytes from input buffer to given buffer
public moveToBuffer ( EventBuffer $dest, integer $n ) : integer | false
$dest EventBuffer Destination nuffer
$n integer Max. number of bytes to move
return integer | false

onFinish() protected method

Called when the session finished
protected onFinish ( ) : void
return void

onRead() protected method

Called when new data received
protected onRead ( ) : void
return void

onReadEv() public method

Called when the connection has got new data
public onReadEv ( object $bev ) : void
$bev object EventBufferEvent
return void

onReady() protected method

Called when the stream is handshaked (at low-level), and peer is ready to recv. data
protected onReady ( ) : void
return void

onStateEv() public method

Called when the connection state changed
public onStateEv ( object $bev, integer $events ) : void
$bev object EventBufferEvent
$events integer Events
return void

onWrite() public method

Called when the connection is ready to accept new data
public onWrite ( ) : void
return void

onWriteEv() public method

Called when the connection is ready to accept new data
public onWriteEv ( object $bev ) : void
$bev object EventBufferEvent
return void

onWriteOnce() public method

Push callback which will be called only once, when writing is available next time
public onWriteOnce ( callable $cb ) : void
$cb callable Callback
return void

prependInput() public method

Prepends data to input buffer
public prependInput ( string $str ) : boolean
$str string Data
return boolean Success

prependOutput() public method

Prepends data to output buffer
public prependOutput ( string $str ) : boolean
$str string Data
return boolean Success

read() public method

Read data from the connection's buffer
public read ( integer $n ) : string | false
$n integer Max. number of bytes to read
return string | false Readed data

readExact() public method

Reads exact $n bytes from buffer
public readExact ( integer $n ) : string | false
$n integer Number of bytes to read
return string | false

readLine() public method

Reads line from buffer
public readLine ( integer $eol = null ) : string | null
$eol integer EOLS_*
return string | null

readUnlimited() public method

Reads all data from the connection's buffer
public readUnlimited ( ) : string
return string Readed data

setContext() public method

Sets context mode
public setContext ( object $ctx, integer $mode ) : void
$ctx object Context
$mode integer Mode
return void

setFd() public method

Sets fd
public setFd ( resource $fd, object $bev = null ) : void
$fd resource File descriptor
$bev object EventBufferEvent
return void

setPriority() public method

Sets priority
public setPriority ( integer $p ) : void
$p integer Priority
return void

setTimeout() public method

Set timeout
public setTimeout ( integer $rw ) : void
$rw integer Timeout
return void

setTimeouts() public method

Set timeouts
public setTimeouts ( integer $read, integer $write ) : void
$read integer Read timeout in seconds
$write integer Write timeout in seconds
return void

setWatermark() public method

Sets watermark
public setWatermark ( integer | null $low = null, integer | null $high = null ) : void
$low integer | null Low
$high integer | null High
return void

substr() public method

Read from buffer without draining
public substr ( integer $o, integer $n ) : string | false
$o integer Offset
$n integer Number of bytes to read
return string | false

unfreezeInput() public method

Unfreeze input
public unfreezeInput ( boolean $at_front = true ) : boolean
$at_front boolean At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen
return boolean Success

unfreezeOutput() public method

Unfreeze output
public unfreezeOutput ( boolean $at_front = true ) : boolean
$at_front boolean At front. Default is true. If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen
return boolean Success

unsetFd() public method

Unsets pointers of associated EventBufferEvent and File descriptr
public unsetFd ( ) : void
return void

write() public method

Send data to the connection. Note that it just writes to buffer that flushes at every baseloop
public write ( string $data ) : boolean
$data string Data to send
return boolean Success

writeFromBuffer() public method

Moves arbitrary number of bytes from given buffer to output buffer
public writeFromBuffer ( EventBuffer $src, integer $n ) : integer | false
$src EventBuffer Source buffer
$n integer Max. number of bytes to move
return integer | false

writeln() public method

Send data and appending \n to connection. Note that it just writes to buffer flushed at every baseloop
public writeln ( string $data ) : boolean
$data string Data to send
return boolean Success

Property Details

$EOL protected_oe property

EOL
protected $EOL

$EOLS protected_oe property

EOLS_* switch
protected $EOLS

$alive protected_oe property

Alive?
protected $alive

$bev protected_oe property

EventBufferEvent
protected $bev

$bevConnect protected_oe property

Is bevConnect used?
protected $bevConnect

$ctx protected_oe property

Context
protected $ctx

$ctxMode protected_oe property

Defines context-related flag
protected $ctxMode

$ctxname protected_oe property

Context name
protected $ctxname

$fd protected_oe property

File descriptor
protected $fd

$finished protected_oe property

Finished?
protected $finished

$freed protected_oe property

Freed?
protected $freed

$highMark protected_oe property

Default high mark. Maximum number of bytes in buffer
protected $highMark

$inited protected_oe property

Initialized?
protected $inited

$lowMark protected_oe property

Default low mark. Minimum number of bytes in buffer
protected $lowMark

$onWriteOnce protected_oe property

Stack of callbacks called when writing is done
protected $onWriteOnce

$pool public_oe property

Associated pool
public $pool

$priority protected_oe property

Priority
protected $priority

$ready protected_oe property

Ready?
protected $ready

$ssl protected_oe property

SSL?
protected $ssl

$state protected_oe property

Current state
protected $state

$timedout protected_oe property

Timeout?
protected $timedout

$timeout protected_oe property

Timeout
protected $timeout

$timeoutRead protected_oe property

Read timeout
protected $timeoutRead

$timeoutWrite protected_oe property

Write timeout
protected $timeoutWrite

$url protected_oe property

URL
protected $url

$wRead protected_oe property

Should we can onReadEv() in next onWriteEv()?
protected $wRead

$writing protected_oe property

Writing?
protected $writing