Move UDP port cloure to the RTSP thread, don't allow calls to mdns_* to be cancelled. Remove usage of (p)select in rtsp thread handling.

This commit is contained in:
Mike Brady
2018-11-30 14:55:04 +00:00
parent 0eac2b9cb3
commit a5c65ceced
3 changed files with 36 additions and 24 deletions
+4 -9
View File
@@ -1448,14 +1448,6 @@ void player_thread_cleanup_handler(void *arg) {
pthread_join(conn->rtp_audio_thread, NULL);
debug(2, "Audio thread terminated.");
debug(2, "Closing timing, control and audio sockets...");
if (conn->control_socket)
close(conn->control_socket);
if (conn->timing_socket)
close(conn->timing_socket);
if (conn->audio_socket)
close(conn->audio_socket);
if (conn->outbuf) {
free(conn->outbuf);
conn->outbuf = NULL;
@@ -1736,7 +1728,9 @@ void *player_thread_func(void *arg) {
pthread_cleanup_push(player_thread_cleanup_handler, arg); // undo what's been done so far
// stop looking elsewhere for DACP stuff
// stop looking elsewhere for DACP stuff
int oldState;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
#ifdef CONFIG_DACP_CLIENT
// debug(1, "Set dacp server info");
@@ -1753,6 +1747,7 @@ void *player_thread_func(void *arg) {
// almost certainly, this has pthread cancellation points in it -- beware
conn->dapo_private_storage = mdns_dacp_monitor(conn->dacp_id);
#endif
pthread_setcancelstate(oldState, NULL);
// set the default volume to whaterver it was before, as stored in the config airplay_volume
debug(2, "Set initial volume to %f.", config.airplay_volume);
+9 -7
View File
@@ -847,13 +847,15 @@ static uint16_t bind_port(int ip_family, const char *self_ip_address, uint32_t s
if (local_socket == -1)
die("Could not allocate a socket.");
int val = 1;
ret = setsockopt(local_socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
if (ret < 0) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(1, "Error %d: \"%s\". Couldn't set SO_REUSEADDR");
}
/*
int val = 1;
ret = setsockopt(local_socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
if (ret < 0) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
debug(1, "Error %d: \"%s\". Couldn't set SO_REUSEADDR");
}
*/
SOCKADDR myaddr;
int tryCount = 0;
+23 -8
View File
@@ -555,18 +555,21 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
int msg_size = -1;
while (msg_size < 0) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(conn->fd, &readfds);
do {
memory_barrier();
} while (conn->stop == 0 &&
pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
/*
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(conn->fd, &readfds);
do {
memory_barrier();
} while (conn->stop == 0 &&
pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
*/
if (conn->stop != 0) {
debug(3, "RTSP conversation thread %d shutdown requested.", conn->connection_number);
reply = rtsp_read_request_response_immediate_shutdown_requested;
goto shutdown;
}
nread = read(conn->fd, buf + inbuf, buflen - inbuf);
if (nread == 0) {
@@ -640,6 +643,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
warning_message_sent = 1;
}
}
/*
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(conn->fd, &readfds);
@@ -647,6 +652,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
memory_barrier();
} while (conn->stop == 0 &&
pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
*/
if (conn->stop != 0) {
debug(1, "RTSP shutdown requested.");
reply = rtsp_read_request_response_immediate_shutdown_requested;
@@ -2070,6 +2077,14 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
if (conn->player_thread)
player_stop(conn);
debug(3, "Closing timing, control and audio sockets...");
if (conn->control_socket)
close(conn->control_socket);
if (conn->timing_socket)
close(conn->timing_socket);
if (conn->audio_socket)
close(conn->audio_socket);
if (conn->fd > 0) {
debug(3, "Connection %d: closing fd %d.", conn->connection_number, conn->fd);
close(conn->fd);
@@ -2517,7 +2532,7 @@ void rtsp_listen_loop(void) {
// conn->thread = rtsp_conversation_thread;
// conn->stop = 0; // record's memory has been zeroed
// conn->authorized = 0; // record's memory has been zeroed
fcntl(conn->fd, F_SETFL, O_NONBLOCK);
// fcntl(conn->fd, F_SETFL, O_NONBLOCK);
ret = pthread_create(&conn->thread, NULL, rtsp_conversation_thread_func,
conn); // also acts as a memory barrier