| @@ 198-211 (lines=14) @@ | ||
| 195 | * @callback $cb ( Connection $conn, boolean $success ) |
|
| 196 | * @return void |
|
| 197 | */ |
|
| 198 | public function onConnected($cb) |
|
| 199 | { |
|
| 200 | if ($this->phase === self::PHASE_AUTH_ERR) { |
|
| 201 | $cb($this, false); |
|
| 202 | } elseif ($this->phase === self::PHASE_HANDSHAKED) { |
|
| 203 | $cb($this, true); |
|
| 204 | } else { |
|
| 205 | if (!$this->onConnected) { |
|
| 206 | $this->onConnected = new StackCallbacks(); |
|
| 207 | } |
|
| 208 | $this->onConnected->push($cb); |
|
| 209 | } |
|
| 210 | } |
|
| 211 | ||
| 212 | /** |
|
| 213 | * Called when the connection is handshaked (at low-level), and peer is ready to recv. data |
|
| 214 | * @return void |
|
| @@ 127-141 (lines=15) @@ | ||
| 124 | * @param callable Callback |
|
| 125 | * @return void |
|
| 126 | */ |
|
| 127 | public function onConnected($cb) |
|
| 128 | { |
|
| 129 | if ($this->state === self::CONN_STATE_HANDSHAKED_ERROR) { |
|
| 130 | $cb($this); |
|
| 131 | } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) { |
|
| 132 | $cb($this); |
|
| 133 | } else { |
|
| 134 | if (!$this->onConnected) { |
|
| 135 | $this->onConnected = new StackCallbacks(); |
|
| 136 | } |
|
| 137 | ||
| 138 | $this->onConnected->push($cb); |
|
| 139 | } |
|
| 140 | } |
|
| 141 | ||
| 142 | /** |
|
| 143 | * Called when the connection is handshaked (at low-level), and peer is ready to recv. data |
|
| 144 | * @return void |
|
| @@ 160-173 (lines=14) @@ | ||
| 157 | * @callback $cb ( ) |
|
| 158 | * @return void |
|
| 159 | */ |
|
| 160 | public function onConnected($cb) |
|
| 161 | { |
|
| 162 | if ($this->state === self::STATE_AUTH_ERROR) { |
|
| 163 | $cb($this, false); |
|
| 164 | } elseif ($this->state === self::STATE_AUTH_OK) { |
|
| 165 | $cb($this, true); |
|
| 166 | } else { |
|
| 167 | if (!$this->onConnected) { |
|
| 168 | $this->onConnected = new StackCallbacks(); |
|
| 169 | } |
|
| 170 | $this->onConnected->push($cb); |
|
| 171 | } |
|
| 172 | } |
|
| 173 | ||
| 174 | /** |
|
| 175 | * Converts binary string to integer |
|
| 176 | * @param string $str Binary string |
|