Skip to content

auparse_next_event returns 0 after auparse_feed #416

@neel

Description

@neel

Given au initialized with auparse_init(AUSOURCE_FEED, 0) the function auparse_next_event returns 0 even after passing data to auparse_feed as shown in the example below. This happens even when there is no callback set.

if (auparse_feed(_au, l.data(), l.size()) != 0) {
    std::cerr << "Failed to feed data to Auparse. Error: " << std::strerror(errno) << std::endl;
}
auparse_flush_feed(_au);
int res = auparse_next_event(_au); // res is 0
while (res > 0) {
    // never comes here
}

This happens because consume_feed loops over all the events unconditionally.

static void consume_feed(auparse_state_t *au, int flush)
{
	//if (debug) printf("consume feed, flush %d\n", flush);
	while (auparse_next_event(au) > 0) {
		if (au->callback) {
			(*au->callback)(au, AUPARSE_CB_EVENT_READY, au->callback_user_data);
		}
	}
     ...
}

I'd prefer a non-callback way of extracting events which is achievable by simple change

static void consume_feed(auparse_state_t *au, int flush)
{
	//if (debug) printf("consume feed, flush %d\n", flush);
	if (au->callback) {
                while (auparse_next_event(au) > 0) {
		     (*au->callback)(au, AUPARSE_CB_EVENT_READY, au->callback_user_data);
	        }
	}

     ...
}

This way the usercode has the freedom to choose a non-callback based way of using auparse_feed method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions