I wish to send some arbitrary amount of data across a TCP connection. I expect that there will be a problem wherein the size of the chunks of data will be too large or the frequency at which they're sent will be too great, resulting in a backup of data being sent.
For example (pseudo):
sf::TcpSocket socket;
// connect socket
while(!endOfData) {
socket.send(/*a chunk of data*/);
// get next chunk of data
}
Now if data is being queued for sending faster than the socket can actually send it off, there will be a backlog of data that hasn't really been sent. I therefore want to reduce the speed at which it is sent.
My solution:
sf::TcpSocket socket;
// connect socket
while(!endOfData) {
sf::Socket::Status status = sf::Socket::NotReady;
while(status == sf::Socket::NotReady) {
status = socket.send(/*a chunk of data*/);
}
// get next chunk of data
}
This now tries to send the same data until the status returned isn't
sf::Socket::NotReady. This seems like the logical solution, but I'm not sure that this is the actual status returned in this situation (when the socket's buffer isn't empty).
How can I regulate the sending speed of a TcpSocket to match the user's system? Furthermore, is it also possible/recommended to match the receiver's download speed as well?
PS: The examples above are not meant as actual implementations, but rather only serve to demonstrate the problem.