aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore/efl_io_reader_fd.c
blob: 8a5ca4ffb3fb552f5af879bf4076af44debf674d (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#define EFL_IO_READER_PROTECTED 1
#define EFL_IO_READER_FD_PROTECTED 1

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Ecore.h>
#include "ecore_private.h"

#define MY_CLASS EFL_IO_READER_FD_CLASS

typedef struct _Efl_Io_Reader_Fd_Data
{
   int fd;
   Eina_Bool can_read;
   Eina_Bool eos;
} Efl_Io_Reader_Fd_Data;

EOLIAN static void
_efl_io_reader_fd_reader_fd_set(Eo *o EINA_UNUSED, Efl_Io_Reader_Fd_Data *pd, int fd)
{
   pd->fd = fd;
}

EOLIAN static int
_efl_io_reader_fd_reader_fd_get(Eo *o EINA_UNUSED, Efl_Io_Reader_Fd_Data *pd)
{
   return pd->fd;
}

EOLIAN static Eina_Error
_efl_io_reader_fd_efl_io_reader_read(Eo *o, Efl_Io_Reader_Fd_Data *pd EINA_UNUSED, Eina_Rw_Slice *rw_slice)
{
   int fd = efl_io_reader_fd_reader_fd_get(o);
   ssize_t r;

   EINA_SAFETY_ON_NULL_RETURN_VAL(rw_slice, EINVAL);
   if (fd < 0) goto error;
   do
     {
        r = read(fd, rw_slice->mem, rw_slice->len);
        if (r < 0)
          {
             if (errno == EINTR) continue;

             rw_slice->len = 0;
             rw_slice->mem = NULL;
             if (errno == EAGAIN) efl_io_reader_can_read_set(o, EINA_FALSE);
             return errno;
          }
     }
   while (r < 0);

   rw_slice->len = r;
   if (r == 0)
     {
        efl_io_reader_can_read_set(o, EINA_FALSE);
        efl_io_reader_eos_set(o, EINA_TRUE);
     }
   return 0;

 error:
   rw_slice->len = 0;
   rw_slice->mem = NULL;
   return EINVAL;
}

EOLIAN static Eina_Bool
_efl_io_reader_fd_efl_io_reader_can_read_get(Eo *o EINA_UNUSED, Efl_Io_Reader_Fd_Data *pd)
{
   return pd->can_read;
}

EOLIAN static void
_efl_io_reader_fd_efl_io_reader_can_read_set(Eo *o, Efl_Io_Reader_Fd_Data *pd, Eina_Bool can_read)
{
   EINA_SAFETY_ON_TRUE_RETURN(efl_io_reader_fd_reader_fd_get(o) < 0);
   if (pd->can_read == can_read) return;
   pd->can_read = can_read;
   efl_event_callback_legacy_call(o, EFL_IO_READER_EVENT_CAN_READ_CHANGED, NULL);
}

EOLIAN static Eina_Bool
_efl_io_reader_fd_efl_io_reader_eos_get(Eo *o EINA_UNUSED, Efl_Io_Reader_Fd_Data *pd)
{
   return pd->eos;
}

EOLIAN static void
_efl_io_reader_fd_efl_io_reader_eos_set(Eo *o, Efl_Io_Reader_Fd_Data *pd, Eina_Bool is_eos)
{
   EINA_SAFETY_ON_TRUE_RETURN(efl_io_reader_fd_reader_fd_get(o) < 0);
   if (pd->eos == is_eos) return;
   pd->eos = is_eos;
   if (is_eos)
     efl_event_callback_legacy_call(o, EFL_IO_READER_EVENT_EOS, NULL);
}

#include "efl_io_reader_fd.eo.c"