X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=vss.c;h=acac159537171c95560e5582dfef538554f04f23;hb=1d8ea0d046caf28d138fe510e2b3e2f20609071a;hp=1be4cd15d1db262dd5f79a43b19e7bba09f2087a;hpb=97727c2e95cce064e03f495e97119cae447397d7;p=paraslash.git diff --git a/vss.c b/vss.c index 1be4cd15..acac1595 100644 --- a/vss.c +++ b/vss.c @@ -182,14 +182,8 @@ static struct timeval *vss_compute_timeout(void) static void vss_eof(void) { struct timeval now; - int i; char *tmp; - if (!map) { - for (i = 0; senders[i].name; i++) - senders[i].shutdown_clients(); - return; - } if (mmd->new_vss_status_flags & VSS_NOMORE) mmd->new_vss_status_flags = VSS_NEXT; gettimeofday(&now, NULL); @@ -262,6 +256,19 @@ enum afs_socket_status { static enum afs_socket_status afsss; +static int need_to_request_new_audio_file(void) +{ + if (map) /* have audio file */ + return 0; + if (!vss_playing()) /* don't need one */ + return 0; + if (mmd->new_vss_status_flags & VSS_NOMORE) + return 0; + if (afsss == AFS_SOCKET_AFD_PENDING) /* already requested one */ + return 0; + return 1; +} + /** * Compute the timeout for para_server's main select-loop. * @@ -286,48 +293,39 @@ static enum afs_socket_status afsss; struct timeval *vss_preselect(fd_set *rfds, fd_set *wfds, int *max_fileno) { int i; - struct timeval *tv; + struct timeval now; - para_fd_set(afs_socket, rfds, max_fileno); - if (!map) + if (!map || vss_next() || vss_paused() || vss_repos()) for (i = 0; senders[i].name; i++) senders[i].shutdown_clients(); - else { - if (vss_next()) { - vss_eof(); - return vss_compute_timeout(); - } + if (vss_next()) { + vss_eof(); + goto out; } - if (vss_paused() || vss_repos()) { - for (i = 0; senders[i].name; i++) - senders[i].shutdown_clients(); - if (map) { - struct timeval now; + if (vss_paused()) { + if (mmd->chunks_sent) { gettimeofday(&now, NULL); - if (!vss_paused() || mmd->chunks_sent) - tv_add(&mmd->afd.afhi.eof_tv, &now, &eof_barrier); - if (vss_repos()) - tv_add(&now, &announce_tv, &data_send_barrier); + tv_add(&mmd->afd.afhi.eof_tv, &now, &eof_barrier); } mmd->chunks_sent = 0; + goto out; } if (vss_repos()) { - mmd->new_vss_status_flags &= ~(VSS_REPOS); + gettimeofday(&now, NULL); + tv_add(&now, &announce_tv, &data_send_barrier); + tv_add(&mmd->afd.afhi.eof_tv, &now, &eof_barrier); + mmd->chunks_sent = 0; mmd->current_chunk = mmd->repos_request; + mmd->new_vss_status_flags &= ~VSS_REPOS; } - tv = vss_compute_timeout(); - if (tv) - return tv; - if (!map && vss_playing() && - !(mmd->new_vss_status_flags & VSS_NOMORE)) { - if (afsss == AFS_SOCKET_READY || - afsss == AFS_SOCKET_CHECK_FOR_WRITE) { - PARA_DEBUG_LOG("ready and playing, but no audio file\n"); - para_fd_set(afs_socket, wfds, max_fileno); - afsss = AFS_SOCKET_CHECK_FOR_WRITE; - } - } - return tv; +out: + if (need_to_request_new_audio_file()) { + PARA_DEBUG_LOG("ready and playing, but no audio file\n"); + para_fd_set(afs_socket, wfds, max_fileno); + afsss = AFS_SOCKET_CHECK_FOR_WRITE; + } else + para_fd_set(afs_socket, rfds, max_fileno); + return vss_compute_timeout(); } static int recv_afs_msg(int *fd, uint32_t *code, uint32_t *data) @@ -420,14 +418,18 @@ void vss_post_select(fd_set *rfds, fd_set *wfds) { int ret; - if (FD_ISSET(afs_socket, rfds)) - recv_afs_result(); - if (afsss != AFS_SOCKET_CHECK_FOR_WRITE || !FD_ISSET(afs_socket, wfds)) + if (afsss != AFS_SOCKET_CHECK_FOR_WRITE) { + if (FD_ISSET(afs_socket, rfds)) + recv_afs_result(); + return; + } + if (!FD_ISSET(afs_socket, wfds)) return; PARA_NOTICE_LOG("requesting new fd from afs\n"); ret = send_buffer(afs_socket, "new"); afsss = AFS_SOCKET_AFD_PENDING; } + /** * Get the data of the given chunk. * @@ -478,7 +480,7 @@ void vss_send_chunk(void) mmd->new_vss_status_flags &= ~VSS_REPOS; if (mmd->current_chunk >= mmd->afd.afhi.chunks_total) { /* eof */ mmd->new_vss_status_flags |= VSS_NEXT; - return vss_eof(); + return; } /* * We call the send function also in case of empty chunks as they