Possible Duplicate:
How do you throttle the bandwidth of a socket connection in C?
I'm writing a simple FTP server in C for a Unix environment. As a feature of the server, I want to limit the upload/download speed of a user.
Are there any library functions directly solve this problem?
If not, what's the algorithm used in a production FTP server? I have a very naive solution: calculate how many bytes to send in a second, say
x
,write(x)
orread(x)
, and thensleep(1)
.
There should be a better solution. Even better if there are code samples.
To be clear, I'm using Mac OS X, but I wish it could also run under Ubuntu or some Linux.