Friday, March 03, 2006

on WSAWaitForMultipleObjects

As we found out today, there are only so many objects that you can wait on in this function. That number is 64. If you try to wait on more than that, very bad things happen. In our case, our listener thread blew up. We were trying to handle more than 64 simultaneous non-blocking connection requests that had been accepted. The fix was a simple matter of making the events over 64 wait in a queue until we can handle them. We will check to make sure this behavior still works for us on the cluster before we roll it into the app.

While there was not a lot of visible changes this week, Tim and I actually fixed some persistent bugs (the above, an SQL injection issue that had been causing caching issues, an Installed Software problem, and the whole Updater not rebooting mess) as well as figured out some interesting new things (like extracting license keys from the registry). It actually felt pretty productive.

more sb-win32-sockets

I've now cleared most of the WARNINGs and STYLE-WARNINGs from the win32 port of sb-bsd-sockets. You can download the reults here. I'm still having fits with a piece of code that initializes the windows sockets subsystem.

For some unknown reason, on windows, you have to run WSAStartup() in your application before you make any calls to networking APIs, or Windows gives you the cold shoulder. Unix isn't so demanding, so I'm hard-pressed to figure out why Windows has to be different. In any case, it is, and so I have to deal with it. It was suggested that I call the function in the initialization of a special.

In Lisp-speak, this is a dynamic, as opposed to lexical variable. The code looks something like:

(defvar *wsa-is-initialized* (wsa-startup ...))

Of course, this doesn't work for me. wsa-startup is in the package sb-bsd-sockets-internal, while the code you are seeing is in the sb-bsd-sockets package. While the same file is sprinkled with internal socket functions, my wsa-startup functions get a nasty ERROR from the compiler. I am assuming that this has to do with the whole eval-when business that I must claim I have absolutely no clue what it is really doing.

It was a package export issue. I wasn't exporting the wsa-startup symbol from the internals package. This was confusing because I thought I was doing the right thing by prefacing it with win32sockint:wsa-startup. It turns out this only works for exported symbols. For unexported symbols, use two colons. win32sockint::wsa-startup. Thanks go to the #lisp crowd for the help on that one. At least you CAN get to the symbol. I was becoming more discontent with C++'s whole public/protected/private pseudo-encapsulation, and Lisp has only solidified that view.