diff --git a/fstrm/control.c b/fstrm/control.c index fbaf78e..28455d6 100644 --- a/fstrm/control.c +++ b/fstrm/control.c @@ -80,9 +80,9 @@ fstrm_control_get_type(struct fstrm_control *c, fstrm_control_type *type) case FSTRM_CONTROL_START: /* FALLTHROUGH */ case FSTRM_CONTROL_STOP: *type = c->type; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; default: - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } } @@ -94,9 +94,9 @@ fstrm_control_set_type(struct fstrm_control *c, fstrm_control_type type) case FSTRM_CONTROL_START: /* FALLTHROUGH */ case FSTRM_CONTROL_STOP: c->type = type; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; default: - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } } @@ -108,9 +108,9 @@ fstrm_control_get_field_content_type(struct fstrm_control *c, if (c->content_type != NULL) { *content_type = c->content_type; *len_content_type = c->len_content_type; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } else { - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } } @@ -120,13 +120,13 @@ fstrm_control_set_field_content_type(struct fstrm_control *c, size_t len_content_type) { if (len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (c->content_type != NULL) my_free(c->content_type); c->len_content_type = len_content_type; c->content_type = my_malloc(len_content_type); memmove(c->content_type, content_type, len_content_type); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -144,35 +144,35 @@ fstrm_control_decode(struct fstrm_control *c, if (flags & FSTRM_CONTROL_FLAG_WITH_HEADER) { /* Read the outer frame length. */ if (!fs_load_be32(&buf, &len, &val)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* The outer frame length must be zero, since this is a control frame. */ if (val != 0) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* Read the control frame length. */ if (!fs_load_be32(&buf, &len, &val)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* Enforce maximum control frame size. */ if (val > FSTRM_MAX_CONTROL_FRAME_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* * Require that the control frame length matches the number of * bytes remaining in 'buf'. */ if (val != len) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } else { /* Enforce maximum control frame size. */ if (len_control_frame > FSTRM_MAX_CONTROL_FRAME_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } /* Read the control frame type. */ if (!fs_load_be32(&buf, &len, &val)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; switch (val) { case FSTRM_CONTROL_ACCEPT: /* FALLTHROUGH */ case FSTRM_CONTROL_START: /* FALLTHROUGH */ @@ -180,20 +180,20 @@ fstrm_control_decode(struct fstrm_control *c, c->type = (fstrm_control_type) val; break; default: - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } /* Read any control frame fields. */ while (len > 0) { /* Read the control frame field type. */ if (!fs_load_be32(&buf, &len, &val)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; switch (val) { case FSTRM_CONTROL_FIELD_CONTENT_TYPE: { /* Read the length of the "Content Type" payload. */ if (!fs_load_be32(&buf, &len, &val)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; c->len_content_type = val; /* @@ -201,27 +201,27 @@ fstrm_control_decode(struct fstrm_control *c, * than 'len', the number of bytes remaining in 'buf'. */ if (c->len_content_type > len) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* Enforce limit on "Content Type" payload length. */ if (c->len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* Read the "Content Type" payload. */ c->content_type = my_malloc(c->len_content_type); if (!fs_load_bytes(c->content_type, c->len_content_type, &buf, &len)) { - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } break; } default: - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } } - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -251,7 +251,7 @@ fstrm_control_encoded_size(struct fstrm_control *c, /* Enforce limit on "Content Type" payload length. */ if (c->len_content_type > FSTRM_MAX_CONTROL_FIELD_CONTENT_TYPE_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* The "Content Type" payload. */ len += c->len_content_type; @@ -259,10 +259,10 @@ fstrm_control_encoded_size(struct fstrm_control *c, /* Sanity check. */ if (len > FSTRM_MAX_CONTROL_FRAME_LENGTH) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; *len_control_frame = len; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -276,7 +276,7 @@ fstrm_control_encode(struct fstrm_control *c, /* Calculate the size of the control frame. */ res = fstrm_control_encoded_size(c, &encoded_size, flags); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return res; /* @@ -284,7 +284,7 @@ fstrm_control_encode(struct fstrm_control *c, * control frame. */ if (*len_control_frame < encoded_size) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* * Now actually serialize the control frame. @@ -295,7 +295,7 @@ fstrm_control_encode(struct fstrm_control *c, if (flags & FSTRM_CONTROL_FLAG_WITH_HEADER) { /* Escape: 32-bit BE integer. Zero. */ if (!fs_store_be32(&buf, &len, 0)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* * Frame length: 32-bit BE integer. @@ -305,27 +305,27 @@ fstrm_control_encode(struct fstrm_control *c, * total length. */ if (!fs_store_be32(&buf, &len, encoded_size - 2 * sizeof(uint32_t))) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } /* Control type: 32-bit BE integer. */ if (!fs_store_be32(&buf, &len, c->type)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (c->content_type != NULL) { /* FSTRM_CONTROL_FIELD_CONTENT_TYPE: 32-bit BE integer. */ if (!fs_store_be32(&buf, &len, FSTRM_CONTROL_FIELD_CONTENT_TYPE)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* Length of the "Content Type" payload: 32-bit BE integer. */ if (!fs_store_be32(&buf, &len, c->len_content_type)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* The "Content Type" string itself. */ if (!fs_store_bytes(&buf, &len, c->content_type, c->len_content_type)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } *len_control_frame = encoded_size; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } diff --git a/fstrm/file_writer.c b/fstrm/file_writer.c index 8a899fe..98ba017 100644 --- a/fstrm/file_writer.c +++ b/fstrm/file_writer.c @@ -41,7 +41,7 @@ fs_file_writer_open(void *data) /* Nothing to do if the file descriptor is already opened. */ if (w->opened) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; /* Open the file descriptor. Request close-on-exec if available. */ int open_flags = O_CREAT | O_WRONLY | O_TRUNC; @@ -51,7 +51,7 @@ fs_file_writer_open(void *data) w->fd = open(w->file_path, open_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if (w->fd < 0) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* * Request close-on-exec if available. There is nothing that can be done @@ -70,7 +70,7 @@ fs_file_writer_open(void *data) #endif w->opened = true; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -82,7 +82,7 @@ fs_file_writer_close(void *data) close(w->fd); w->opened = false; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -100,25 +100,25 @@ fs_file_writer_write(void *data, written = writev(w->fd, iov, iovcnt); } while (written == -1 && errno == EINTR); if (written == -1) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (cur == 0 && written == (ssize_t) nbytes) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; while (written >= (ssize_t) iov[cur].iov_len) written -= iov[cur++].iov_len; if (cur == iovcnt) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; iov[cur].iov_base = (void *) ((char *) iov[cur].iov_base + written); iov[cur].iov_len -= written; } } else { - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -131,10 +131,10 @@ fs_file_writer_create(struct fstrm_io *io __attribute__((__unused__)), (const struct fstrm_file_writer_options *) opt; if (wopt->magic != FS_FILE_WRITER_OPTIONS_MAGIC) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (wopt->file_path == NULL) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; w = my_calloc(1, sizeof(*w)); w->file_path = my_strdup(wopt->file_path); @@ -142,7 +142,7 @@ fs_file_writer_create(struct fstrm_io *io __attribute__((__unused__)), (void) fs_file_writer_open(w); *data = w; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -152,7 +152,7 @@ fs_file_writer_destroy(void *data) (void) fs_file_writer_close(w); my_free(w->file_path); my_free(w); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } struct fstrm_file_writer_options * diff --git a/fstrm/fstrm.c b/fstrm/fstrm.c index 8f07e20..fe04cd0 100644 --- a/fstrm/fstrm.c +++ b/fstrm/fstrm.c @@ -187,7 +187,7 @@ fstrm_io_init(const struct fstrm_io_options *opt, char **err) * method will be called in fstrm_io_destroy(). */ res = io->opt.writer->create(io, io->opt.writer_options, &io->writer_data); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { if (err != NULL) *err = my_strdup("writer 'create' method failed"); goto err_out; @@ -291,10 +291,10 @@ fstrm_io_submit(struct fstrm_io *io, struct fstrm_queue *q, struct fs_queue_entry entry; if (unlikely(io->shutting_down)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (unlikely(len < 1 || len >= UINT32_MAX || buf == NULL)) - return FSTRM_RES_INVALID; + return fstrm_res_invalid; entry.bytes = buf; entry.be32_len = htonl((uint32_t) len); @@ -304,9 +304,9 @@ fstrm_io_submit(struct fstrm_io *io, struct fstrm_queue *q, if (likely(len > 0) && io->queue_ops->insert(q->q, &entry, &space)) { if (space == io->opt.queue_notify_threshold) pthread_cond_signal(&io->cv); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } else { - return FSTRM_RES_AGAIN; + return fstrm_res_again; } } @@ -327,7 +327,7 @@ fs_io_open(struct fstrm_io *io) { fstrm_res res; res = io->opt.writer->open(io->writer_data); - if (res == FSTRM_RES_SUCCESS) + if (res == fstrm_res_success) io->writable = true; else io->writable = false; @@ -356,7 +356,7 @@ fs_io_write_data(struct fstrm_io *io, res = io->opt.writer->write_data(io->writer_data, iov, iovcnt, total_length); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) (void)fs_io_close(io); return res; } @@ -376,7 +376,7 @@ fs_io_write_control(struct fstrm_io *io, res = io->opt.writer->write_control(io->writer_data, iov, iovcnt, total_length); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) (void)fs_io_close(io); return res; } @@ -500,12 +500,12 @@ fs_io_maybe_connect(struct fstrm_io *io) if (since >= (time_t) io->opt.reconnect_interval) { /* The reconnect interval expired. */ - if (fs_io_open(io) == FSTRM_RES_SUCCESS) { + if (fs_io_open(io) == fstrm_res_success) { /* * The transport has been reopened, so send the * start frame. */ - if (fs_io_write_control_start(io) != FSTRM_RES_SUCCESS) { + if (fs_io_write_control_start(io) != fstrm_res_success) { /* * Writing the control frame failed, so * close the transport. diff --git a/fstrm/fstrm.h b/fstrm/fstrm.h index f32913f..fdeda62 100644 --- a/fstrm/fstrm.h +++ b/fstrm/fstrm.h @@ -144,19 +144,19 @@ * does this. * * If space is available in the queue, fstrm_io_submit() will return - * #FSTRM_RES_SUCCESS, indicating that ownership of the memory allocation for the + * #fstrm_res_success, indicating that ownership of the memory allocation for the * data frame has passed from the caller to the library. The caller must not * reuse or deallocate the memory for the data frame after a successful call to * fstrm_io_submit(). * * Callers must check the return value of fstrm_io_submit(). If this function - * fails, that is, it returns any result code other than #FSTRM_RES_SUCCESS, the + * fails, that is, it returns any result code other than #fstrm_res_success, the * caller must deallocate or otherwise dispose of memory allocated for the data * frame, in order to avoid leaking memory. fstrm_io_submit() can fail with - * #FSTRM_RES_AGAIN if there is currently no space in the circular queue for an + * #fstrm_res_again if there is currently no space in the circular queue for an * additional frame, in which case a later call to fstrm_io_submit() with the * same parameters may succeed. However, if fstrm_io_submit() fails with - * #FSTRM_RES_INVALID, then there is a problem with the parameters and a later + * #fstrm_res_invalid, then there is a problem with the parameters and a later * call will not succeed. * * The following code example shows data frames containing a short sequence of @@ -190,10 +190,10 @@ res = fstrm_io_submit(fio, fq, frame, sizeof(frame_template), fstrm_free_wrapper, NULL); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { // Frame successfully queued. break; - } else if (res == FSTRM_RES_AGAIN) { + } else if (res == fstrm_res_again) { // Queue is full. Try again in a busy loop. continue; } else { @@ -246,16 +246,16 @@ struct fstrm_writer_options; */ typedef enum { /** Success. */ - FSTRM_RES_SUCCESS, + fstrm_res_success, /** Failure. */ - FSTRM_RES_FAILURE, + fstrm_res_failure, /** Resource temporarily unavailable. */ - FSTRM_RES_AGAIN, + fstrm_res_again, /** Parameters were invalid. */ - FSTRM_RES_INVALID, + fstrm_res_invalid, } fstrm_res; /**@}*/ @@ -372,7 +372,7 @@ fstrm_io_get_queue(struct fstrm_io *fio); * the I/O thread has an active output stream opened, the data frame will be * asynchronously written to the output stream. * - * When this function returns #FSTRM_RES_SUCCESS, responsibility for + * When this function returns #fstrm_res_success, responsibility for * deallocating the data frame specified by the `buf` parameter passes to the * `fstrm` library. The caller **MUST** ensure that the `buf` object remains valid * after fstrm_io_submit() returns. The callback function specified by the @@ -404,11 +404,11 @@ fstrm_io_get_queue(struct fstrm_io *fio); * \param free_data * Parameter to pass to `free_func`. * - * \return FSTRM_RES_SUCCESS + * \return fstrm_res_success * The data frame was successfully queued. - * \return FSTRM_RES_AGAIN + * \return fstrm_res_again * The queue is full. - * \return FSTRM_RES_FAILURE + * \return fstrm_res_failure * Permanent failure. */ fstrm_res @@ -783,10 +783,10 @@ my_writer_create(struct fstrm_io *fio, (const struct my_writer_options *) wopt; struct my_writer_state *state = calloc(1, sizeof(*state)); if (!state) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; *data = state; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -794,21 +794,21 @@ my_writer_destroy(void *data) { struct my_writer_state *state = (struct my_writer_state *) data; free(state); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res my_writer_open(void *data) { struct my_writer_state *state = (struct my_writer_state *) data; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res my_writer_close(void *data) { struct my_writer_state *state = (struct my_writer_state *) data; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -817,7 +817,7 @@ my_writer_write_data(void *data, unsigned nbytes) { struct my_writer_state *state = (struct my_writer_state *) data; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } fstrm_res @@ -826,7 +826,7 @@ my_writer_write_control(void *data, unsigned nbytes) { struct my_writer_state *state = (struct my_writer_state *) data; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -867,7 +867,7 @@ my_writer_write_control(void *data, * parameter. * * \return - * #FSTRM_RES_SUCCESS on success, or any other #fstrm_res value on failure. + * #fstrm_res_success on success, or any other #fstrm_res value on failure. */ typedef fstrm_res (*fstrm_writer_create_func)( struct fstrm_io *fio, @@ -884,7 +884,7 @@ typedef fstrm_res (*fstrm_writer_create_func)( * The `data` value returned by the `create` method. * * \return - * #FSTRM_RES_SUCCESS on success, or any other #fstrm_res value on failure. + * #fstrm_res_success on success, or any other #fstrm_res value on failure. */ typedef fstrm_res (*fstrm_writer_destroy_func)(void *data); @@ -906,7 +906,7 @@ typedef fstrm_res (*fstrm_writer_destroy_func)(void *data); * The `data` value returned by the `create` method. * * \return - * #FSTRM_RES_SUCCESS on success, or any other #fstrm_res value on failure. + * #fstrm_res_success on success, or any other #fstrm_res value on failure. */ typedef fstrm_res (*fstrm_writer_open_func)(void *data); @@ -925,7 +925,7 @@ typedef fstrm_res (*fstrm_writer_open_func)(void *data); * The `data` value returned by the `create` method. * * \return - * #FSTRM_RES_SUCCESS on success, or any other #fstrm_res value on failure. + * #fstrm_res_success on success, or any other #fstrm_res value on failure. */ typedef fstrm_res (*fstrm_writer_close_func)(void *data); @@ -945,7 +945,7 @@ typedef fstrm_res (*fstrm_writer_close_func)(void *data); * Total number of bytes described by the `iovec` array. * * \return - * #FSTRM_RES_SUCCESS on success, or any other #fstrm_res value on failure. + * #fstrm_res_success on success, or any other #fstrm_res value on failure. */ typedef fstrm_res (*fstrm_writer_write_func)( void *data, @@ -1431,8 +1431,8 @@ fstrm_control_reset(struct fstrm_control *c); * \param[out] type * Type of the control frame. * - * \return FSTRM_RES_SUCCESS - * \return FSTRM_RES_FAILURE + * \return fstrm_res_success + * \return fstrm_res_failure */ fstrm_res fstrm_control_get_type( @@ -1447,8 +1447,8 @@ fstrm_control_get_type( * \param[in] type * Type of the control frame. * - * \return FSTRM_RES_SUCCESS - * \return FSTRM_RES_FAILURE + * \return fstrm_res_success + * \return fstrm_res_failure */ fstrm_res fstrm_control_set_type( @@ -1468,9 +1468,9 @@ fstrm_control_set_type( * \param[out] len_content_type * The number of bytes in `content_type`. * - * \return FSTRM_RES_SUCCESS + * \return fstrm_res_success * The control frame has a "Content Type" field. - * \return FSTRM_RES_FAILURE + * \return fstrm_res_failure * The control frame does not have a "Content Type" field. */ fstrm_res @@ -1492,9 +1492,9 @@ fstrm_control_get_field_content_type( * \param[in] len_content_type * The number of bytes in `content_type`. * - * \return FSTRM_RES_SUCCESS + * \return fstrm_res_success * The "Content Type" field was successfully set. - * \return FSTRM_RES_FAILURE + * \return fstrm_res_failure * The "Content Type" string is too long. */ fstrm_res @@ -1522,14 +1522,14 @@ decode_control_frame(const void *control_frame, size_t len_control_frame) c = fstrm_control_init(); res = fstrm_control_decode(c, control_frame, len_control_frame, flags); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { puts("fstrm_control_decode() failed."); fstrm_control_destroy(&c); return res; } res = fstrm_control_get_type(c, &c_type); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { puts("fstrm_control_get_type() failed."); fstrm_control_destroy(&c); return res; @@ -1541,13 +1541,13 @@ decode_control_frame(const void *control_frame, size_t len_control_frame) size_t len_content_type; res = fstrm_control_get_field_content_type(c, &content_type, &len_content_type); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { printf("The control frame has a CONTENT_TYPE field of length %zd.\n", len_content_type); } fstrm_control_destroy(&c); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * @@ -1561,8 +1561,8 @@ decode_control_frame(const void *control_frame, size_t len_control_frame) * \param flags * Flags controlling the decoding process. See #fstrm_control_flag. * - * \return FSTRM_RES_SUCCESS - * \return FSTRM_RES_FAILURE + * \return fstrm_res_success + * \return fstrm_res_failure */ fstrm_res fstrm_control_decode( @@ -1604,8 +1604,8 @@ typedef enum { * \param flags * Flags controlling the encoding process. See #fstrm_control_flag. * - * \return FSTRM_RES_SUCCESS - * \return FSTRM_RES_FAILURE + * \return fstrm_res_success + * \return fstrm_res_failure */ fstrm_res fstrm_control_encoded_size( @@ -1629,13 +1629,13 @@ fstrm_control_encoded_size( c = fstrm_control_init(); res = fstrm_control_set_type(c, FSTRM_CONTROL_START); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { // Error handling goes here. } // Calculate the number of bytes needed. res = fstrm_control_encoded_size(c, &len_control_frame, flags); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { // Error handling goes here. } @@ -1648,7 +1648,7 @@ fstrm_control_encoded_size( // Serialize the control frame into the allocated buffer. res = fstrm_control_encode(c, control_frame, &len_control_frame, 0); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { // Error handling goes here. } @@ -1671,13 +1671,13 @@ fstrm_control_encoded_size( c = fstrm_control_init(); res = fstrm_control_set_type(c, FSTRM_CONTROL_START); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { // Error handling. } // Serialize the control frame. res = fstrm_control_encode(c, control_frame, &len_control_frame, 0); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { // Error handling goes here. } @@ -1697,8 +1697,8 @@ fstrm_control_encoded_size( * \param flags * Flags controlling the encoding process. See #fstrm_control_flag. * - * \return FSTRM_RES_SUCCESS - * \return FSTRM_RES_FAILURE + * \return fstrm_res_success + * \return fstrm_res_failure */ fstrm_res fstrm_control_encode( diff --git a/fstrm/unix_writer.c b/fstrm/unix_writer.c index 4336b8e..dd125dd 100644 --- a/fstrm/unix_writer.c +++ b/fstrm/unix_writer.c @@ -42,7 +42,7 @@ fs_unix_writer_open(void *data) /* Nothing to do if the socket is already connected. */ if (w->connected) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; /* Open an AF_UNIX socket. Request socket close-on-exec if available. */ #if defined(SOCK_CLOEXEC) @@ -53,7 +53,7 @@ fs_unix_writer_open(void *data) w->fd = socket(AF_UNIX, SOCK_STREAM, 0); #endif if (w->fd < 0) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; /* * Request close-on-exec if available. There is nothing that can be done @@ -81,18 +81,18 @@ fs_unix_writer_open(void *data) static const int on = 1; if (setsockopt(w->fd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on)) != 0) { close(w->fd); - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } #endif /* Connect the AF_UNIX socket. */ if (connect(w->fd, (struct sockaddr *) &w->sa, sizeof(w->sa)) < 0) { close(w->fd); - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } w->connected = true; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -104,7 +104,7 @@ fs_unix_writer_close(void *data) close(w->fd); w->connected = false; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -126,25 +126,25 @@ fs_unix_writer_write(void *data, written = sendmsg(w->fd, &msg, MSG_NOSIGNAL); } while (written == -1 && errno == EINTR); if (written == -1) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (cur == 0 && written == (ssize_t) nbytes) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; while (written >= (ssize_t) msg.msg_iov[cur].iov_len) written -= msg.msg_iov[cur++].iov_len; if (cur == iovcnt) - return FSTRM_RES_SUCCESS; + return fstrm_res_success; msg.msg_iov[cur].iov_base = (void *) ((char *) msg.msg_iov[cur].iov_base + written); msg.msg_iov[cur].iov_len -= written; } } else { - return FSTRM_RES_FAILURE; + return fstrm_res_failure; } - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -157,13 +157,13 @@ fs_unix_writer_create(struct fstrm_io *io __attribute__((__unused__)), (const struct fstrm_unix_writer_options *) opt; if (wopt->magic != FS_UNIX_WRITER_OPTIONS_MAGIC) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (wopt->socket_path == NULL) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; if (strlen(wopt->socket_path) + 1 > sizeof(w->sa.sun_path)) - return FSTRM_RES_FAILURE; + return fstrm_res_failure; w = my_calloc(1, sizeof(*w)); w->sa.sun_family = AF_UNIX; @@ -172,7 +172,7 @@ fs_unix_writer_create(struct fstrm_io *io __attribute__((__unused__)), (void) fs_unix_writer_open(w); *data = w; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -181,7 +181,7 @@ fs_unix_writer_destroy(void *data) struct fs_unix_writer *w = data; (void) fs_unix_writer_close(w); my_free(w); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } struct fstrm_unix_writer_options * diff --git a/src/fstrm_dump.c b/src/fstrm_dump.c index bb16eef..6ff4e93 100644 --- a/src/fstrm_dump.c +++ b/src/fstrm_dump.c @@ -125,12 +125,12 @@ dump_control_frame(FILE *fp, struct fstrm_control *c) /* Decode the control frame. */ fstrm_control_type type; res = fstrm_control_decode(c, control_frame, len, 0); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return false; /* Print the control frame. */ res = fstrm_control_get_type(c, &type); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return false; fprintf(stderr, "%s [0x%08x] (%u bytes):\n ", fstrm_control_type_to_str(type), type, len); @@ -142,7 +142,7 @@ dump_control_frame(FILE *fp, struct fstrm_control *c) size_t len_content_type; res = fstrm_control_get_field_content_type(c, &content_type, &len_content_type); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { fprintf(stderr, "%s [0x%08x] (%zd bytes):\n ", fstrm_control_field_type_to_str(FSTRM_CONTROL_FIELD_CONTENT_TYPE), FSTRM_CONTROL_FIELD_CONTENT_TYPE, @@ -175,7 +175,7 @@ dump_file(FILE *fp, struct fstrm_control *c) if (!dump_control_frame(fp, c)) return false; res = fstrm_control_get_type(c, &type); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return false; if (type != FSTRM_CONTROL_START) { fprintf(stderr, "%s: unexpected control frame type at beginning of stream\n", @@ -204,12 +204,12 @@ dump_file(FILE *fp, struct fstrm_control *c) /* Decode the control frame. */ res = fstrm_control_decode(c, control_frame, len_control_frame, 0); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return false; /* Print the control frame. */ res = fstrm_control_get_type(c, &type); - if (res != FSTRM_RES_SUCCESS) + if (res != fstrm_res_success) return false; fprintf(stderr, "%s [0x%08x] (%u bytes):\n ", fstrm_control_type_to_str(type), type, diff --git a/t/test_control.c b/t/test_control.c index 681997c..315f62f 100644 --- a/t/test_control.c +++ b/t/test_control.c @@ -284,7 +284,7 @@ decode_control_frame(struct fstrm_control *c, fstrm_control_type type; res = fstrm_control_decode(c, control_frame, len_control_frame, flags); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { printf("Successfully decoded frame (%zd bytes):\n ", len_control_frame); print_string(control_frame, len_control_frame, stdout); @@ -298,7 +298,7 @@ decode_control_frame(struct fstrm_control *c, } res = fstrm_control_get_type(c, &type); - if (res != FSTRM_RES_SUCCESS) { + if (res != fstrm_res_success) { puts(" fstrm_control_get_type() failed."); return res; } @@ -309,19 +309,19 @@ decode_control_frame(struct fstrm_control *c, size_t len_content_type; res = fstrm_control_get_field_content_type(c, &content_type, &len_content_type); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { printf(" The control frame has a CONTENT_TYPE field (%zd bytes): ", len_content_type); print_string(content_type, len_content_type, stdout); putchar('\n'); - } else if (res == FSTRM_RES_FAILURE) { + } else if (res == fstrm_res_failure) { puts(" The control frame does not have a CONTENT_TYPE field."); } else { /* Not reached. */ assert(0); } - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static void @@ -337,14 +337,14 @@ test_reencode_frame(struct fstrm_control *c, size_t len_new_frame = 0, len_new_frame_2 = 0; res = fstrm_control_encoded_size(c, &len_new_frame, flags); - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); printf("Need %zd bytes for new frame.\n", len_new_frame); assert(len_new_frame <= FSTRM_MAX_CONTROL_FRAME_LENGTH); uint8_t new_frame[len_new_frame]; len_new_frame_2 = len_new_frame; res = fstrm_control_encode(c, new_frame, &len_new_frame_2, flags); - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); printf("Successfully encoded a new frame (%zd bytes):\n ", len_new_frame_2); print_string(new_frame, len_new_frame_2, stdout); @@ -371,7 +371,7 @@ test_reencode_frame_static(struct fstrm_control *c, size_t len_new_frame = sizeof(new_frame); res = fstrm_control_encode(c, new_frame, &len_new_frame, flags); - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); assert(len_new_frame <= FSTRM_MAX_CONTROL_FRAME_LENGTH); printf("Successfully encoded a new frame (%zd bytes):\n ", len_new_frame); print_string(new_frame, len_new_frame, stdout); @@ -395,9 +395,9 @@ test_control_test(struct fstrm_control *c, const struct control_test *test) fstrm_control_type type; res = decode_control_frame(c, test->frame, test->len_frame, test->flags); - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); res = fstrm_control_get_type(c, &type); - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); assert(type == test->type); const uint8_t *content_type; @@ -407,12 +407,12 @@ test_control_test(struct fstrm_control *c, const struct control_test *test) if (test->content_type != NULL) { int cmp; - assert(res == FSTRM_RES_SUCCESS); + assert(res == fstrm_res_success); assert(len_content_type == test->len_content_type); cmp = memcmp(content_type, test->content_type, len_content_type); assert(cmp == 0); } else { - assert(res == FSTRM_RES_FAILURE); + assert(res == fstrm_res_failure); } test_reencode_frame(c, test->frame, test->len_frame, test->flags); @@ -444,7 +444,7 @@ test_invalid(struct fstrm_control *c) { fstrm_res res; res = decode_control_frame(c, test->bytes, test->len, 0); - assert(res != FSTRM_RES_SUCCESS); + assert(res != fstrm_res_success); } } diff --git a/t/test_fstrm_io_file.c b/t/test_fstrm_io_file.c index d498657..b7bf858 100644 --- a/t/test_fstrm_io_file.c +++ b/t/test_fstrm_io_file.c @@ -87,7 +87,7 @@ thr_producer(void *arg) ubuf_destroy(&u); res = fstrm_io_submit(fio, p->fq, message, len, fstrm_free_wrapper, NULL); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { p->pstat.count_submitted++; p->pstat.bytes_submitted += len; } else { diff --git a/t/test_fstrm_io_unix.c b/t/test_fstrm_io_unix.c index 7d27e97..d8092f4 100644 --- a/t/test_fstrm_io_unix.c +++ b/t/test_fstrm_io_unix.c @@ -89,7 +89,7 @@ thr_producer(void *arg) ubuf_destroy(&u); res = fstrm_io_submit(fio, p->fq, message, len, fstrm_free_wrapper, NULL); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { p->pstat.count_submitted++; p->pstat.bytes_submitted += len; } else { diff --git a/t/test_writer_hello.c b/t/test_writer_hello.c index d1e4304..e37bf14 100644 --- a/t/test_writer_hello.c +++ b/t/test_writer_hello.c @@ -56,28 +56,28 @@ fs_test_writer_create(struct fstrm_io *io, void **data) { //fprintf(stderr, "%s: called\n", __func__); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res fs_test_writer_destroy(void *data) { //fprintf(stderr, "%s: called\n", __func__); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res fs_test_writer_open(void *data) { //fprintf(stderr, "%s: called\n", __func__); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res fs_test_writer_close(void *data) { //fprintf(stderr, "%s: called\n", __func__); - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -95,7 +95,7 @@ fs_test_writer_write_control(void *data, fputc('\n', stderr); */ } - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static fstrm_res @@ -121,7 +121,7 @@ fs_test_writer_write_data(void *data, memmove(t_cur->data, iov[i].iov_base, iov[i].iov_len); } num_iovecs += iovcnt; - return FSTRM_RES_SUCCESS; + return fstrm_res_success; } static int @@ -269,9 +269,9 @@ main(void) res = fstrm_io_submit(io, fq, bytes, strlen(bytes), fstrm_free_wrapper, NULL); - if (res == FSTRM_RES_SUCCESS) { + if (res == fstrm_res_success) { break; - } else if (res == FSTRM_RES_AGAIN) { + } else if (res == fstrm_res_again) { poll(NULL, 0, 1); /* sleep for a millisecond */ continue; } else {