X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afs.c;h=8a60166fe7e42d5f5762cb46547a9413df6bd342;hp=c36f86b8aec855e07e6149a2b7e724c9f1e7326e;hb=2bb9fcbfa99cf30a6f46ba33fd95c0a456a225cc;hpb=613b848d6d5a1dc7e714582c74bc98ffed1d84a0 diff --git a/afs.c b/afs.c index c36f86b8..8a60166f 100644 --- a/afs.c +++ b/afs.c @@ -486,17 +486,27 @@ int open_next_audio_file(void) struct audio_file_data afd; int ret, shmid; char buf[8]; - + long score; +again: PARA_NOTICE_LOG("getting next audio file\n"); - ret = score_get_best(&aft_row, &afd.score); - if (ret < 0) - return ret; - ret = open_and_update_audio_file(aft_row, &afd); - if (ret < 0) - return ret; + ret = score_get_best(&aft_row, &score); + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + goto no_admissible_files; + } + ret = open_and_update_audio_file(aft_row, score, &afd); + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + ret = score_delete(aft_row); + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + goto no_admissible_files; + } + goto again; + } shmid = ret; if (!write_ok(server_socket)) { - PARA_EMERG_LOG("afs_socket not writable\n"); + ret = -E_AFS_SOCKET; goto destroy; } *(uint32_t *)buf = NEXT_AUDIO_FILE; @@ -505,10 +515,13 @@ int open_next_audio_file(void) close(afd.fd); if (ret >= 0) return ret; - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); destroy: shm_destroy(shmid); return ret; +no_admissible_files: + *(uint32_t *)buf = NO_ADMISSIBLE_FILES; + *(uint32_t *)(buf + 4) = (uint32_t)0; + return send_bin_buffer(server_socket, buf, 8); } /* Never fails if arg == NULL */ @@ -754,9 +767,13 @@ static void register_signal_task(void) static struct list_head afs_client_list; +/** Describes on connected afs client. */ struct afs_client { + /** Position in the afs client list. */ struct list_head node; + /** The socket file descriptor for this client. */ int fd; + /** The time the client connected. */ struct timeval connect_time; }; @@ -841,8 +858,10 @@ static void execute_server_command(void) PARA_DEBUG_LOG("received: %s\n", buf); if (!strcmp(buf, "new")) { ret = open_next_audio_file(); - if (ret < 0) - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + if (ret < 0) { + PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); + unregister_tasks(); + } return; } PARA_ERROR_LOG("unknown command\n");