Fixed a few socket fd related issues.