boost::asio memory buffers and persistent connections.

I have a server running with asio. At any time i have 5000+ persistent connections from clients, but not all of them are sending/receiving data at all times. In fact, they only do requests once in a while. The problem is (with my current approach) that i need to have 5000+ memory buffers ready to receive that requests of very varying length. How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive? And maybe have those buffers in some memory pool. I've been studying http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/example/allocation/... without understanding it completely, but it doesn't look like what im looking for. Any ideas? Thanks a lot in advance. Alejandro

How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive?
You can make initial calls to async_read (or whatever read function you use) with buffer of 1 byte. When the handler is called, i.e. some data is available, you can perform "speculative" read (even synchronous) of all the data available - into any buffer you wish.

Perhaps you could use streambuffers ?
Matthieu
2009/3/25 Igor R
How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive?
You can make initial calls to async_read (or whatever read function you use) with buffer of 1 byte. When the handler is called, i.e. some data is available, you can perform "speculative" read (even synchronous) of all the data available - into any buffer you wish. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher

how?
"Matthieu Brucher"
Perhaps you could use streambuffers ?
Matthieu
2009/3/25 Igor R
: How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive?
You can make initial calls to async_read (or whatever read function you use) with buffer of 1 byte. When the handler is called, i.e. some data is available, you can perform "speculative" read (even synchronous) of all the data available - into any buffer you wish. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher

"Igor R"
How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive?
You can make initial calls to async_read (or whatever read function you use) with buffer of 1 byte. When the handler is called, i.e. some data is available, you can perform "speculative" read (even synchronous) of all the data available - into any buffer you wish.
And wouldn't that affect performance in some way? I've read somewhere, that i will not be able to get just the first byte, that i would probably get some more, and so i would have to copy that extra part to the real destination buffer and then read from there on. Am i correct? Thank you for your time.

And wouldn't that affect performance in some way?
I can't see how it would affect performance, but the real answer you will get from performance tests.
I've read somewhere, that i will not be able to get just the first byte, that i would probably get some more
boost::array

Igor R wrote:
How could i make it so i can set the buffer to use at the exact moment in which data for a new request in an already open connection begins to arrive?
You can make initial calls to async_read (or whatever read function you use) with buffer of 1 byte. When the handler is called, i.e. some data is available, you can perform "speculative" read (even synchronous) of all the data available - into any buffer you wish.
There is no need for a 1 byte buffer - ASIO provides null_buffers() for this purpose. See e.g. http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/overview/core/react... HTH, Juraj

There is no need for a 1 byte buffer - ASIO provides null_buffers() for this purpose. See e.g.
http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/overview/core/react...
Ah, right, I'm not updated with these latest features :)
participants (4)
-
Alejandro Martinez
-
Igor R
-
Juraj Ivančić
-
Matthieu Brucher