Lines Matching refs:io
62 static void delete_events(pa_iochannel *io) {
63 pa_assert(io);
65 if (io->input_event)
66 io->mainloop->io_free(io->input_event);
68 if (io->output_event && io->output_event != io->input_event)
69 io->mainloop->io_free(io->output_event);
71 io->input_event = io->output_event = NULL;
74 static void enable_events(pa_iochannel *io) {
75 pa_assert(io);
77 if (io->hungup) {
78 delete_events(io);
82 if (io->ifd == io->ofd && io->ifd >= 0) {
85 if (!io->readable)
87 if (!io->writable)
90 pa_assert(io->input_event == io->output_event);
93 if (io->input_event)
94 io->mainloop->io_enable(io->input_event, f);
96 io->input_event = io->output_event = io->mainloop->io_new(io->mainloop, io->ifd, f, callback, io);
98 delete_events(io);
102 if (io->ifd >= 0) {
103 if (!io->readable) {
104 if (io->input_event)
105 io->mainloop->io_enable(io->input_event, PA_IO_EVENT_INPUT);
107 io->input_event = io->mainloop->io_new(io->mainloop, io->ifd, PA_IO_EVENT_INPUT, callback, io);
108 } else if (io->input_event) {
109 io->mainloop->io_free(io->input_event);
110 io->input_event = NULL;
114 if (io->ofd >= 0) {
115 if (!io->writable) {
116 if (io->output_event)
117 io->mainloop->io_enable(io->output_event, PA_IO_EVENT_OUTPUT);
119 io->output_event = io->mainloop->io_new(io->mainloop, io->ofd, PA_IO_EVENT_OUTPUT, callback, io);
120 } else if (io->output_event) {
121 io->mainloop->io_free(io->output_event);
122 io->output_event = NULL;
129 pa_iochannel *io = userdata;
137 if ((f & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) && !io->hungup) {
138 io->hungup = true;
142 if ((f & PA_IO_EVENT_INPUT) && !io->readable) {
143 io->readable = true;
145 pa_assert(e == io->input_event);
148 if ((f & PA_IO_EVENT_OUTPUT) && !io->writable) {
149 io->writable = true;
151 pa_assert(e == io->output_event);
155 enable_events(io);
157 if (io->callback)
158 io->callback(io, io->userdata);
163 pa_iochannel *io;
168 io = pa_xnew0(pa_iochannel, 1);
169 io->ifd = ifd;
170 io->ofd = ofd;
171 io->mainloop = m;
173 if (io->ifd >= 0)
174 pa_make_fd_nonblock(io->ifd);
176 if (io->ofd >= 0 && io->ofd != io->ifd)
177 pa_make_fd_nonblock(io->ofd);
179 enable_events(io);
180 return io;
183 void pa_iochannel_free(pa_iochannel*io) {
184 pa_assert(io);
186 delete_events(io);
188 if (!io->no_close) {
189 if (io->ifd >= 0)
190 pa_close(io->ifd);
191 if (io->ofd >= 0 && io->ofd != io->ifd)
192 pa_close(io->ofd);
195 pa_xfree(io);
198 bool pa_iochannel_is_readable(pa_iochannel*io) {
199 pa_assert(io);
201 return io->readable || io->hungup;
204 bool pa_iochannel_is_writable(pa_iochannel*io) {
205 pa_assert(io);
207 return io->writable && !io->hungup;
210 bool pa_iochannel_is_hungup(pa_iochannel*io) {
211 pa_assert(io);
213 return io->hungup;
216 ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) {
219 pa_assert(io);
222 pa_assert(io->ofd >= 0);
224 r = pa_write(io->ofd, data, l, &io->ofd_type);
237 io->writable = io->hungup = false;
238 enable_events(io);
243 ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) {
246 pa_assert(io);
248 pa_assert(io->ifd >= 0);
250 if ((r = pa_read(io->ifd, data, l, &io->ifd_type)) >= 0) {
255 io->readable = io->hungup = false;
256 enable_events(io);
271 bool pa_iochannel_creds_supported(pa_iochannel *io) {
282 pa_assert(io);
283 pa_assert(io->ifd >= 0);
284 pa_assert(io->ofd == io->ifd);
287 if (getsockname(io->ifd, &sa.sa, &l) < 0)
293 int pa_iochannel_creds_enable(pa_iochannel *io) {
298 pa_assert(io);
299 pa_assert(io->ifd >= 0);
302 if (setsockopt(io->ifd, SOL_SOCKET, SO_PASSCRED, &t, sizeof(t)) < 0) {
311 ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l, const pa_creds *ucred) {
321 pa_assert(io);
324 pa_assert(io->ofd >= 0);
356 if ((r = sendmsg(io->ofd, &mh, MSG_NOSIGNAL)) >= 0) {
357 io->writable = io->hungup = false;
358 enable_events(io);
366 ssize_t pa_iochannel_write_with_fds(pa_iochannel*io, const void*data, size_t l, int nfd, const int *fds) {
376 pa_assert(io);
379 pa_assert(io->ofd >= 0);
408 if ((r = sendmsg(io->ofd, &mh, MSG_NOSIGNAL)) >= 0) {
409 io->writable = io->hungup = false;
410 enable_events(io);
415 ssize_t pa_iochannel_read_with_ancil_data(pa_iochannel*io, void*data, size_t l, pa_cmsg_ancil_data *ancil_data) {
424 pa_assert(io);
427 pa_assert(io->ifd >= 0);
430 if (io->ifd_type > 0) {
433 return pa_iochannel_read(io, data, l);
445 if ((r = recvmsg(io->ifd, &mh, 0)) >= 0) {
484 io->readable = io->hungup = false;
485 enable_events(io);
489 io->ifd_type = 1;
490 return pa_iochannel_read_with_ancil_data(io, data, l, ancil_data);
498 void pa_iochannel_set_callback(pa_iochannel*io, pa_iochannel_cb_t _callback, void *userdata) {
499 pa_assert(io);
501 io->callback = _callback;
502 io->userdata = userdata;
505 void pa_iochannel_set_noclose(pa_iochannel*io, bool b) {
506 pa_assert(io);
508 io->no_close = b;
511 void pa_iochannel_socket_peer_to_string(pa_iochannel*io, char*s, size_t l) {
512 pa_assert(io);
516 pa_socket_peer_to_string(io->ifd, s, l);
519 int pa_iochannel_socket_set_rcvbuf(pa_iochannel *io, size_t l) {
520 pa_assert(io);
522 return pa_socket_set_rcvbuf(io->ifd, l);
525 int pa_iochannel_socket_set_sndbuf(pa_iochannel *io, size_t l) {
526 pa_assert(io);
528 return pa_socket_set_sndbuf(io->ofd, l);
531 pa_mainloop_api* pa_iochannel_get_mainloop_api(pa_iochannel *io) {
532 pa_assert(io);
534 return io->mainloop;
537 int pa_iochannel_get_recv_fd(pa_iochannel *io) {
538 pa_assert(io);
540 return io->ifd;
543 int pa_iochannel_get_send_fd(pa_iochannel *io) {
544 pa_assert(io);
546 return io->ofd;
549 bool pa_iochannel_socket_is_local(pa_iochannel *io) {
550 pa_assert(io);
552 if (pa_socket_is_local(io->ifd))
555 if (io->ifd != io->ofd)
556 if (pa_socket_is_local(io->ofd))