Added include required by boost::system::system_category
Removed direct reference to pthread which causes compilation problems in Windows
Corrected undeclared identifiers and casts
Avoid problems regarding circular dependencies
Convert wstring to string.

Issue introduced by commit c366670ba1f6bc1e5de9720a2aaa6440482a1ff2