| @@ 95-115 (lines=21) @@ | ||
| 92 | * Called when new data received. |
|
| 93 | * @return void |
|
| 94 | */ |
|
| 95 | public function onRead() |
|
| 96 | { |
|
| 97 | start: |
|
| 98 | if ($this->state === self::STATE_ROOT) { |
|
| 99 | if (false === ($r = $this->readExact(4))) { |
|
| 100 | return; // not ready yet |
|
| 101 | } |
|
| 102 | $u = unpack('N', $r); |
|
| 103 | $this->packetLength = $u[1]; |
|
| 104 | $this->state = self::STATE_CONTENT; |
|
| 105 | } |
|
| 106 | if ($this->state === self::STATE_CONTENT) { |
|
| 107 | if (false === ($packet = $this->readExact($this->packetLength))) { |
|
| 108 | $this->setWatermark($this->packetLength, $this->packetLength); |
|
| 109 | return; // not ready yet |
|
| 110 | } |
|
| 111 | $this->setWatermark(4, 0xFFFF); |
|
| 112 | $this->state = self::STATE_ROOT; |
|
| 113 | $this->onPacket(\igbinary_unserialize($packet)); |
|
| 114 | } |
|
| 115 | goto start; |
|
| 116 | } |
|
| 117 | } |
|
| 118 | ||
| @@ 49-69 (lines=21) @@ | ||
| 46 | * Called when new data received. |
|
| 47 | * @return void |
|
| 48 | */ |
|
| 49 | public function onRead() |
|
| 50 | { |
|
| 51 | start: |
|
| 52 | if ($this->state === self::STATE_ROOT) { |
|
| 53 | if (false === ($r = $this->readExact(4))) { |
|
| 54 | return; // not ready yet |
|
| 55 | } |
|
| 56 | $u = unpack('N', $r); |
|
| 57 | $this->packetLength = $u[1]; |
|
| 58 | $this->state = self::STATE_CONTENT; |
|
| 59 | } |
|
| 60 | if ($this->state === self::STATE_CONTENT) { |
|
| 61 | if (false === ($packet = $this->readExact($this->packetLength))) { |
|
| 62 | $this->setWatermark($this->packetLength, $this->packetLength); |
|
| 63 | return; // not ready yet |
|
| 64 | } |
|
| 65 | $this->setWatermark(4, 0xFFFF); |
|
| 66 | $this->state = self::STATE_ROOT; |
|
| 67 | $this->onPacket(igbinary_unserialize($packet)); |
|
| 68 | } |
|
| 69 | goto start; |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|