networking · beginner · ~15 min
Distinguish transient errors from fatal ones.
Some socket errors are transient and mean "just try the call again"; others are fatal. Classify an errno as retriable or not.
Implement int is_retriable(int err) that returns 1 for EAGAIN (would block) or EINTR (interrupted by a signal), otherwise 0.
One int err — an errno value.
Returns 1 if err is EAGAIN or EINTR, else 0.
is_retriable(EAGAIN) -> 1
is_retriable(EINTR) -> 1
is_retriable(ECONNREFUSED) -> 0
One integer err (an errno value).
1 if err is EAGAIN or EINTR, else 0.
EAGAIN and EINTR are the retriable (transient) errors.
#include <errno.h>
int is_retriable(int err) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.