From b087c1356e3eebf656aa1c783ff7e50c9de5a229 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 30 Dec 2022 15:08:59 +0100 Subject: [PATCH] Consolidate EOF error codes. Currently we have ~15 error codes which indicate an EOF condition. One should suffice, so drop all codes except the generic E_EOF and use that everywhere. --- afh_recv.c | 4 ++-- alsa_write.c | 2 +- amp_filter.c | 2 +- ao_write.c | 4 ++-- audioc.c | 2 +- buffer_tree.c | 2 +- client.c | 2 -- client_common.c | 4 ++-- compress_filter.c | 2 +- error.h | 15 --------------- fecdec_filter.c | 2 +- flacdec_filter.c | 4 ++-- interactive.c | 4 ++-- mp3dec_filter.c | 4 ++-- oggdec_filter.c | 2 +- opusdec_filter.c | 2 +- oss_write.c | 2 +- play.c | 3 +-- resample_filter.c | 2 +- sched.c | 2 +- sync_filter.c | 2 +- udp_recv.c | 4 ++-- wav_filter.c | 2 +- wmadec_filter.c | 2 +- write.c | 2 +- 25 files changed, 30 insertions(+), 48 deletions(-) diff --git a/afh_recv.c b/afh_recv.c index eebac67f..8449e787 100644 --- a/afh_recv.c +++ b/afh_recv.c @@ -205,7 +205,7 @@ static int afh_recv_post_monitor(__a_unused struct sched *s, void *context) PARA_DEBUG_LOG("adding %u bytes\n", len); btr_add_output_dont_free(start, len, btrn); } - ret = -E_RECV_EOF; + ret = -E_EOF; goto out; } if (pard->current_chunk == pard->first_chunk) @@ -226,7 +226,7 @@ static int afh_recv_post_monitor(__a_unused struct sched *s, void *context) PARA_DEBUG_LOG("adding chunk %u\n", pard->current_chunk); btr_add_output_dont_free(start, len, btrn); if (pard->current_chunk >= pard->last_chunk) { - ret = -E_RECV_EOF; + ret = -E_EOF; goto out; } pard->current_chunk++; diff --git a/alsa_write.c b/alsa_write.c index 92d6cb70..53d7b1b4 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -277,7 +277,7 @@ again: bytes = btr_next_buffer(btrn, &data); if (ret < 0 || bytes < wn->min_iqs) { /* eof */ assert(btr_no_parent(btrn)); - ret = -E_WRITE_COMMON_EOF; + ret = -E_EOF; if (!pad) goto err; /* wait until pending frames are played */ diff --git a/amp_filter.c b/amp_filter.c index 360e3fc2..be69ad67 100644 --- a/amp_filter.c +++ b/amp_filter.c @@ -67,7 +67,7 @@ next_buffer: in_bytes = btr_next_buffer(btrn, (char **)&in); len = in_bytes / 2; if (len == 0) { /* eof and in_bytes == 1 */ - ret = -E_AMP_EOF; + ret = -E_EOF; goto err; } diff --git a/ao_write.c b/ao_write.c index 950f8f73..43a58dd6 100644 --- a/ao_write.c +++ b/ao_write.c @@ -266,7 +266,7 @@ static void *aow_play(void *priv) if (frames > 0) break; /* eof and less than a single frame available */ - ret = -E_WRITE_COMMON_EOF; + ret = -E_EOF; goto fail; } /* @@ -388,7 +388,7 @@ static int aow_post_monitor(__a_unused struct sched *s, void *context) if (!wn->btrn) { if (!pawd->thread_btrn) { pthread_join(pawd->thread, NULL); - return -E_AO_EOF; + return -E_EOF; } PARA_INFO_LOG("waiting for play thread to terminate\n"); return 0; diff --git a/audioc.c b/audioc.c index d6c14cbc..f2e4cb91 100644 --- a/audioc.c +++ b/audioc.c @@ -175,7 +175,7 @@ static int audioc_post_monitor(struct sched *s, void *context) ret = recv_bin_buffer(at->fd, buf, bufsize); PARA_DEBUG_LOG("recv: %d\n", ret); if (ret == 0) - ret = -E_AUDIOC_EOF; + ret = -E_EOF; if (ret < 0) goto out; btr_add_output(buf, ret, at->btrn); diff --git a/buffer_tree.c b/buffer_tree.c index 05cdfa83..35353f56 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -1208,7 +1208,7 @@ int btr_node_status(struct btr_node *btrn, size_t min_iqs, if (type != BTR_NT_LEAF && btr_no_children(btrn)) return -E_BTR_NO_CHILD; if (type != BTR_NT_ROOT && btr_eof(btrn)) - return -E_BTR_EOF; + return -E_EOF; if (btr_get_output_queue_size(btrn) > BTRN_MAX_PENDING) return 0; diff --git a/client.c b/client.c index a6aee0f8..84b7580c 100644 --- a/client.c +++ b/client.c @@ -666,8 +666,6 @@ int main(int argc, char *argv[]) /* these are not errors */ case -E_SERVER_CMD_SUCCESS: case -E_EOF: - case -E_SERVER_EOF: - case -E_BTR_EOF: ret = 0; break; default: ret = -E_SERVER_CMD_FAILURE; diff --git a/client_common.c b/client_common.c index 95e59fd2..2a6b47d6 100644 --- a/client_common.c +++ b/client_common.c @@ -398,12 +398,12 @@ static int client_post_monitor(struct sched *s, void *context) char *buf2; size_t sz; ret = btr_node_status(ct->btrn[1], 0, BTR_NT_LEAF); - if (ret == -E_BTR_EOF) { + if (ret == -E_EOF) { /* empty blob data packet indicates EOF */ PARA_INFO_LOG("blob sent\n"); ret = send_sb(ct, 1, NULL, 0, SBD_BLOB_DATA, true); if (ret >= 0) - ret = -E_BTR_EOF; + ret = -E_EOF; } if (ret < 0) goto close1; diff --git a/compress_filter.c b/compress_filter.c index a6a00191..1bce35f5 100644 --- a/compress_filter.c +++ b/compress_filter.c @@ -59,7 +59,7 @@ next_buffer: btr_merge(btrn, fn->min_iqs); length = btr_next_buffer(btrn, &inbuf) & ~(size_t)1; if (length == 0) { /* eof and 1 byte available */ - ret = -E_COMPRESS_EOF; + ret = -E_EOF; goto err; } ip = (int16_t *)inbuf; diff --git a/error.h b/error.h index 0e815444..94f315ce 100644 --- a/error.h +++ b/error.h @@ -19,13 +19,11 @@ PARA_ERROR(ALSA_MIX_OPEN, "could not open mixer"), \ PARA_ERROR(ALSA_MIX_RANGE, "value control element out of range"), \ PARA_ERROR(ALSA_MIX_SET_VAL, "could not set control element state"), \ - PARA_ERROR(AMP_EOF, "amp: end of file"), \ PARA_ERROR(AMP_ZERO_AMP, "no amplification necessary"), \ PARA_ERROR(AO_APPEND_OPTION, "ao append option: memory allocation failure"), \ PARA_ERROR(AO_BAD_DRIVER, "ao: invalid driver"), \ PARA_ERROR(AO_BAD_OPTION, "ao option is not of type key:value"), \ PARA_ERROR(AO_DEFAULT_DRIVER, "ao: no usable output device"), \ - PARA_ERROR(AO_EOF, "ao: end of file"), \ PARA_ERROR(AO_FILE_NOT_SUPP, "ao: file io drivers not supported"), \ PARA_ERROR(AO_OPEN_LIVE, "ao: could not open audio device"), \ PARA_ERROR(AO_PLAY, "ao_play() failed"), \ @@ -36,7 +34,6 @@ PARA_ERROR(ATOI_OVERFLOW, "value too large"), \ PARA_ERROR(ATTR_SYNTAX, "attribute syntax error"), \ PARA_ERROR(ATT_TABLE_FULL, "no more space left in attribute table"), \ - PARA_ERROR(AUDIOC_EOF, "audioc: end of file"), \ PARA_ERROR(AUDIOD_OFF, "audiod switched off"), \ PARA_ERROR(AUDIOD_SIGNAL, "caught deadly signal"), \ PARA_ERROR(AUDIOD_TERM, "terminating on user request"), \ @@ -65,7 +62,6 @@ PARA_ERROR(BIGNUM, "bignum error"), \ PARA_ERROR(BLINDING, "failed to activate key blinding"), \ PARA_ERROR(BLOB_SYNTAX, "blob syntax error"), \ - PARA_ERROR(BTR_EOF, "buffer tree: end of file"), \ PARA_ERROR(BTR_NAVAIL, "btr node: value currently unavailable"), \ PARA_ERROR(BTR_NO_CHILD, "btr node has no children"), \ PARA_ERROR(CHILD_CONTEXT, "now running in child context"), \ @@ -73,7 +69,6 @@ PARA_ERROR(CLIENT_SYNTAX, "syntax error"), \ PARA_ERROR(CLIENT_WRITE, "client write error"), \ PARA_ERROR(COMMAND_SYNTAX, "syntax error in command"), \ - PARA_ERROR(COMPRESS_EOF, "compress: end of file"), \ PARA_ERROR(CREATE_OPUS_DECODER, "could not create opus decoder"), \ PARA_ERROR(DCCP_OVERRUN, "dccp output buffer buffer overrun"), \ PARA_ERROR(DECRYPT, "decrypt error"), \ @@ -84,7 +79,6 @@ PARA_ERROR(EOF, "end of file"), \ PARA_ERROR(EOP, "end of playlist"), \ PARA_ERROR(FEC_BAD_IDX, "invalid index vector"), \ - PARA_ERROR(FECDEC_EOF, "received eof packet"), \ PARA_ERROR(FECDEC_OVERRUN, "fecdec output buffer overrun"), \ PARA_ERROR(FEC_PARMS, "invalid fec parameters"), \ PARA_ERROR(FEC_PIVOT, "pivot column not found"), \ @@ -97,7 +91,6 @@ PARA_ERROR(FLAC_CHAIN_READ, "could not read meta chain"), \ PARA_ERROR(FLACDEC_DECODER_ALLOC, "could not allocate stream decoder"), \ PARA_ERROR(FLACDEC_DECODER_INIT, "could not init stream decoder"), \ - PARA_ERROR(FLACDEC_EOF, "flacdec encountered end of file condition"), \ PARA_ERROR(FLAC_DECODE_POS, "could not get decode position"), \ PARA_ERROR(FLAC_ITER_ALLOC, "could not allocate meta iterator"), \ PARA_ERROR(FLAC_REPLACE_COMMENT, "could not replace vorbis comment"), \ @@ -115,7 +108,6 @@ PARA_ERROR(HEADER_BITRATE, "invalid header bitrate"), \ PARA_ERROR(HEADER_FREQ, "invalid header frequency"), \ PARA_ERROR(HTTP_RECV_OVERRUN, "http_recv: output buffer overrun"), \ - PARA_ERROR(I9E_EOF, "end of input"), \ PARA_ERROR(I9E_SETUPTERM, "failed to set up terminal"), \ PARA_ERROR(I9E_TERM_RQ, "received termination request"), \ PARA_ERROR(ID3_ATTACH, "could not attach id3 frame"), \ @@ -134,7 +126,6 @@ PARA_ERROR(MISSING_COLON, "syntax error: missing colon"), \ PARA_ERROR(MOOD_PARSE, "mood parse error"), \ PARA_ERROR(MP3DEC_CORRUPT, "too many corrupt frames"), \ - PARA_ERROR(MP3DEC_EOF, "mp3dec: end of file"), \ PARA_ERROR(MP3_INFO, "could not read mp3 info"), \ PARA_ERROR(MP4_READ, "mp4: read error or unexpected end of file"), \ PARA_ERROR(MP4_CORRUPT, "invalid/corrupt mp4 file"), \ @@ -174,10 +165,8 @@ PARA_ERROR(PRIVATE_KEY, "can not read private key"), \ PARA_ERROR(QUEUE, "packet queue overrun"), \ PARA_ERROR(READ_PATTERN, "did not read expected pattern"), \ - PARA_ERROR(RECV_EOF, "end of file"), \ PARA_ERROR(RECVMSG, "recvmsg() failed"), \ PARA_ERROR(REGEX, "regular expression error"), \ - PARA_ERROR(RESAMPLE_EOF, "resample filter: end of file"), \ PARA_ERROR(RSA, "RSA error"), \ PARA_ERROR(RSA_DECODE, "RSA decoding error"), \ PARA_ERROR(SB_PACKET_SIZE, "invalid sideband packet size or protocol error"), \ @@ -187,7 +176,6 @@ PARA_ERROR(SERVER_CMD_FAILURE, "command failed"), \ PARA_ERROR(SERVER_CMD_SUCCESS, "command terminated successfully"), \ PARA_ERROR(SERVER_CRASH, "para_server crashed -- can not live without it"), \ - PARA_ERROR(SERVER_EOF, "connection closed by para_server"), \ PARA_ERROR(SEXP_BUILD, "could not build S-expression"), \ PARA_ERROR(SEXP_DECRYPT, "could not decrypt S-expression"), \ PARA_ERROR(SEXP_ENCRYPT, "could not encrypt S-expression"), \ @@ -231,15 +219,12 @@ PARA_ERROR(VORBIS_COMMENTHEADER, "could not create vorbis comment header"), \ PARA_ERROR(VORBIS, "vorbis synthesis header-in error (not vorbis?)"), \ PARA_ERROR(WAV_BAD_FC, "invalid filter configuration"), \ - PARA_ERROR(WAV_EOF, "wav filter: end of file"), \ PARA_ERROR(WAV_SUCCESS, "successfully wrote wav header"), \ PARA_ERROR(WMA_BAD_PARAMS, "invalid WMA parameters"), \ PARA_ERROR(WMA_BAD_SUPERFRAME, "invalid superframe"), \ PARA_ERROR(WMA_BLOCK_SIZE, "invalid block size"), \ - PARA_ERROR(WMADEC_EOF, "wmadec: end of file"), \ PARA_ERROR(WMA_NO_GUID, "audio stream guid not found"), \ PARA_ERROR(WMA_OUTPUT_SPACE, "insufficient output space"), \ - PARA_ERROR(WRITE_COMMON_EOF, "end of file"), \ /** * This is temporarily defined to expand to its first argument (prefixed by diff --git a/fecdec_filter.c b/fecdec_filter.c index 1d8fbc16..375f4c0a 100644 --- a/fecdec_filter.c +++ b/fecdec_filter.c @@ -360,7 +360,7 @@ static int read_fec_header(char *buf, size_t len, struct fec_header *h) h->bos = read_u8(buf + 22); h->header_stream = read_u8(buf + 23); if (!memcmp(buf, FEC_EOF_PACKET, FEC_EOF_PACKET_LEN)) - return -E_FECDEC_EOF; + return -E_EOF; // PARA_DEBUG_LOG("group %u, slize %u, slices per group: %u\n", // h->group_num, h->slice_num, h->slices_per_group); return 1; diff --git a/flacdec_filter.c b/flacdec_filter.c index f3060f57..fb8ebf15 100644 --- a/flacdec_filter.c +++ b/flacdec_filter.c @@ -232,7 +232,7 @@ static int flacdec_post_monitor(__a_unused struct sched *s, void *context) if (output_queue_full(btrn)) return 0; ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL); - if (ret < 0 && ret != -E_BTR_EOF) /* fatal error */ + if (ret < 0 && ret != -E_EOF) /* fatal error */ goto out; if (ret <= 0 && !pfd->have_more) /* nothing to do */ goto out; @@ -248,7 +248,7 @@ static int flacdec_post_monitor(__a_unused struct sched *s, void *context) pfd->have_more = false; FLAC__stream_decoder_process_single(pfd->decoder); state = FLAC__stream_decoder_get_state(pfd->decoder); - ret = -E_FLACDEC_EOF; + ret = -E_EOF; if (state == FLAC__STREAM_DECODER_END_OF_STREAM) goto out; if (state == FLAC__STREAM_DECODER_ABORTED) { diff --git a/interactive.c b/interactive.c index e367a659..1376cf1d 100644 --- a/interactive.c +++ b/interactive.c @@ -287,7 +287,7 @@ static int i9e_post_monitor(__a_unused struct sched *s, __a_unused void *context char *buf; size_t sz, consumed = 0; - ret = -E_I9E_EOF; + ret = -E_EOF; if (i9ep->input_eof) goto rm_btrn; ret = -E_I9E_TERM_RQ; @@ -306,7 +306,7 @@ static int i9e_post_monitor(__a_unused struct sched *s, __a_unused void *context goto rm_btrn; } if (ret == 0) { - ret = -E_I9E_EOF; + ret = -E_EOF; goto rm_btrn; } buf[1] = '\0'; diff --git a/mp3dec_filter.c b/mp3dec_filter.c index bc8ccdaa..d40df85e 100644 --- a/mp3dec_filter.c +++ b/mp3dec_filter.c @@ -105,7 +105,7 @@ next_frame: mp3dec_consume(btrn, &pmd->stream, len); if (pmd->stream.error == MAD_ERROR_BUFLEN) { if (len == iqs && btr_no_parent(btrn)) { - ret = -E_MP3DEC_EOF; + ret = -E_EOF; goto err; } fn->min_iqs += 100; @@ -127,7 +127,7 @@ decode: goto err; mad_stream_sync(&pmd->stream); if (pmd->stream.error == MAD_ERROR_BUFLEN) { - ret = -E_MP3DEC_EOF; + ret = -E_EOF; if (len == iqs && btr_no_parent(btrn)) goto err; fn->min_iqs += 100; diff --git a/oggdec_filter.c b/oggdec_filter.c index da70d4c0..b1aec4bc 100644 --- a/oggdec_filter.c +++ b/oggdec_filter.c @@ -211,7 +211,7 @@ static int ogg_post_monitor(__a_unused struct sched *s, void *context) ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL); if (ret < 0) { - if (ret != -E_BTR_EOF) /* fatal error */ + if (ret != -E_EOF) /* fatal error */ goto out; if (fn->min_iqs == 0 && !pod->have_more) /* EOF */ goto out; diff --git a/opusdec_filter.c b/opusdec_filter.c index 85287be0..f36990fa 100644 --- a/opusdec_filter.c +++ b/opusdec_filter.c @@ -217,7 +217,7 @@ static int opusdec_post_monitor(__a_unused struct sched *s, void *context) ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL); if (ret < 0) { - if (ret != -E_BTR_EOF) /* fatal error */ + if (ret != -E_EOF) /* fatal error */ goto out; if (!ctx->have_more) /* EOF */ goto out; diff --git a/oss_write.c b/oss_write.c index 96d7b187..4ea85afa 100644 --- a/oss_write.c +++ b/oss_write.c @@ -218,7 +218,7 @@ static int oss_post_monitor(__a_unused struct sched *s, void *context) bytes = btr_next_buffer(btrn, &data); frames = bytes / powd->bytes_per_frame; if (!frames) { /* eof and less than a single frame available */ - ret = -E_WRITE_COMMON_EOF; + ret = -E_EOF; goto out; } ret = 0; diff --git a/play.c b/play.c index 8ee91504..4024c8ea 100644 --- a/play.c +++ b/play.c @@ -230,8 +230,7 @@ static int get_playback_error(void) return 0; if (task_status(pt->rn.task) >= 0) return 0; - if (err == -E_BTR_EOF || err == -E_RECV_EOF || err == -E_EOF - || err == -E_WRITE_COMMON_EOF) + if (err == -E_EOF) return 1; return err; } diff --git a/resample_filter.c b/resample_filter.c index bf28e975..72cb3f62 100644 --- a/resample_filter.c +++ b/resample_filter.c @@ -220,7 +220,7 @@ static int resample_post_monitor(__a_unused struct sched *s, void *context) } btr_merge(btrn, fn->min_iqs); in_bytes = btr_next_buffer(btrn, (char **)&in); - ret = -E_RESAMPLE_EOF; + ret = -E_EOF; num_frames = in_bytes / 2 / ctx->channels; if (num_frames == 0) goto out; diff --git a/sched.c b/sched.c index 07703f92..20822038 100644 --- a/sched.c +++ b/sched.c @@ -179,7 +179,7 @@ int task_reap(struct task **tptr) if (t->status >= 0) return 0; ret = t->status; - PARA_INFO_LOG("reaping %s (%s)\n", t->name, para_strerror(-ret)); + PARA_INFO_LOG("reaping %s: %s\n", t->name, para_strerror(-ret)); /* * With list_for_each_entry_safe() it is only safe to remove the * _current_ list item. Since we are being called from the loop in diff --git a/sync_filter.c b/sync_filter.c index b4710f67..20db1b1d 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -365,7 +365,7 @@ success: ret = -E_SYNC_COMPLETE; /* success */ goto out; fail: - if (ret != -E_BTR_EOF) + if (ret != -E_EOF) PARA_WARNING_LOG("%s\n", para_strerror(-ret)); out: sync_close_buddies(ctx); diff --git a/udp_recv.c b/udp_recv.c index 365b6863..f98a9664 100644 --- a/udp_recv.c +++ b/udp_recv.c @@ -40,14 +40,14 @@ static int udp_check_eof(size_t sz, struct iovec iov[2]) if (memcmp(iov[0].iov_base, FEC_EOF_PACKET, FEC_EOF_PACKET_LEN) != 0) return 0; - return -E_RECV_EOF; + return -E_EOF; } if (memcmp(iov[0].iov_base, FEC_EOF_PACKET, iov[0].iov_len) != 0) return 0; if (memcmp(iov[1].iov_base, &FEC_EOF_PACKET[iov[0].iov_len], FEC_EOF_PACKET_LEN - iov[0].iov_len) != 0) return 0; - return -E_RECV_EOF; + return -E_EOF; } static int udp_recv_post_monitor(__a_unused struct sched *s, void *context) diff --git a/wav_filter.c b/wav_filter.c index 7d6c3714..de4a3e6a 100644 --- a/wav_filter.c +++ b/wav_filter.c @@ -78,7 +78,7 @@ static int wav_post_monitor(__a_unused struct sched *s, void *context) int32_t rate, ch; if (iqs == 0) { - ret = -E_WAV_EOF; + ret = -E_EOF; if (btr_no_parent(btrn)) goto err; return 0; diff --git a/wmadec_filter.c b/wmadec_filter.c index f7ee2c4d..f2ca273c 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -1176,7 +1176,7 @@ next_buffer: return 0; btr_merge(btrn, fn->min_iqs); len = btr_next_buffer(btrn, &in); - ret = -E_WMADEC_EOF; + ret = -E_EOF; if (len < fn->min_iqs) goto err; if (!pwd) { diff --git a/write.c b/write.c index f7018aa1..cb32d391 100644 --- a/write.c +++ b/write.c @@ -104,7 +104,7 @@ static int setup_and_schedule(struct lls_parse_result *lpr) struct writer_node *wn = wns + j; ts = task_status(wn->task); assert(ts < 0); - if (ts != -E_WRITE_COMMON_EOF && ts != -E_BTR_EOF) { + if (ts != -E_EOF) { const char *name = writer_name(wn->wid); PARA_ERROR_LOG("%s: %s\n", name, para_strerror(-ts)); -- 2.39.2