libevent: předávání dat z listener_cb() do conn_read_cb()
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 19 Nov 2016 20:10:17 +0100
changeset 34117e8ff77326
parent 33 6f68b5e695df
child 35 ef8152d84946
libevent: předávání dat z listener_cb() do conn_read_cb()
c++/domain-socket-bridge/domain-socket-bridge.c
     1.1 --- a/c++/domain-socket-bridge/domain-socket-bridge.c	Sat Nov 19 19:58:52 2016 +0100
     1.2 +++ b/c++/domain-socket-bridge/domain-socket-bridge.c	Sat Nov 19 20:10:17 2016 +0100
     1.3 @@ -111,7 +111,7 @@
     1.4  		event_base_loopbreak(base);
     1.5  		return;
     1.6  	}
     1.7 -	bufferevent_setcb(bev, conn_read_cb, conn_write_cb, conn_event_cb, NULL);
     1.8 +	bufferevent_setcb(bev, conn_read_cb, conn_write_cb, conn_event_cb, (void*) "TODO: tady bude informace o spojení");
     1.9  	bufferevent_setwatermark(bev, EV_READ, 0, MAX_LINE);
    1.10  	bufferevent_enable(bev, EV_READ | EV_WRITE);
    1.11  
    1.12 @@ -121,11 +121,12 @@
    1.13  }
    1.14  
    1.15  static void conn_read_cb(struct bufferevent *bev, void *user_data) {
    1.16 +	printf("conn_read_cb: user_data = '%s'\n", (char*) user_data);
    1.17 +
    1.18  	/* This callback is invoked when there is data to read on bev. */
    1.19  	struct evbuffer *input = bufferevent_get_input(bev);
    1.20  	struct evbuffer *output = bufferevent_get_output(bev);
    1.21  	struct event_base *base = bufferevent_get_base(bev);
    1.22 -	;
    1.23  
    1.24  	size_t len = evbuffer_get_length(input);
    1.25  	char *data = (char*) malloc(len);
    1.26 @@ -138,7 +139,6 @@
    1.27  		event_base_loopexit(base, &delay);
    1.28  	}
    1.29  
    1.30 -
    1.31  	evbuffer_add(output, "echo: ", 6);
    1.32  	/* Copy all the data from the input buffer to the output buffer. */
    1.33  	evbuffer_add_buffer(output, input);
    1.34 @@ -146,6 +146,8 @@
    1.35  }
    1.36  
    1.37  static void conn_write_cb(struct bufferevent *bev, void *user_data) {
    1.38 +	printf("conn_write_cb: user_data = '%s'\n", (char*) user_data);
    1.39 +
    1.40  	struct evbuffer *output = bufferevent_get_output(bev);
    1.41  	if (evbuffer_get_length(output) == 0) {
    1.42  		printf("flushed answer / %p\n", bev);
    1.43 @@ -156,6 +158,8 @@
    1.44  }
    1.45  
    1.46  static void conn_event_cb(struct bufferevent *bev, short events, void *user_data) {
    1.47 +	printf("conn_event_cb: user_data = '%s'\n", (char*) user_data);
    1.48 +	
    1.49  	if (events & BEV_EVENT_EOF) {
    1.50  		printf("Connection closed.\n");
    1.51  	} else if (events & BEV_EVENT_ERROR) {