Lines Matching refs:fda
13 void fdarray__init(struct fdarray *fda, int nr_autogrow) in fdarray__init() argument
15 fda->entries = NULL; in fdarray__init()
16 fda->priv = NULL; in fdarray__init()
17 fda->nr = fda->nr_alloc = 0; in fdarray__init()
18 fda->nr_autogrow = nr_autogrow; in fdarray__init()
21 int fdarray__grow(struct fdarray *fda, int nr) in fdarray__grow() argument
24 int nr_alloc = fda->nr_alloc + nr; in fdarray__grow()
25 size_t psize = sizeof(fda->priv[0]) * nr_alloc; in fdarray__grow()
27 struct pollfd *entries = realloc(fda->entries, size); in fdarray__grow()
32 priv = realloc(fda->priv, psize); in fdarray__grow()
38 memset(&entries[fda->nr_alloc], 0, sizeof(struct pollfd) * nr); in fdarray__grow()
39 memset(&priv[fda->nr_alloc], 0, sizeof(fda->priv[0]) * nr); in fdarray__grow()
41 fda->nr_alloc = nr_alloc; in fdarray__grow()
42 fda->entries = entries; in fdarray__grow()
43 fda->priv = priv; in fdarray__grow()
49 struct fdarray *fda = calloc(1, sizeof(*fda)); in fdarray__new() local
51 if (fda != NULL) { in fdarray__new()
52 if (fdarray__grow(fda, nr_alloc)) { in fdarray__new()
53 free(fda); in fdarray__new()
54 fda = NULL; in fdarray__new()
56 fda->nr_autogrow = nr_autogrow; in fdarray__new()
60 return fda; in fdarray__new()
63 void fdarray__exit(struct fdarray *fda) in fdarray__exit() argument
65 free(fda->entries); in fdarray__exit()
66 free(fda->priv); in fdarray__exit()
67 fdarray__init(fda, 0); in fdarray__exit()
70 void fdarray__delete(struct fdarray *fda) in fdarray__delete() argument
72 fdarray__exit(fda); in fdarray__delete()
73 free(fda); in fdarray__delete()
76 int fdarray__add(struct fdarray *fda, int fd, short revents, enum fdarray_flags flags) in fdarray__add() argument
78 int pos = fda->nr; in fdarray__add()
80 if (fda->nr == fda->nr_alloc && in fdarray__add()
81 fdarray__grow(fda, fda->nr_autogrow) < 0) in fdarray__add()
84 fda->entries[fda->nr].fd = fd; in fdarray__add()
85 fda->entries[fda->nr].events = revents; in fdarray__add()
86 fda->priv[fda->nr].flags = flags; in fdarray__add()
87 fda->nr++; in fdarray__add()
91 int fdarray__dup_entry_from(struct fdarray *fda, int pos, struct fdarray *from) in fdarray__dup_entry_from() argument
101 npos = fdarray__add(fda, entry->fd, entry->events, from->priv[pos].flags); in fdarray__dup_entry_from()
103 fda->priv[npos] = from->priv[pos]; in fdarray__dup_entry_from()
108 int fdarray__filter(struct fdarray *fda, short revents, in fdarray__filter() argument
109 void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), in fdarray__filter() argument
114 if (fda->nr == 0) in fdarray__filter()
117 for (fd = 0; fd < fda->nr; ++fd) { in fdarray__filter()
118 if (!fda->entries[fd].events) in fdarray__filter()
121 if (fda->entries[fd].revents & revents) { in fdarray__filter()
123 entry_destructor(fda, fd, arg); in fdarray__filter()
125 fda->entries[fd].revents = fda->entries[fd].events = 0; in fdarray__filter()
129 if (!(fda->priv[fd].flags & fdarray_flag__nonfilterable)) in fdarray__filter()
136 int fdarray__poll(struct fdarray *fda, int timeout) in fdarray__poll() argument
138 return poll(fda->entries, fda->nr, timeout); in fdarray__poll()
141 int fdarray__fprintf(struct fdarray *fda, FILE *fp) in fdarray__fprintf() argument
143 int fd, printed = fprintf(fp, "%d [ ", fda->nr); in fdarray__fprintf()
145 for (fd = 0; fd < fda->nr; ++fd) in fdarray__fprintf()
146 printed += fprintf(fp, "%s%d", fd ? ", " : "", fda->entries[fd].fd); in fdarray__fprintf()