Hooks into PR_Write and PR_Read

"[email protected]" <[email protected]> Sun, 6 Dec 2009 07:16:32 -0800 (PST)
Newsgroups gmane.comp.mozilla.devel.nspr
Message-ID <[email protected]>
Hello, 

I'm developing an application that will hook into Mozilla Firefox PR_Read and PR_Write, which will be able to tamper requests and responses. Hooking works fine, but I'm having troubles. 

The hook for PR_Write works in a way that will collect all the output for an request, tamper it and do the real send, using another call to original PR_Write. My problem is that I need to write and read all the data before I return it to Firefox. I know that the sockets are in non-blocking mode, so if I get -1 as return code and last error would block, then I just pause a bit and retry sending or reading, so I return to Firefox only when all the request was sent or all the response was read. 

Is this the right approach? Because on some websites, I keep getting -1 and would block forever, and I get stuck in my sending or receiving loop. 

Any help would be greatly appreciated, 
Thanks.