On 31/01/2023 17:17, Rahul K R wrote:
As part of my project activity, I have to create an asynchronous TCP server application using the boost library.
Note that this particular mailing list is primarily intended for development discussion of Boost libraries, not for usage questions. Those are better placed at the boost-users mailing list or on Stack Overflow or your other favourite code-questions site.
I have created a sample application and it's working. But the issue I am facing is the boost::asio::read API takes a long time to read from the TCP socket, almost 5 seconds. I am using boost library version 1.76.0.
read is a synchronous method; it does not belong in an asynchronous server. I suggest that you look at the existing asynchronous server examples at https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/examples.html (or the equivalent for your version of choice).
1. Is there any known issues for boost::asio::read to consume more time?
Read carefully what the CompletionCondition does and what happens if you don't pass one, or pass an inappropriate one for your traffic pattern. You may want to consider using the member function instead.
2. I am doing reading and writing to the same socket from two threads parallelly, Is that possible with the boost?
If, by that, you mean exclusively reading on one thread and writing on another, that's fine (provided you're careful with any shared state), but is also not typically how you'd implement an async server. Mixing multiple concurrent reads or concurrent writes on different threads is not recommended, since the results will likely interleave strangely even if you get the thread-safety perfect.