libevent: c++ string
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 20 Nov 2016 21:00:47 +0100
changeset 425bd10c0ae650
parent 41 2383ed4da507
child 43 b54d76467040
libevent: c++ string
c++/domain-socket-bridge/domain-socket-bridge.cpp
     1.1 --- a/c++/domain-socket-bridge/domain-socket-bridge.cpp	Sun Nov 20 20:40:30 2016 +0100
     1.2 +++ b/c++/domain-socket-bridge/domain-socket-bridge.cpp	Sun Nov 20 21:00:47 2016 +0100
     1.3 @@ -17,10 +17,8 @@
     1.4  
     1.5  using namespace std;
     1.6  
     1.7 -static const char MESSAGE[] = "Hello, World!\n";
     1.8 -
     1.9 -static const char PATH[] = "./roura";
    1.10 -
    1.11 +static const string HELLO_MESSAGE("Hello, World!\n");
    1.12 +static const string SOCKET_PATH("./roura");
    1.13  static const string COMMAND_EXIT("exit\n");
    1.14  
    1.15  static void listener_cb(evutil_socket_t, short, void *);
    1.16 @@ -49,13 +47,13 @@
    1.17  
    1.18  	memset(&sun, 0, sizeof (sun));
    1.19  	sun.sun_family = AF_UNIX;
    1.20 -	strcpy(sun.sun_path, PATH);
    1.21 +	strcpy(sun.sun_path, SOCKET_PATH.c_str());
    1.22  
    1.23  	listener = socket(AF_UNIX, SOCK_STREAM, 0);
    1.24  	evutil_make_socket_nonblocking(listener);
    1.25  
    1.26  	if (bind(listener, (struct sockaddr*) &sun, sizeof (sun)) < 0) {
    1.27 -		printf("%4s %8s %s: %s\n", "*", "ERROR", "unable to create domain socket:", PATH);
    1.28 +		printf("%4s %8s %s: %s\n", "*", "ERROR", "unable to create domain socket:", SOCKET_PATH.c_str());
    1.29  		return 1;
    1.30  	}
    1.31  
    1.32 @@ -91,7 +89,7 @@
    1.33  
    1.34  	// smažeme soket na disku / soubor -- jinak by program příště spadl na bind()
    1.35  	// TODO: co když soket někdo přesune a místo něj dá jiný soubor?
    1.36 -	unlink(PATH);
    1.37 +	unlink(SOCKET_PATH.c_str());
    1.38  
    1.39  	printf("%4s %8s\n", "*", "FINISHED");
    1.40  	return 0;
    1.41 @@ -138,7 +136,7 @@
    1.42  	printf("%4d %8s somebody has connected: socketId = %d → connectionId = %d\n", *connectionId, "CONN", listener, *connectionId);
    1.43  	print_socket_info(*connectionId, fd);
    1.44  
    1.45 -	bufferevent_write(bev, MESSAGE, strlen(MESSAGE));
    1.46 +	bufferevent_write(bev, HELLO_MESSAGE.c_str(), strlen(HELLO_MESSAGE.c_str()));
    1.47  }
    1.48  
    1.49  static void conn_read_cb(struct bufferevent *bev, void *user_data) {