Lines Matching refs:io
42 struct io_file *io;
47 io = i_new(struct io_file, 1);
48 io->io.condition = condition;
49 io->io.callback = callback;
50 io->io.context = context;
51 io->io.ioloop = ioloop;
52 io->io.source_filename = source_filename;
53 io->io.source_linenum = source_linenum;
54 io->refcount = 1;
55 io->fd = fd;
57 if (io->io.ioloop->cur_ctx != NULL) {
58 io->io.ctx = io->io.ioloop->cur_ctx;
59 io_loop_context_ref(io->io.ctx);
62 if (io->io.ioloop->handler_context == NULL)
63 io_loop_initialize_handler(io->io.ioloop);
65 io_loop_handle_add(io);
71 if (io->io.ioloop->io_files != NULL) {
72 io->io.ioloop->io_files->prev = io;
73 io->next = io->io.ioloop->io_files;
75 io->io.ioloop->io_files = io;
76 return io;
80 struct io *io_add_to(struct ioloop *ioloop, int fd, enum io_condition condition,
84 struct io_file *io;
87 io = io_add_file(ioloop, fd, condition,
90 return &io->io;
94 struct io *io_add(int fd, enum io_condition condition,
105 struct io *io_add_istream_to(struct ioloop *ioloop, struct istream *input,
110 struct io_file *io;
112 io = io_add_file(ioloop, i_stream_get_fd(input), IO_READ,
114 io->istream = input;
115 i_stream_ref(io->istream);
116 i_stream_set_io(io->istream, &io->io);
117 return &io->io;
121 struct io *io_add_istream(struct istream *input, const char *source_filename,
130 static void io_file_unlink(struct io_file *io)
132 if (io->prev != NULL)
133 io->prev->next = io->next;
135 io->io.ioloop->io_files = io->next;
137 if (io->next != NULL)
138 io->next->prev = io->prev;
142 if (io->io.ioloop->next_io_file == io)
143 io->io.ioloop->next_io_file = io->next;
146 static void io_remove_full(struct io **_io, bool closed)
148 struct io *io = *_io;
150 i_assert(io->callback != NULL);
156 io->callback = NULL;
158 if (io->pending) {
159 i_assert(io->ioloop->io_pending_count > 0);
160 io->ioloop->io_pending_count--;
163 if (io->ctx != NULL)
164 io_loop_context_unref(&io->ctx);
166 if ((io->condition & IO_NOTIFY) != 0)
167 io_loop_notify_remove(io);
169 struct io_file *io_file = (struct io_file *)io;
173 /* remove io before it's freed */
174 i_stream_unset_io(istream, io);
181 i_free(io);
183 /* remove io from the ioloop before unreferencing the istream,
190 void io_remove(struct io **io)
192 if (*io == NULL)
195 io_remove_full(io, FALSE);
198 void io_remove_closed(struct io **io)
200 if (*io == NULL)
203 i_assert(((*io)->condition & IO_NOTIFY) == 0);
205 io_remove_full(io, TRUE);
208 void io_set_pending(struct io *io)
210 i_assert((io->condition & IO_NOTIFY) == 0);
212 if (!io->pending) {
213 io->pending = TRUE;
214 io->ioloop->io_pending_count++;
659 void io_loop_call_io(struct io *io)
661 struct ioloop *ioloop = io->ioloop;
664 if (io->pending) {
667 io->pending = FALSE;
670 if (io->ctx != NULL)
671 io_loop_context_activate(io->ctx);
673 (void *)io->callback);
674 io->callback(io->context);
677 (void *)io->callback);
705 struct io_file *io;
708 io = ioloop->io_files;
710 ioloop->next_io_file = io->next;
711 if (io->io.pending)
712 io_loop_call_io(&io->io);
715 io = ioloop->next_io_file;
716 } while (io != NULL);
803 struct io_file *io = ioloop->io_files;
804 struct io *_io = &io->io;
807 (void *)io->io.callback,
808 io->io.source_filename,
809 io->io.source_linenum, io->fd);
1068 struct io *io_loop_move_io_to(struct ioloop *ioloop, struct io **_io)
1070 struct io *old_io = *_io;
1089 io_set_pending(&new_io_file->io);
1092 /* update istream io after it was removed with io_remove() */
1093 i_stream_set_io(new_io_file->istream, &new_io_file->io);
1095 return &new_io_file->io;
1098 struct io *io_loop_move_io(struct io **_io)
1141 struct io_file *io;
1145 for (io = ioloop->io_files; io != NULL; io = io->next) {
1146 if (io->fd == fd)
1147 conditions |= io->io.condition;