stream_ctl.c
935 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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)));
}