static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata) { pa_context *c = userdata; int saved_errno = errno; pa_assert(client); pa_assert(c); pa_assert(c->state == PA_CONTEXT_CONNECTING); pa_context_ref(c); pa_socket_client_unref(client); c->client = NULL; if (!io) { /* Try the next item in the list */ if (saved_errno == ECONNREFUSED || saved_errno == ETIMEDOUT || saved_errno == EHOSTUNREACH) { try_next_connection(c); goto finish; } pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); goto finish; } setup_context(c, io); finish: pa_context_unref(c); }
static void context_unlink(pa_context *c) { pa_stream *s; pa_assert(c); s = c->streams ? pa_stream_ref(c->streams) : NULL; while (s) { pa_stream *n = s->next ? pa_stream_ref(s->next) : NULL; pa_stream_set_state(s, c->state == PA_CONTEXT_FAILED ? PA_STREAM_FAILED : PA_STREAM_TERMINATED); pa_stream_unref(s); s = n; } while (c->operations) pa_operation_cancel(c->operations); if (c->pdispatch) { pa_pdispatch_unref(c->pdispatch); c->pdispatch = NULL; } if (c->pstream) { pa_pstream_unlink(c->pstream); pa_pstream_unref(c->pstream); c->pstream = NULL; } if (c->client) { pa_socket_client_unref(c->client); c->client = NULL; } reset_callbacks(c); }
void pa__done(pa_module*m) { struct userdata *u; pa_assert(m); if (!(u = m->userdata)) return; if (u->sink) pa_sink_unlink(u->sink); if (u->thread) { pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); pa_thread_free(u->thread); } pa_thread_mq_done(&u->thread_mq); if (u->sink) pa_sink_unref(u->sink); if (u->io) pa_iochannel_free(u->io); if (u->rtpoll_item) pa_rtpoll_item_free(u->rtpoll_item); if (u->rtpoll) pa_rtpoll_free(u->rtpoll); if (u->memchunk.memblock) pa_memblock_unref(u->memchunk.memblock); if (u->client) pa_socket_client_unref(u->client); pa_xfree(u->read_data); pa_xfree(u->write_data); if (u->smoother) pa_smoother_free(u->smoother); if (u->fd >= 0) pa_close(u->fd); pa_xfree(u); }
static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata) { pa_rtsp_client *c = userdata; union { struct sockaddr sa; struct sockaddr_in in; struct sockaddr_in6 in6; } sa; socklen_t sa_len = sizeof(sa); pa_assert(sc); pa_assert(c); pa_assert(STATE_CONNECT == c->state); pa_assert(c->sc == sc); pa_socket_client_unref(c->sc); c->sc = NULL; if (!io) { pa_log("Connection failed: %s", pa_cstrerror(errno)); return; } pa_assert(!c->ioline); c->ioline = pa_ioline_new(io); pa_ioline_set_callback(c->ioline, line_callback, c); /* Get the local IP address for use externally */ if (0 == getsockname(pa_iochannel_get_recv_fd(io), &sa.sa, &sa_len)) { char buf[INET6_ADDRSTRLEN]; const char *res = NULL; if (AF_INET == sa.sa.sa_family) { if ((res = inet_ntop(sa.sa.sa_family, &sa.in.sin_addr, buf, sizeof(buf)))) { c->localip = pa_xstrdup(res); } } else if (AF_INET6 == sa.sa.sa_family) { if ((res = inet_ntop(AF_INET6, &sa.in6.sin6_addr, buf, sizeof(buf)))) { c->localip = pa_sprintf_malloc("[%s]", res); } } } pa_log_debug("Established RTSP connection from local ip %s", c->localip); if (c->callback) c->callback(c, c->state, NULL, c->userdata); }
static void on_connection(pa_socket_client *c, pa_iochannel*io, void *userdata) { struct userdata *u = userdata; pa_socket_client_unref(u->client); u->client = NULL; if (!io) { pa_log("Connection failed: %s", pa_cstrerror(errno)); pa_module_unload_request(u->module, TRUE); return; } pa_assert(!u->io); u->io = io; pa_iochannel_set_callback(u->io, io_callback, u); pa_log_debug("Connection established, authenticating ..."); }
void pa_rtsp_client_free(pa_rtsp_client* c) { pa_assert(c); if (c->sc) pa_socket_client_unref(c->sc); pa_rtsp_disconnect(c); pa_xfree(c->hostname); pa_xfree(c->url); pa_xfree(c->localip); pa_xfree(c->session); pa_xfree(c->transport); pa_xfree(c->last_header); if (c->header_buffer) pa_strbuf_free(c->header_buffer); if (c->response_headers) pa_headerlist_free(c->response_headers); pa_headerlist_free(c->headers); pa_xfree(c); }