The networking session of this year's USENIX has a paper talking about
a userland bandwidth shaper created by Google engineer Marius Aamodt Eriksen (need login to download the paper, but the source code is available
here).
Form Trickle's man page:
trickle is a userspace bandwidth manager. Currently, trickle supports
the shaping of any SOCK_STREAM (see socket(2)) connection established
via the socket(2) interface. Furthermore, trickle will not work
with statically linked executables, nor with setuid(2) executables.
trickle is highly configurable; download and upload rates can be
set separately, or in an aggregate fashion.
The trickle daemon, an LD_PRELOAD module, works by imposing a rate cap on the bandwidth (upload, download, or both) of a process or group of processes using socket connections.
LD_PRELOAD is a way to intercept dynamic function called. You set the environment variable to your own shared library, in which you define your own functions.