⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sleepus.c

📁 unix网络编程卷1:套接口API的全书源码
💻 C
字号:
#include	<sys/types.h>#include	<sys/time.h>#include	<errno.h>#include	<stddef.h>#include	"ourhdr.h"voidsleep_us(unsigned int nusecs){	struct timeval	tval;	for ( ; ; ) {		tval.tv_sec = nusecs / 1000000;		tval.tv_usec = nusecs % 1000000;		if (select(0, NULL, NULL, NULL, &tval) == 0)			break;		/* all OK */		/*		 * Note than on an interrupted system call (i.e, SIGIO) there's not		 * much we can do, since the timeval{} isn't updated with the time		 * remaining.  We could obtain the clock time before the call, and		 * then obtain the clock time here, subtracting them to determine		 * how long select() blocked before it was interrupted, but that		 * seems like too much work :-)		 */		if (errno == EINTR)			continue;		err_sys("sleep_us: select error");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -