c++/domain-socket-bridge/domain-socket-bridge.c
changeset 32 0eaa8735a083
parent 31 baa90e4359c8
child 33 6f68b5e695df
     1.1 --- a/c++/domain-socket-bridge/domain-socket-bridge.c	Sat Nov 19 19:29:54 2016 +0100
     1.2 +++ b/c++/domain-socket-bridge/domain-socket-bridge.c	Sat Nov 19 19:53:12 2016 +0100
     1.3 @@ -81,7 +81,7 @@
     1.4  	event_free(signal_event);
     1.5  	event_base_free(base);
     1.6  
     1.7 -	// smažeme soket na disku / soubor -- jinak by program příště spadl na evconnlistener_new_bind()
     1.8 +	// smažeme soket na disku / soubor -- jinak by program příště spadl na bind()
     1.9  	unlink(PATH);
    1.10  
    1.11  	printf("done\n");
    1.12 @@ -127,23 +127,9 @@
    1.13  	struct event_base *base = (event_base *) user_data;
    1.14  
    1.15  	size_t len = evbuffer_get_length(input);
    1.16 -	char *data;
    1.17 -	/*
    1.18 -	data = (char*) malloc(len);
    1.19 +	char *data = (char*) malloc(len);
    1.20  	evbuffer_copyout(input, data, len);
    1.21 -	 */
    1.22 -
    1.23 -	size_t n;
    1.24 -	int i;
    1.25 -	while ((data = evbuffer_readln(input, &n, EVBUFFER_EOL_LF))) {
    1.26 -		for (i = 0; i < n; ++i)
    1.27 -			data[i] = rot13_char(data[i]);
    1.28 -		evbuffer_add(output, data, n);
    1.29 -		evbuffer_add(output, "\n", 1);
    1.30 -		free(data);
    1.31 -	}
    1.32 -
    1.33 -	printf("we got some data...\n");
    1.34 +	printf("we got some data: %s\n", data);
    1.35  
    1.36  	/*
    1.37  	if (memcmp(data, "exit\n", len) == 0) {
    1.38 @@ -152,24 +138,11 @@
    1.39  	}
    1.40  	 */
    1.41  
    1.42 -	if (evbuffer_get_length(input) >= MAX_LINE) {
    1.43 -		/* Too long; just process what there is and go on so that the buffer
    1.44 -		 * doesn't grow infinitely long. */
    1.45 -		char buf[1024];
    1.46 -		while (evbuffer_get_length(input)) {
    1.47 -			int n = evbuffer_remove(input, buf, sizeof (buf));
    1.48 -			for (i = 0; i < n; ++i)
    1.49 -				buf[i] = rot13_char(buf[i]);
    1.50 -			evbuffer_add(output, buf, n);
    1.51 -		}
    1.52 -		evbuffer_add(output, "\n", 1);
    1.53 -	}
    1.54  
    1.55 +	evbuffer_add(output, "echo: ", 6);
    1.56  	/* Copy all the data from the input buffer to the output buffer. */
    1.57 -	/*
    1.58  	evbuffer_add_buffer(output, input);
    1.59  	free(data);
    1.60 -	 */
    1.61  }
    1.62  
    1.63  static void conn_write_cb(struct bufferevent *bev, void *user_data) {
    1.64 @@ -201,14 +174,3 @@
    1.65  
    1.66  	event_base_loopexit(base, &delay);
    1.67  }
    1.68 -
    1.69 -static char rot13_char(char c) {
    1.70 -	/* We don't want to use isalpha here; setting the locale would change
    1.71 -	 * which characters are considered alphabetical. */
    1.72 -	if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
    1.73 -		return c + 13;
    1.74 -	else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
    1.75 -		return c - 13;
    1.76 -	else
    1.77 -		return c;
    1.78 -}