We must read the errno variable before doing anything else which might trigger a syscall or glibc function, which in turn overwrite errno with the status of that subsequent call.
Note: This only fixes the error message, not the underlying problem of blindly writing to a non-blocking socket.