This should take care of most compile issues as well as busy loops caused by unhandled recv() calls returning 0 and general cleanups.