Tuesday, March 14, 2006

socket() vs. WSASocket()

It turns out there are more differences in socket() and WSASocket() than just the number of arguments they take. In working on the sbcl/win32 socket port, Alastair Bridgewater pointed out that there were some Unix'y assumptions about socket handles being equivalent to file descriptors. The rest of sbcl expects to be able to _read and _write with them. On windows, you have to convert between SOCKETs and FDs using _open_osfhandle and _get_osfhandle. The interesting lesson is that in order to do anything with the file descriptor you get, the original SOCKET has to be generated with WSASocket(), NOT just socket(). Spent a fair amount of time today figuring that one out. The good news is, we now have slime running on win32/sbcl: