socks: add timeout & win32 support to sock_readn()