diff --git a/src/modules/mixer/Pulse.h b/src/modules/mixer/Pulse.h index dc6e1a4dd..bbfabde3a 100644 --- a/src/modules/mixer/Pulse.h +++ b/src/modules/mixer/Pulse.h @@ -37,6 +37,7 @@ void pulse_shutdown(void); Pulse *pulse_new(void); Eina_Bool pulse_connect(Pulse *conn); +void pulse_disconnect(Pulse *conn); void pulse_free(Pulse *conn); void pulse_cb_set(Pulse *conn, uint32_t tagnum, Pulse_Cb cb); void pulse_server_info_free(Pulse_Server_Info *ev); diff --git a/src/modules/mixer/msg.c b/src/modules/mixer/msg.c index 6b6a00233..adb69526a 100644 --- a/src/modules/mixer/msg.c +++ b/src/modules/mixer/msg.c @@ -33,8 +33,7 @@ msg_recv_creds(Pulse *conn, Pulse_Tag *tag) if (errno != EAGAIN) { ERR("%d: %s", errno, strerror(errno)); - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; + pulse_disconnect(conn); } } else @@ -84,8 +83,7 @@ msg_recv(Pulse *conn, Pulse_Tag *tag) if (errno != EAGAIN) { ERR("%d: %s", errno, strerror(errno)); - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; + pulse_disconnect(conn); } } else @@ -138,8 +136,7 @@ msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag) if (errno != EAGAIN) { ERR("%d: %s", errno, strerror(errno)); - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; + pulse_disconnect(conn); } } else @@ -165,8 +162,7 @@ msg_send_creds(Pulse *conn, Pulse_Tag *tag) if (errno != EAGAIN) { ERR("%d: %s", errno, strerror(errno)); - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; + pulse_disconnect(conn); } } else @@ -198,8 +194,7 @@ msg_send(Pulse *conn, Pulse_Tag *tag) if (errno != EAGAIN) { ERR("%d: %s", errno, strerror(errno)); - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; + pulse_disconnect(conn); } } else diff --git a/src/modules/mixer/pa.c b/src/modules/mixer/pa.c index ae628d629..497beb8f5 100644 --- a/src/modules/mixer/pa.c +++ b/src/modules/mixer/pa.c @@ -196,11 +196,7 @@ pulse_recv(Pulse *conn, Ecore_Fd_Handler *fdh) if (!tag->dsize) { ERR("Kicked!"); - conn->state = PA_STATE_INIT; - ecore_main_fd_handler_del(conn->fdh); - conn->fdh = NULL; - close(conn->fd); - ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL); + pulse_disconnect(conn); return NULL; } tag->data = malloc(tag->dsize); @@ -274,6 +270,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh) if (!wprev->auth) msg_sendmsg_creds(conn, wprev); + if (wprev->auth && msg_send(conn, wprev)) { @@ -354,10 +351,7 @@ con(Pulse *conn, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev) fd = ecore_con_server_fd_get(ev->server); if (fd == -1) { - conn->state = PA_STATE_INIT; - ecore_con_server_del(ev->server); - conn->svr = NULL; - ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL); + pulse_disconnect(conn); return ECORE_CALLBACK_RENEW; } conn->fd = dup(fd); @@ -752,6 +746,27 @@ pulse_connect(Pulse *conn) return !!conn->svr; } +void +pulse_disconnect(Pulse *conn) +{ + EINA_SAFETY_ON_NULL_RETURN(conn); + if (conn->state == PA_STATE_INIT) return; + conn->state = PA_STATE_INIT; + if (conn->fdh) + { + ecore_main_fd_handler_del(conn->fdh); + conn->fdh = NULL; + close(conn->fd); + conn->fd = -1; + } + else if (conn->svr) + { + ecore_con_server_del(conn->svr); + conn->svr = NULL; + } + ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL); +} + void pulse_server_info_free(Pulse_Server_Info *ev) {