What API of Linux/Windows corresponds to limiting network (download/upload) speed?

后端 未结 4 1427
谎友^
谎友^ 2021-02-09 03:15

I\'m talking about speed limiting in download managers. For example, in Internet Download Manager there is a an option :

4条回答
  •  面向向阳花
    2021-02-09 03:37

    On Linux, I have no idea how it is done actually, but you could always look at the source code of applications doing this (eg wget with --limit-rate) or just strace them to understand the involved system calls.

    If I had to code a bandwidth limitation in a network application, I would simply do that after each buffer transmission: I would compute the current bandwidth, and would wait (without transmitting) the suitable delay to avoid overflowing the limitation.

    On Linux, poll and select system calls can wait some delay till input or output is available. And to just wait, use usleep or nanosleep system calls, etc.

提交回复
热议问题