port socket fix from 918f59fbe26571f78231f380f3304fd164b19b10 to Windows
fix potential wrong error code in posix socket
Merge pull request #221 from FernetMenta/winsocket

port socket fix from 918f59fbe26571f78231f380f3304fd164b19b10 to Windows