Return true if this thread is finished
| 558 | |
| 559 | // Return true if this thread is finished |
| 560 | container::impl::dispatch_result container::impl::dispatch(pn_event_t* event) { |
| 561 | |
| 562 | // If we have any pending connection work, do it now |
| 563 | pn_connection_t* c = pn_event_connection(event); |
| 564 | if (c) { |
| 565 | work_queue::impl* queue = connection_context::get(c).work_queue_.impl_.get(); |
| 566 | queue->run_all_jobs(); |
| 567 | } |
| 568 | |
| 569 | // Process events that shouldn't be sent to messaging_handler |
| 570 | switch (pn_event_type(event)) { |
| 571 | |
| 572 | case PN_PROACTOR_INACTIVE: /* listener and all connections closed */ |
| 573 | // If we're stopping interrupt all other threads still running |
| 574 | if (auto_stop_) pn_proactor_interrupt(proactor_); |
| 575 | return ContinueLoop; |
| 576 | |
| 577 | // We only interrupt to stop threads |
| 578 | case PN_PROACTOR_INTERRUPT: { |
| 579 | // Interrupt any other threads still running |
| 580 | GUARD(lock_); |
| 581 | if (threads_>1) pn_proactor_interrupt(proactor_); |
| 582 | return EndLoop; |
| 583 | } |
| 584 | |
| 585 | case PN_PROACTOR_TIMEOUT: { |
| 586 | // Can get an immediate timeout, if we have a container event loop inject |
| 587 | run_timer_jobs(); |
| 588 | |
| 589 | // Run every container event loop job |
| 590 | // This is not at all efficient and single threads all these jobs, but it does correctly |
| 591 | // serialise them |
| 592 | work_queues queues; |
| 593 | { |
| 594 | GUARD(work_queues_lock_); |
| 595 | queues = work_queues_; |
| 596 | } |
| 597 | for (work_queues::iterator queue = queues.begin(); queue!=queues.end(); ++queue) { |
| 598 | (*queue)->run_all_jobs(); |
| 599 | } |
| 600 | return EndBatch; |
| 601 | } |
| 602 | case PN_LISTENER_OPEN: { |
| 603 | pn_listener_t* l = pn_event_listener(event); |
| 604 | proton::listen_handler* handler; |
| 605 | { |
| 606 | GUARD(lock_); |
| 607 | listener_context &lc(listener_context::get(l)); |
| 608 | handler = lc.listen_handler_; |
| 609 | } |
| 610 | if (handler) { |
| 611 | listener lstnr(l); |
| 612 | handler->on_open(lstnr); |
| 613 | } |
| 614 | return ContinueLoop; |
| 615 | } |
| 616 | case PN_LISTENER_ACCEPT: { |
| 617 | pn_listener_t* l = pn_event_listener(event); |
nothing calls this directly
no test coverage detected