stream_ctl.c 935 Bytes
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include <scot/stream.h>
#include <scot/exception.h>

#include <scot_common.h>

int
scot_stream_get_blocking (struct scot_stream * s)
{
	int flags = fcntl (s->handle.file, F_GETFL);

	if (flags == -1)
		THROW (EXC (EXC_ERROR, errno, strerror (errno)));

	return ! (flags & O_NONBLOCK);
}

void
scot_stream_set_block (struct scot_stream * s)
{
	int flags = fcntl (s->handle.file, F_GETFL);

	if (flags == -1)
		THROW (EXC (EXC_ERROR, errno, strerror (errno)));

	if (fcntl (s->handle.file, F_SETFL, flags & ~O_NONBLOCK) == -1)
		THROW (EXC (EXC_ERROR, errno, strerror (errno)));
}

void
scot_stream_set_nonblock (struct scot_stream * s)
{
	int flags = fcntl (s->handle.file, F_GETFL);

	if (flags == -1)
		THROW (EXC (EXC_ERROR, errno, strerror (errno)));

	if (fcntl ( s->handle.file, F_SETFL, flags | O_NONBLOCK) == -1)
		THROW (EXC (EXC_ERROR, errno, strerror (errno)));
}