Avatar of adisal
 asked on

Want to limit bandwidth in windows using Winsock SPI

I am trying to make a tool that can limit / throttle / shape / cap the bandwidth allocated to each process / application in Windows XP.
Got some lead on LSP here :
But still  i am not clear about how i can limit bandwidth as for each process.
I read about functions WSPSend & WSPRecv etc in SPI, how can i use these functions for my job?
Programming Languages-OtherWindows OSWindows Networking

Avatar of undefined
Last Comment

8/22/2022 - Mon

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

I was able to hook API call WSPSend .
I inserted sleep in between calls.
 but it feels like Internet Explorer hangs for a while in between calls.
May be i inserted sleep in wrong place , trying to figure it out now.
Any suggestions?

I assume that it uses non-blocking mode: asynchronous API or doing "select" before the calls.

(1) Select
(1.a) WSPSelect function - you can call the original function, but add  a sleep here before returning from the call
(1.b) WSPAsyncSleep - it's more complicated. Basically, the application gives you Event object and it will later so one of "WaitFor" functions on it. You can replace the event with your own event, but you have to make sure you get called when the event is fired. One option is to add hooks (with "detours") on all versions of "WaitFor" (note: there are "single object", "multiple objects", "msg" etc), and add your handle to the list of application's handles (of cause, only if the "hooked" handle is present). When you Event is being signeled - it's a place to "sleep", but you don't want to sleep - or the appliction will block :) Here you can set up a timer and signel the original event when the timer expires. See, for example, http://msdn.microsoft.com/en-us/library/ms686898(VS.85).aspx
The other option would be doing the waiting in separate thread, and once ready + appropriate time has passed - notify the original event.

(2) Async (overlapped) functions
(2.a) Through "lpCompletionRoutine" parameter (say, of WSPSend). This case is pretty easy - just override the callback with your own function + register timer callback + notify original event
(2.b) Through"hEvent" member of "lpOverlapped" parameter - in this case you should act same way as i (1.b)

Good luck :)

I would suggest to start with printing a debug info, to understand which type of non-blocking API is used by IE. Of cause, if you want to make a generic solution, you'll need to support all synchronization types.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck