diff --git a/cami.c b/cami.c index e96ed8d..762a5a7 100644 --- a/cami.c +++ b/cami.c @@ -751,6 +751,8 @@ static void *ami_event_dispatch(void *varg) struct pollfd fds; struct ami_event *event; int res; + int count = 0; + int pos; char buf[AMI_BUFFER_SIZE]; (void) varg; /* Unused argument. */ @@ -769,6 +771,7 @@ static void *ami_event_dispatch(void *varg) } if (res) { res = read(ami_event_pipe[0], buf, AMI_BUFFER_SIZE - 1); + ami_debug(3, "ami_event_dispatch: readsize %d\n", res); if (res < 1) { ami_debug(1, "read pipe failed?\n"); break; @@ -778,9 +781,16 @@ static void *ami_event_dispatch(void *varg) /* XXX We should wait for the null terminator and/or split on null terminator if we read multiple events. */ } buf[res] = '\0'; - event = ami_parse_event(buf); - /* Provide the user with the original event, user is responsible for freeing */ - ami_callback(event); + /* it is possible that there are multiple events in the read buffer separated by '\0' */ + pos = 0; + for (count = 0; count < res; count++) { + if (*(buf + count) == '\0') { + event = ami_parse_event(buf + pos); + pos = count + 1; + /* Provide the user with the original event, user is responsible for freeing */ + ami_callback(event); + } + } } }