Coverage Report

Created: 2025-07-18 06:24

/src/dovecot/src/lib/ioloop-iolist.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
3
 *
4
 * This software is released under the MIT license.
5
 */
6
7
#include "lib.h"
8
#include "ioloop-private.h"
9
#include "ioloop-iolist.h"
10
11
bool ioloop_iolist_add(struct io_list *list, struct io_file *io)
12
94.6k
{
13
94.6k
  int i, idx;
14
15
94.6k
  if ((io->io.condition & IO_READ) != 0)
16
55.1k
    idx = IOLOOP_IOLIST_INPUT;
17
39.4k
  else if ((io->io.condition & IO_WRITE) != 0)
18
39.4k
    idx = IOLOOP_IOLIST_OUTPUT;
19
0
  else if ((io->io.condition & IO_ERROR) != 0)
20
0
    idx = IOLOOP_IOLIST_ERROR;
21
0
  else {
22
0
    i_unreached();
23
0
  }
24
25
94.6k
  if (list->ios[idx] != NULL) {
26
0
    i_panic("io_add(0x%x) called twice fd=%d, callback=%p -> %p",
27
0
      io->io.condition, io->fd, list->ios[idx]->io.callback,
28
0
      io->io.callback);
29
0
  }
30
94.6k
  i_assert(list->ios[idx] == NULL);
31
94.6k
  list->ios[idx] = io;
32
33
  /* check if this was the first one */
34
263k
  for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
35
213k
    if (i != idx && list->ios[i] != NULL)
36
44.1k
      return FALSE;
37
213k
  }
38
39
50.4k
  return TRUE;
40
94.6k
}
41
42
bool ioloop_iolist_del(struct io_list *list, struct io_file *io)
43
94.6k
{
44
94.6k
  bool last = TRUE;
45
94.6k
  int i;
46
47
378k
  for (i = 0; i < IOLOOP_IOLIST_IOS_PER_FD; i++) {
48
283k
    if (list->ios[i] != NULL) {
49
138k
      if (list->ios[i] == io)
50
94.6k
        list->ios[i] = NULL;
51
44.1k
      else
52
44.1k
        last = FALSE;
53
138k
    }
54
283k
  }
55
94.6k
  return last;
56
94.6k
}