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

📄 sselect.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
字号:
#include "syshdrs.h"

void
SelectSetInit(SelectSetPtr const ssp, const double timeout)
{
	double i;
	long l;

	/* Inititalize SelectSet, which will clear the fd_set, the
	 * timeval, and the maxfd and numfds to 0.
	 */
	memset(ssp, 0, sizeof(SelectSet));
	l = (long) timeout;
	i = (double) l;
	ssp->timeout.tv_sec = l;
	ssp->timeout.tv_usec = (long) ((timeout - i) * 1000000.0);
}	/* SelectSetInit */




void
SelectSetAdd(SelectSetPtr const ssp, const int fd)
{
	if (fd >= 0) {
		FD_SET(fd, &ssp->fds);
		if (ssp->maxfd < (fd + 1))
			ssp->maxfd = (fd + 1);
		++ssp->numfds;
	}
}	/* SelectSetAdd */




void
SelectSetRemove(SelectSetPtr const ssp, const int fd)
{
	if ((fd >= 0) && (FD_ISSET(fd, &ssp->fds))) {
		FD_CLR(fd, &ssp->fds);
		/* Note that maxfd is left alone, even if maxfd was
		 * this one.  That is okay.
		 */
		--ssp->numfds;
	}
}	/* SelectSetRemove */



int
SelectW(SelectSetPtr ssp, SelectSetPtr resultssp)
{
	int rc;

	do {
		memcpy(resultssp, ssp, sizeof(SelectSet));
		rc = select(resultssp->maxfd, NULL, SELECT_TYPE_ARG234 &resultssp->fds, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
	} while ((rc < 0) && (errno == EINTR));
	return (rc);
}	/* SelectW */



int
SelectR(SelectSetPtr ssp, SelectSetPtr resultssp)
{
	int rc;

	do {
		memcpy(resultssp, ssp, sizeof(SelectSet));
		rc = select(resultssp->maxfd, SELECT_TYPE_ARG234 &resultssp->fds, NULL, NULL, SELECT_TYPE_ARG5 &resultssp->timeout);
	} while ((rc < 0) && (errno == EINTR));
	return (rc);
}	/* SelectR */

⌨️ 快捷键说明

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