From cbd962c5b6e4d207ab405aecba2ea2f870769715 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 9 Jun 2015 13:14:27 +0200 Subject: [PATCH] Fix bench.c so it actually reads from the pipe/socket, update callback API Signed-off-by: Joachim Nilsson --- Makefile | 8 ++++---- bench.c | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 78132f4..c77f2e0 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -.PHONY: all test clean joystick test examples +.PHONY: all test clean joystick test examples bench #VERSION = $(shell git tag -l | tail -1) VERSION ?= 1.1.0 @@ -106,9 +106,9 @@ strip: $(TARGET) @$(STRIP) --strip-unneeded $(TARGET) @size $(TARGET) -bench: Makefile bench.o $(STATICLIB) - @printf " BENCH %s\n" $(STATICLIB) - @$(CC) $(CPPFLAGS) -g -o bench bench.c $(STATICLIB) && ./bench +bench: Makefile $(STATICLIB) + @printf " RUN %s\n" $@ + @$(CC) $(CPPFLAGS) -D_GNU_SOURCE -g -o bench bench.c $(STATICLIB) && ./bench examples: all @$(MAKE) -C examples diff --git a/bench.c b/bench.c index 5278607..577e0f4 100644 --- a/bench.c +++ b/bench.c @@ -70,7 +70,7 @@ static int *pipes; static uev_t *evio; static uev_t *evto; -static void read_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *arg, int UNUSED(events)) +static void read_cb(uev_t *w, void *arg, int UNUSED(events)) { int idx, widx; u_char ch; @@ -96,7 +96,7 @@ static void read_cb(uev_ctx_t *UNUSED(ctx), uev_t *w, void *arg, int UNUSED(even } } -static void timer_cb(uev_ctx_t UNUSED(*ctx), uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events)) +static void timer_cb(uev_t UNUSED(*w), void UNUSED(*arg), int UNUSED(events)) { /* nop */ } @@ -208,16 +208,17 @@ int main(int argc, char **argv) if (timers) uev_timer_init(&ctx, &evto[i], timer_cb, NULL, 0, 0); args[i].index = i; - uev_io_init(&ctx, &evio[i], read_cb, &args[i], -1, UEV_READ); #ifdef USE_PIPES - if (pipe(cp) == -1) { + if (pipe2(cp, O_NONBLOCK) == -1) { #else - if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) { + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, cp) == -1) { #endif perror("pipe"); exit(1); } + + uev_io_init(&ctx, &evio[i], read_cb, &args[i], cp[0], UEV_READ); } for (i = 0; i < 2; i++)