| @@ 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 |
|
| @@ 138-151 (lines=14) @@ | ||
| 135 | * @callback $cb ( ) |
|
| 136 | * @return void |
|
| 137 | */ |
|
| 138 | public function onConnected($cb) |
|
| 139 | { |
|
| 140 | if ($this->state === self::STATE_AUTH_ERROR) { |
|
| 141 | $cb($this, false); |
|
| 142 | } elseif ($this->state === self::STATE_AUTH_OK) { |
|
| 143 | $cb($this, true); |
|
| 144 | } else { |
|
| 145 | if (!$this->onConnected) { |
|
| 146 | $this->onConnected = new StackCallbacks(); |
|
| 147 | } |
|
| 148 | $this->onConnected->push($cb); |
|
| 149 | } |
|
| 150 | } |
|
| 151 | ||
| 152 | /** |
|
| 153 | * Converts binary string to integer |
|
| 154 | * @param string $str Binary string |
|
| @@ 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 |
|