[asio-users] querying for active async operations
Brought to you by:
chris_kohlhoff
From: Arvid N. <c9...@cs...> - 2005-12-14 01:59:46
|
Hi. I have a stream_socket, and I want to throttle the bandwidth it uses for the data I send and receive on that socket. Right now I have implemented this as a per second quota. When the socket runs out of quota it won't receive anything until the next second, when it's restored again. The use pattern for receiving seems to be: main() { socket.async_read_some(handler, ...); demuxer.run(); } void handler(...) { // process received data socket.async_read_some(handler, ...); } Something like that. Now that I want to throttle the download speed; at the end of the handler I sometimes don't want to call async_read_some(), because the download quota for this second is already used up. But in some situations, where the quota is much bigger than the actual transfer rate, it will always call async_read_some() at the end. Now, every time I reset the receive quota, I will have to check: "am I currently waiting for data or should I call async_read_some() now?" This would be pretty easy to know, just by storing that state with my connection, but maybe it could be useful to be able to query the socket for that too. I'm not sure if it's really a good idea, since the interface is pretty big as it is though, but at least it would make the invariance of my connection class easier to maintain. And, btw, is this a stupid way of throttling the download speed? (assuming there's no protocol support that can tell the other side to throttle its send rate). thanks. -- Arvid Norberg |