networking · intermediate · ~15 min
Recognise the in-progress connect status.
Recognise the "handshake still running" status from a non-blocking connect().
A non-blocking connect() returns -1 and sets errno to EINPROGRESS while the TCP handshake is still underway.
Implement int connect_in_progress(int err).
err: the errno value after a non-blocking connect().Return 1 if err == EINPROGRESS, else 0.
connect_in_progress(EINPROGRESS) -> 1
connect_in_progress(ECONNREFUSED) -> 0
err: the errno value after a non-blocking connect().
1 if err == EINPROGRESS, else 0.
EINPROGRESS means the connect is underway; wait for writability for the result.
#include <errno.h>
int connect_in_progress(int err) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.