Shutdown cleanup

- Many file descriptors were left open. They're now tracked globally for windows(like in the osx/linux code) and closed on shutdown. It would be better if we closed them in the code that used them.
- A number of initialization variables weren't being reset.
- Made the device loop shutdown consistent. I was getting intermittent failures with the old code since the device loop often remained open during shutdown and devices were being added while things were being freed.
- Simplified killing the IO pump.
- Fixed the bug on OSX where devices weren't able to reconnect after close and open.