[boost::asio]Question about how to properly make several async requests (reads and writes)
Dear list, I have learned that one cannot make several async write requests, one after another, without waiting for the completion of each request, otherwise the bytes get merged and the messages will not make sense at the receiving side. I am correct assuming that, right? My doubt is if the same happens to async read requests. Does one have to wait a read request completes before issuing another? Will the bytes get merged too, if one does not wait before making another read request? Assuming things happen that way, one async request waiting for the completion of another earlier request, then one have serial I/O processing and if one wants to have things done in parallel, the simplest way would be having other(s) thread(s) reading and writting in the same I/O object. Is this correct? I hope I have made my doubts clear enough, and if it is not clear please say it and i will try to be more objective. Regards, -- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
2009/9/4 Matheus Araújo Aguiar
Dear list,
I have learned that one cannot make several async write requests, one after another, without waiting for the completion of each request, otherwise the bytes get merged and the messages will not make sense at the receiving side. I am correct assuming that, right? My doubt is if the same happens to async read requests. Does one have to wait a read request completes before issuing another? Will the bytes get merged too, if one does not wait before making another read request?
Assuming things happen that way, one async request waiting for the completion of another earlier request, then one have serial I/O processing and if one wants to have things done in parallel, the simplest way would be having other(s) thread(s) reading and writting in the same I/O object. Is this correct?
I hope I have made my doubts clear enough, and if it is not clear please say it and i will try to be more objective.
See http://article.gmane.org/gmane.comp.lib.boost.user/50424 Regards.
Thanx Robert, although in the link you send me i could not find the follow
up, googling the mail subject easily returned me the complete mail exchange
(two e-mails from the same guy). In those, he finds out that the callbacks
might be called in an order different from the order of the requests made,
hence data could get merged.
However, i feel that doesn't answer the question about the writes, since
callbacks are called after the bytes are sent, so this 'out-of-order
callback calls' will not have impact on the data sent. Or am i mistaken, and
actually the async writes could be executed out of order and/or at the same
time?
Thanks again and best wishes,
On Fri, Sep 4, 2009 at 10:36 AM, Robert Jones
2009/9/4 Matheus Araújo Aguiar
Dear list,
I have learned that one cannot make several async write requests, one after another, without waiting for the completion of each request, otherwise the bytes get merged and the messages will not make sense at the receiving side. I am correct assuming that, right? My doubt is if the same happens to async read requests. Does one have to wait a read request completes before issuing another? Will the bytes get merged too, if one does not wait before making another read request?
Assuming things happen that way, one async request waiting for the completion of another earlier request, then one have serial I/O processing and if one wants to have things done in parallel, the simplest way would be having other(s) thread(s) reading and writting in the same I/O object. Is this correct?
I hope I have made my doubts clear enough, and if it is not clear please say it and i will try to be more objective.
See http://article.gmane.org/gmane.comp.lib.boost.user/50424
Regards.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
Matheus Araújo Aguiar wrote:
Dear list,
I have learned that one cannot make several async write requests, one after another, without waiting for the completion of each request, otherwise the bytes get merged and the messages will not make sense at the receiving side. I am correct assuming that, right? My doubt is if the same happens to async read requests. Does one have to wait a read request completes before issuing another? Will the bytes get merged too, if one does not wait before making another read request?
Assuming things happen that way, one async request waiting for the completion of another earlier request, then one have serial I/O processing and if one wants to have things done in parallel, the simplest way would be having other(s) thread(s) reading and writting in the same I/O object. Is this correct?
I hope I have made my doubts clear enough, and if it is not clear please say it and i will try to be more objective.
Regards,
Several read/write requests may not make sense because each read/write request may be split up in several read_some/write_some requests. Suppose you have a larger message A, and a smaller B, and you issue AB, it may be transmitted as A1BA2. You can issue a read and write request before completion of either to achieve full duplex communication with just one thread. Kind regards, Rutger ter Borg
On Fri, Sep 4, 2009 at 1:45 PM, Rutger ter Borg
Matheus Araújo Aguiar wrote:
Dear list,
I have learned that one cannot make several async write requests, one after another, without waiting for the completion of each request, otherwise the bytes get merged and the messages will not make sense at the receiving side. I am correct assuming that, right? My doubt is if the same happens to async read requests. Does one have to wait a read request completes before issuing another? Will the bytes get merged too, if one does not wait before making another read request?
Assuming things happen that way, one async request waiting for the completion of another earlier request, then one have serial I/O processing and if one wants to have things done in parallel, the simplest way would be having other(s) thread(s) reading and writting in the same I/O object. Is this correct?
I hope I have made my doubts clear enough, and if it is not clear please say it and i will try to be more objective.
Regards,
Several read/write requests may not make sense because each read/write request may be split up in several read_some/write_some requests. Suppose you have a larger message A, and a smaller B, and you issue AB, it may be transmitted as A1BA2.
In the case of writes, i see the problem. But, in reads, since i'm using tcp, i think that shouldn't be a problem.
You can issue a read and write request before completion of either to achieve full duplex communication with just one thread.
Thanks for the tip!
Kind regards,
Rutger ter Borg
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
I have defined a sequence of steps defining how to handle several async reads/writes. I am dealing with byte streams (TCP). Could you guys take a look and point any mistakes i might have made, please? Thanks in advance, *Write 1. Get a message from a queue; 2. Request async write the message; 3. Write completes and callback handler is called; 4. go back to 1; * Read (More than one async read have been requested) 1. Create buffer and assign it a sequence number; 2. Request async read passing the buffer; 3. Read completes and callback handler is called; 4. Request another async read; 5. Does the buffer number matches the next buffer number to be processed? 6. Numbers don't match, so put the buffer on a wait queue and exit; 7. Numbers match, so process the buffer; 8. Is there a buffer on the wait queue? 9. There's no buffer in queue, then exit; 10. There's a buffer on the queue, go back to 5; -- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
participants (3)
-
Matheus Araújo Aguiar
-
Robert Jones
-
Rutger ter Borg