summaryrefslogtreecommitdiff
path: root/minix/lib/libasyn/asyn_synch.c
blob: 2330d6e6d72c8f1c540a469ec19cc71f7b663963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*	asyn_synch() - step back to synch		Author: Kees J. Bot
 *								7 Jul 1997
 */
#include "asyn.h"

int asyn_synch(asynchio_t *asyn, int fd)
/* No more asynchronous operations on this file descriptor. */
{
	asynfd_t *afd;
	int op;

	if ((unsigned) fd >= FD_SETSIZE) { errno= EBADF; return -1; }
	afd= &asyn->asyn_afd[fd];

	for (op= 0; op < SEL_NR; op++) {
		if (afd->afd_state[op] != IDLE) {
			errno= EAGAIN;
			return -1;
		}
	}

	/* Make sure the file flags are as they once were. */
	if (afd->afd_seen && fcntl(fd, F_SETFL, afd->afd_flags) < 0) return -1;
	afd->afd_seen= 0;
	return 0;
}