# HG changeset patch # User František Kučera # Date 1479582617 -3600 # Node ID 117e8ff7732655d13f11b10c4f33f725d8c41dde # Parent 6f68b5e695df03f525df6df503a4d3a1717060b9 libevent: předávání dat z listener_cb() do conn_read_cb() diff -r 6f68b5e695df -r 117e8ff77326 c++/domain-socket-bridge/domain-socket-bridge.c --- a/c++/domain-socket-bridge/domain-socket-bridge.c Sat Nov 19 19:58:52 2016 +0100 +++ b/c++/domain-socket-bridge/domain-socket-bridge.c Sat Nov 19 20:10:17 2016 +0100 @@ -111,7 +111,7 @@ event_base_loopbreak(base); return; } - bufferevent_setcb(bev, conn_read_cb, conn_write_cb, conn_event_cb, NULL); + bufferevent_setcb(bev, conn_read_cb, conn_write_cb, conn_event_cb, (void*) "TODO: tady bude informace o spojení"); bufferevent_setwatermark(bev, EV_READ, 0, MAX_LINE); bufferevent_enable(bev, EV_READ | EV_WRITE); @@ -121,11 +121,12 @@ } static void conn_read_cb(struct bufferevent *bev, void *user_data) { + printf("conn_read_cb: user_data = '%s'\n", (char*) user_data); + /* This callback is invoked when there is data to read on bev. */ struct evbuffer *input = bufferevent_get_input(bev); struct evbuffer *output = bufferevent_get_output(bev); struct event_base *base = bufferevent_get_base(bev); - ; size_t len = evbuffer_get_length(input); char *data = (char*) malloc(len); @@ -138,7 +139,6 @@ event_base_loopexit(base, &delay); } - evbuffer_add(output, "echo: ", 6); /* Copy all the data from the input buffer to the output buffer. */ evbuffer_add_buffer(output, input); @@ -146,6 +146,8 @@ } static void conn_write_cb(struct bufferevent *bev, void *user_data) { + printf("conn_write_cb: user_data = '%s'\n", (char*) user_data); + struct evbuffer *output = bufferevent_get_output(bev); if (evbuffer_get_length(output) == 0) { printf("flushed answer / %p\n", bev); @@ -156,6 +158,8 @@ } static void conn_event_cb(struct bufferevent *bev, short events, void *user_data) { + printf("conn_event_cb: user_data = '%s'\n", (char*) user_data); + if (events & BEV_EVENT_EOF) { printf("Connection closed.\n"); } else if (events & BEV_EVENT_ERROR) {