Bulat M. Bulat M. - 1 month ago 8
C Question

Recover after "accept" interruption

Was writing program with server capability.
Here is short snippet demonstrating accept:

for (;;) {
if ((c = accept(s, (struct sockaddr *)&sa, &b)) == -1) {
if (EINTR == errno) {
syslog(LOG_INFO, "recovering after system call interruption");
continue;
} else
err_exit(strerror(errno));
}
/* forking, client handling code */
}


Also I handle HUP by rereading configuration file so that signal could happen when
accept
is being blocked waiting for client requests.

Is the approach I use correct or there is another proper method for doing
accept
and handling signals?

Does interruption by a signal flushes clients queue waiting to be serviced, that is my main concern regarding the question.

alk alk
Answer

Does interruption by a signal flushes clients queue

No, it doesn't.

Is the approach I use correct

It is a common approach, yes.

or there is another proper method for doing accept and handling signals?

Not answerable, as you do not show the related code, how you actually do the signal handling.

Comments