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
Afficher le fichier Open project: kakserpom/phpdaemon Class Usage Examples

Méthodes publiques

Свойство Type Description
$pool Associated pool

Protected Properties

Свойство 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?

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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

__get() public méthode

Getter
public __get ( string $name ) : mixed
$name string Name
Résultat mixed

close() public méthode

Close the connection
public close ( ) : void
Résultat void

drain() public méthode

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

drainIfMatch() public méthode

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

finish() public méthode

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

freezeInput() public méthode

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
Résultat boolean Success

freezeOutput() public méthode

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
Résultat boolean Success

getBev() public méthode

Get EventBufferEvent
public getBev ( ) : EventBufferEvent
Résultat EventBufferEvent

getFd() public méthode

Get file descriptor
public getFd ( ) : resource
Résultat resource File descriptor

getInputLength() public méthode

Returns length of input buffer
public getInputLength ( ) : integer
Résultat integer

gracefulShutdown() public méthode

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

init() protected méthode

Constructor
protected init ( ) : void
Résultat void

isFinished() public méthode

Finished?
public isFinished ( ) : boolean
Résultat boolean

isFreed() public méthode

Freed?
public isFreed ( ) : boolean
Résultat boolean

log() protected méthode

Send message to log
protected log ( string $m ) : void
$m string Message
Résultat void

look() public méthode

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

lookExact() public méthode

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
Résultat string | false

moveToBuffer() public méthode

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
Résultat integer | false

onFinish() protected méthode

Called when the session finished
protected onFinish ( ) : void
Résultat void

onRead() protected méthode

Called when new data received
protected onRead ( ) : void
Résultat void

onReadEv() public méthode

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

onReady() protected méthode

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

onStateEv() public méthode

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

onWrite() public méthode

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

onWriteEv() public méthode

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

onWriteOnce() public méthode

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

prependInput() public méthode

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

prependOutput() public méthode

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

read() public méthode

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

readExact() public méthode

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

readLine() public méthode

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

readUnlimited() public méthode

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

setContext() public méthode

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

setFd() public méthode

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

setPriority() public méthode

Sets priority
public setPriority ( integer $p ) : void
$p integer Priority
Résultat void

setTimeout() public méthode

Set timeout
public setTimeout ( integer $rw ) : void
$rw integer Timeout
Résultat void

setTimeouts() public méthode

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

setWatermark() public méthode

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

substr() public méthode

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

unfreezeInput() public méthode

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
Résultat boolean Success

unfreezeOutput() public méthode

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
Résultat boolean Success

unsetFd() public méthode

Unsets pointers of associated EventBufferEvent and File descriptr
public unsetFd ( ) : void
Résultat void

write() public méthode

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
Résultat boolean Success

writeFromBuffer() public méthode

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
Résultat integer | false

writeln() public méthode

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
Résultat 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