networking · beginner · ~15 min
Validate the listen backlog argument.
Validate the backlog argument to listen(), which bounds the pending-connection queue.
Implement int valid_backlog(int b).
b: the proposed backlog value.Return 1 if b >= 0 (a valid backlog), else 0.
valid_backlog(128) -> 1
valid_backlog(0) -> 1
valid_backlog(-1) -> 0
b: the proposed listen backlog.
1 if b >= 0, else 0.
The backlog must be non-negative.
int valid_backlog(int b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.