view src/lib/fd-set-nonblock.c @ 3749:194295062e5e HEAD

Added kqueue support. Patch by Vaclav Haisman.
author Timo Sirainen <tss@iki.fi>
date Wed, 14 Dec 2005 20:51:52 +0200
parents 3ae2df67459c
children 55df57c028d4
line wrap: on
line source

/* Copyright (c) 1999-2005 Timo Sirainen */

#include "lib.h"
#include "fd-set-nonblock.h"

#include <fcntl.h>

int fd_set_nonblock(int fd, int nonblock)
{
	int flags;

	flags = fcntl(fd, F_GETFL, 0);
	if (flags < 0) {
		i_error("fcntl(%d, F_GETFL) failed: %m", fd);
		return -1;
	}

	if (nonblock)
		flags |= O_NONBLOCK;
	else
		flags &= ~O_NONBLOCK;

	if (fcntl(fd, F_SETFL, flags) < 0) {
		i_error("fcntl(%d, F_SETFL) failed: %m", fd);
		return -1;
	}
	return 0;
}