From: Mihai I. <mi...@re...> - 2006-06-19 04:26:09
|
On Sun, Jun 18, 2006 at 07:24:17PM -0500, Andrew Gaffney wrote: > Andrew Gaffney wrote: > > Okay, I finally have it "working". My above statement was actually wrong. It > looks like HTTPResponse *does* use makefile(), but HTTPConnection does *not*. > So, it calls close() which decrements the counter without ever calling > makefile() which increments the counter. The way I made it "work" was by > commenting all the calls to .close() and .shutdown(). This is technically > "wrong", but it gets around the faulty close_refcount logic. Can anyone suggest > a better way to do this? The history behind that counter is (but this is all based on memory): When the response object is created, httplib.HTTPConnection will use makefile() to dup() the file descriptor it passes down to the HTTPResponse object. This allows the code to be much cleaner, you can now close the main connection object and just keep reading from the response one. The problem with SSL is, it's not exposing real sockets. As such, there is no dup() that works. The only way to achieve the same functionality is to play the tricky counter thingie to keep the file descriptor open even after you close the HTTPConnection. So, makefile() should increment the counter, and close() should keep decrementing it (and do nothing else) until you hit zero, at which point it should close the SSL connection. For the same reason, select() works very unreliably on SSL sockets, because it uses the underlying file descriptor/socket to check for incoming bytes. You may (and I did) run into the situation where you get a couple of bytes on the socket, but not enough to create input into the SSL buffer. So, select() would return, but the read from the SSL socket would block. Hope this helps. Misa |