networking · beginner · ~15 min
Interpret accept()'s return.
Interpret the return value of accept(), which hands back a new fd or -1 on error.
Implement int accept_ok(int rc).
rc: the value accept() returned.Return 1 if rc >= 0 (a valid descriptor for the accepted connection), else 0.
accept_ok(5) -> 1
accept_ok(-1) -> 0
rc: the return value of accept().
1 if rc >= 0 (valid fd), else 0.
accept() returns a new fd (>= 0) on success, -1 on error.
int accept_ok(int rc) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.