networking · beginner · ~15 min

Did connect succeed?

Interpret connect()'s return.

Challenge

Interpret the return value of a blocking connect().

Task

Implement int connect_succeeded(int rc).

Input

  • rc: the value connect() returned.

Output

Return 1 if rc == 0 (the handshake completed), else 0.

Example

connect_succeeded(0)   ->  1
connect_succeeded(-1)  ->  0

Input format

rc: the return value of connect().

Output format

1 if rc == 0, else 0.

Constraints

A blocking connect() returns 0 once the TCP handshake completes.

Starter code

int connect_succeeded(int rc) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.