Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Nov 1996 08:11:58 -0600 (CST)
From:      Joe Greco <jgreco@brasil.moneng.mei.com>
To:        hannibal@cyberstation.net
Cc:        hackers@freebsd.org
Subject:   Re: Limiting bandwidth on a socket?  (SO_RCVBUF?)
Message-ID:  <199611061411.IAA08311@brasil.moneng.mei.com>
In-Reply-To: <Pine.BSI.3.95.961105222131.7619A-100000@citrine.cyberstation.net> from "Dan Walters" at Nov 5, 96 10:51:58 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> I'm trying to come up with some way to limit the amount of bandwidth on a
> socket, so I can have my mail and large files retrieve without slowing
> down a telnet session that much.
> 
> I thought I could do this by setting SO_RCVBUF to a small value, but it
> doesn't seem to change the window size at all when I look at it with
> tcpdump.
> 
> I saw something about patches to fix a broken SO_RCVBUF implementation in
> the mailing list archives, but can't seem to locate them / not sure if
> they made it in the kernel in the first place.  If SO_RCVBUF would do what
> I want, I'd like a copy of them.  :)
> 
> I could swear I saw a "low-bandwidth ncftp" or something of the sort on
> sunsite.unc.edu a couple years ago, so I think this is possible (Well, at
> least in Linux...).  It's apparently been deleted though.
> 
> Anyone know how to do this?

int s, rval;

s = socket(...);

while ((rval = read(..., 1024)) > 0) {
	sleep(1);
}

if (rval < 0) {
	perror(...);
}

You can adjust the number of bytes read and the sleep() value to arange for
many different potential amounts of bandwidth.

I have successfully applied this concept numerous times before...  and it
applies to UDP as well as TCP (I have done this with tftp, once, when
someone was trying to convince me that tftp "cannot be slowed down" (for
a specific application where this was a requirement.  1K/sec is painful).

The downside is that it generally requires C code modifications.

I am not aware of any general way to do this without code modifications,
without the introduction of specialized code such as ET's bandwidth
manager (and I am by no means certain that BWMGR can handle this).

I will note that some PPP/SLIP software allows prioritization of certain
types of traffic, by way of "TOS" (type of service) queue reordering.  
This works moderately well when the MTU is small and the amount of data
being buffered by the modem is very small.  Cheap modems generally do not
give you that level of control.

... JG



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199611061411.IAA08311>