| @@ 341-365 (lines=25) @@ | ||
| 338 | * Enable socket events |
|
| 339 | * @return void |
|
| 340 | */ |
|
| 341 | public function enable() |
|
| 342 | { |
|
| 343 | if ($this->enabled) { |
|
| 344 | return; |
|
| 345 | } |
|
| 346 | if (!$this->fd) { |
|
| 347 | return; |
|
| 348 | } |
|
| 349 | $this->enabled = true; |
|
| 350 | if ($this->ev === null) { |
|
| 351 | if ($this->eventLoop === null) { |
|
| 352 | $this->eventLoop = EventLoop::$instance; |
|
| 353 | } |
|
| 354 | $this->ev = $this->eventLoop->listener( |
|
| 355 | [$this, 'onAcceptEv'], |
|
| 356 | null, |
|
| 357 | \EventListener::OPT_CLOSE_ON_FREE | \EventListener::OPT_REUSEABLE, |
|
| 358 | -1, |
|
| 359 | $this->fd |
|
| 360 | ); |
|
| 361 | $this->onBound(); |
|
| 362 | } else { |
|
| 363 | $this->ev->enable(); |
|
| 364 | } |
|
| 365 | } |
|
| 366 | ||
| 367 | /** |
|
| 368 | * @param \EventListener $listener |
|
| @@ 158-180 (lines=23) @@ | ||
| 155 | * Enable socket events |
|
| 156 | * @return void |
|
| 157 | */ |
|
| 158 | public function enable() |
|
| 159 | { |
|
| 160 | if ($this->enabled) { |
|
| 161 | return; |
|
| 162 | } |
|
| 163 | if (!$this->fd) { |
|
| 164 | return; |
|
| 165 | } |
|
| 166 | $this->enabled = true; |
|
| 167 | ||
| 168 | if ($this->ev === null) { |
|
| 169 | if ($this->eventLoop === null) { |
|
| 170 | // @TODO нужно перенести куда-то выше, не годиться тут инициировать |
|
| 171 | $this->eventLoop = EventLoop::$instance; |
|
| 172 | } |
|
| 173 | ||
| 174 | $this->ev = $this->eventLoop->event($this->fd, \Event::READ | \Event::PERSIST, [$this, 'onReadUdp']); |
|
| 175 | $this->onBound(); |
|
| 176 | } else { |
|
| 177 | $this->onAcceptEv(); |
|
| 178 | } |
|
| 179 | $this->ev->add(); |
|
| 180 | } |
|
| 181 | ||
| 182 | /** |
|
| 183 | * Called when we got UDP packet |
|