// SPDX-License-Identifier: GPL-2.0-only /* Timeout API for single-threaded programs that use blocking *syscalls(read/write/send/recv/connect/accept). * *Copyright(C)2017RedHat,Inc. * *Author:StefanHajnoczi<stefanha@redhat.com>
*/
/* Use the following pattern: * *timeout_begin(TIMEOUT); *do{ *ret=accept(...); *timeout_check("accept"); *}while(ret<0&&ret==EINTR); *timeout_end();
*/
/* SIGALRM handler function. Do not use sleep(2), alarm(2), or *setitimer(2)whileusingthisAPI-theymayinterferewitheach *other. * *Ifyouneedtosleep,pleaseusetimeout_sleep()providedbythisAPI.
*/ void sigalrm(int signo)
{
timeout = true;
}
/* Start a timeout. Call timeout_check() to verify that the timeout hasn't *expired.timeout_end()mustbecalledtostopthetimeout.Timeoutscannot *benested.
*/ void timeout_begin(unsignedint seconds)
{
alarm(seconds);
}
/* Exit with an error message if the timeout has expired */ void timeout_check(constchar *operation)
{ if (timeout) {
fprintf(stderr, "%s timed out\n", operation); exit(EXIT_FAILURE);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.