From: Andre Noll Date: Mon, 16 Jan 2012 21:14:41 +0000 (+0100) Subject: Introduce afs_max_size_handler_data and afs_max_size_handler(). X-Git-Tag: v0.4.11~14^2~13 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=68cb0aef88594f3dea1f7dfdc279f125bf5bbecc Introduce afs_max_size_handler_data and afs_max_size_handler(). Whenever the maximal size of a para buffer is reached, para_printf() calls the specified max size handler. This handler takes, in addition to the actual buffer and its size, a void * context pointer. Currently all commands simply pass a pointer to the underlying file descriptor here since this is the only context the handler needs to know about. However, this is going to change since with sideband connections the handler needs to know also the sideband designator. To meet this future need, this patch introduces struct afs_max_size_handler_data, which consists of the file descriptor only at the moment, as well as a simple wrapper for pass_buffer_as_shm(). --- diff --git a/afs.c b/afs.c index 5939cbe6..04b69611 100644 --- a/afs.c +++ b/afs.c @@ -546,8 +546,10 @@ static void com_select_callback(int fd, const struct osl_object *query) { struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, }; char *arg = query->data; int num_admissible, ret, ret2; @@ -787,10 +789,6 @@ static void command_pre_select(struct sched *s, struct task *t) * \param size The size of \a buf. * \param fd_ptr A pointer to the file descriptor. * - * This function is used as the \a max_size handler in a \ref para_buffer - * structure. If used this way, it is called by \ref para_printf() whenever - * the buffer passed to para_printf() is about to exceed its maximal size. - * * This function creates a shared memory area large enough to hold * the content given by \a buf and \a size and sends the identifier * of this area to the file descriptor given by \a fd_ptr. diff --git a/afs.h b/afs.h index 7145c41b..ba0d266a 100644 --- a/afs.h +++ b/afs.h @@ -209,6 +209,34 @@ typedef int callback_result_handler(struct osl_object *result, void *private); int sc_send_result(struct osl_object *result, void *private); int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr); + +/** Structure passed to the AFS max_size handler. */ +struct afs_max_size_handler_data { + /** Local socket connecting the command handler and the AFS process. */ + int fd; +}; + +/** + * Standard max_size handler for AFS commands. + * + * \param buf Contains (part of) the AFS command output. + * \param size The number of bytes in \a buf. + * \param private Pointer to a \ref afs_max_size_handler_data structure. + * + * Whenever the output of an AFS command exceeds the maximal size of a shared + * memory area, the max size handler of the para_buffer which holds the command + * output is called with \a private being a pointer to a structure of type + * afs_max_size_handler_data. + * + * \return The return value of the underlying call to \ref + * pass_buffer_as_shm(). + */ +_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private) +{ + struct afs_max_size_handler_data *amshd = private; + return pass_buffer_as_shm(buf, size, &amshd->fd); +} + __noreturn void afs_init(uint32_t cookie, int socket_fd); void afs_event(enum afs_events event, struct para_buffer *pb, void *data); diff --git a/aft.c b/aft.c index 7516e328..dffe3a31 100644 --- a/aft.c +++ b/aft.c @@ -1349,9 +1349,14 @@ static void com_ls_callback(int fd, const struct osl_object *query) { struct ls_options *opts = query->data; char *p, *pattern_start = (char *)query->data + sizeof(*opts); - struct para_buffer b = {.max_size = shm_get_shmmax(), + struct para_buffer b = { + .max_size = shm_get_shmmax(), .flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0, - .max_size_handler = pass_buffer_as_shm, .private_data = &fd}; + .max_size_handler = afs_max_size_handler, + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + } + }; int i = 0, ret; time_t current_time; @@ -1674,8 +1679,13 @@ static void com_add_callback(int fd, const struct osl_object *query) char afsi_buf[AFSI_SIZE]; uint32_t flags = read_u32(buf + CAB_FLAGS_OFFSET); struct afs_info default_afsi = {.last_played = 0}; - struct para_buffer msg = {.max_size = shm_get_shmmax(), - .max_size_handler = pass_buffer_as_shm, .private_data = &fd}; + struct para_buffer msg = { + .max_size = shm_get_shmmax(), + .max_size_handler = afs_max_size_handler, + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + } + }; uint16_t afhi_offset, chunks_offset; hash = (unsigned char *)buf + CAB_HASH_OFFSET; @@ -2082,7 +2092,7 @@ static void com_touch_callback(int fd, const struct osl_object *query) .pb = { .max_size = shm_get_shmmax(), .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .max_size_handler = afs_max_size_handler } }; int ret, ret2 = 0; @@ -2223,7 +2233,7 @@ static void com_rm_callback(int fd, const struct osl_object *query) .pb = { .max_size = shm_get_shmmax(), .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .max_size_handler = afs_max_size_handler } }; int ret; @@ -2365,7 +2375,7 @@ static void com_cpsi_callback(int fd, const struct osl_object *query) .pb = { .max_size = shm_get_shmmax(), .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .max_size_handler = afs_max_size_handler } }; int ret; @@ -2538,8 +2548,10 @@ void aft_check_callback(int fd, __a_unused const struct osl_object *query) { struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler }; int ret = para_printf(&pb, "checking audio file table...\n"); diff --git a/attribute.c b/attribute.c index 19700944..9fddc1c3 100644 --- a/attribute.c +++ b/attribute.c @@ -151,8 +151,10 @@ static void com_lsatt_callback(int fd, const struct osl_object *query) .flags = *(unsigned *) query->data, .pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler } }; @@ -297,8 +299,10 @@ static void com_addatt_callback(int fd, const struct osl_object *query) int ret = 1, ret2 = 0; struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler }; size_t len; @@ -380,8 +384,10 @@ static void com_mvatt_callback(int fd, const struct osl_object *query) struct osl_row *row; struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, }; int ret; @@ -450,8 +456,10 @@ static void com_rmatt_callback(int fd, const struct osl_object *query) .num_removed = 0, .pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, } }; int ret, ret2 = 0; diff --git a/blob.c b/blob.c index 409e3487..fea230f1 100644 --- a/blob.c +++ b/blob.c @@ -133,8 +133,10 @@ static void com_lsblob_callback(struct osl_table *table, .flags = *(uint32_t *)query->data, .pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, } }; struct pattern_match_data pmd = { @@ -265,8 +267,10 @@ static void com_rmblob_callback(struct osl_table *table, int fd, struct rmblob_data rmbd = { .pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, } }; struct pattern_match_data pmd = { diff --git a/mood.c b/mood.c index f580400d..c892ff5c 100644 --- a/mood.c +++ b/mood.c @@ -425,8 +425,10 @@ void mood_check_callback(int fd, __a_unused const struct osl_object *query) { struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler }; int ret = para_printf(&pb, "checking moods...\n"); diff --git a/playlist.c b/playlist.c index 13c29404..dd437157 100644 --- a/playlist.c +++ b/playlist.c @@ -132,8 +132,10 @@ void playlist_check_callback(int fd, __a_unused const struct osl_object *query) { struct para_buffer pb = { .max_size = shm_get_shmmax(), - .private_data = &fd, - .max_size_handler = pass_buffer_as_shm + .private_data = &(struct afs_max_size_handler_data) { + .fd = fd, + }, + .max_size_handler = afs_max_size_handler, }; int ret = para_printf(&pb, "checking playlists...\n");