networking · intermediate · ~15 min

Non-blocking connect in progress?

Recognise the in-progress connect status.

Challenge

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.

Task

Implement int connect_in_progress(int err).

Input

  • err: the errno value after a non-blocking connect().

Output

Return 1 if err == EINPROGRESS, else 0.

Example

connect_in_progress(EINPROGRESS)   ->  1
connect_in_progress(ECONNREFUSED)  ->  0

Input format

err: the errno value after a non-blocking connect().

Output format

1 if err == EINPROGRESS, else 0.

Constraints

EINPROGRESS means the connect is underway; wait for writability for the result.

Starter code

#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.