This question is very similar (or almost identical) to In a non blocking socket connect, select() always returns 1; however, I can\'t seem to find where my code is faltering
When connecting in non-blocking mode and select() indicates the connection is writeable, you are then supposed to call connect() again. Doing so will return -1 with errno == ECONNRESET or whatever it is.