Thanks, Rafael!

07.05.2015 16:47, Rafael Schloming пишет:
> That looks mostly correct to me. I've made a few notes inline...
> 
> On Thu, May 7, 2015 at 9:27 AM, Michael Ivanov <iv...@logit-ag.de> wrote:
> 
>> Hallo,
>>
>> I am trying to integrate proton messenger with a regular select-based
>> event loop.
>> Regrettably there's not much documentation about reading and sendingn
>> messages
>> in passive mode using selectors. Can you give a quick look to the
>> pseudo-code,
>> describing message input in my event loop and verify whether I understand
>> it
>> correctly?
>>
>> Here goes the pseudo-code:
>>
>> for (;;) {
>>    foreach messenger:
>>       messenger::recv(N);                // Make sure message read
>> automata is started.
>>       foreach selectable in messenger:
>>          if (is_registered(selectable))
>>             continue;                    // Selectable is already in use
>> by event loop
>>       // Create an I/O object which refers to selectable
>>       // and add it to the I/O list
>>          iolist << new IO(selectable)
>>
>>    foreach iolist item:
>>       if is_terminal(item):
>>          Remove item from iolist
>>          pn_selectable_free(item::selectable)
>>          continue;
>>       if is_readable:
>>          add selection fd to read mask
>>       if is_writable:
>>          add selection fd to write mask
>>       if (selection has deadline)
>>          schedule timer for this iolist item
>>
>>    select(read_mask, write_mask, timeout)
>>
>>    foreach iolist item:
>>       if (read event signalled)
>>          pn_selectable_readable(item::selection)
>>       if (write event signalled)
>>          pn_selectable_writable(item::selection)
>>
> 
> You also want to do if (deadline for selectable expired)
> pn_selectable_expired(item::selection) here.
> 
> 
>>
>>    If we had any read events check whether some messages
>>    were placed into input queue. If no messages are available
>>    pn_messenger_get() will not block, but rather will return
>>    PN_EOS
>>
>>       foreach messenger:
>>          while pn_messenger_get(messenger, message) != PN_EOS
>>             Handle input message
>>
>>    Check whether some timers have expired. If expired timer
>>    refers to the proton I/O object, delete this object
>>    (this will also exclude it from iolist and select masks)
>>
> 
> This isn't quite right. The timer expiring doesn't mean you should throw
> out the selectable, it simply means you should signal the timing event
> using the call to pn_selectable_expired as described above.
> 
> 
>>
>> }
>>
>> All messengers are created in non-blocking and passive mode.
>>
>> Some of the messengers are already subscribed to queues.
>>
>> To send messages I just use pn_messenger_put as usual and
>> pn_selectable_writable takes care about actual message delivery.
>>
> 
> 
> Other than the notes above, I believe this is correct.
> 
> --Rafael
> 


-- 
 \   / |                                   |
 (OvO) |  Михаил Иванов                    |
 (^^^) |      Тел.:    +7(911) 223-1300    |
  \^/  |      E-mail:  iv...@isle.spb.ru   |
  ^ ^  |                                   |

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to