Skip to content

Commit 6d2b93f

Browse files
committed
restructured
1 parent fbe346f commit 6d2b93f

File tree

7 files changed

+37
-17
lines changed

7 files changed

+37
-17
lines changed

C++/src/client_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include <boost/asio.hpp>
33

4-
#include "msg.pb.h"
4+
#include "../gen/msg.pb.h"
55

66
using namespace std;
77

C++/src/server_async.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <functional>
44
#include <vector>
55
#include <boost/asio.hpp>
6-
#include "msg.pb.h"
6+
#include "../gen/msg.pb.h"
77

88
#include "asio_server.h"
99

C++/src/server_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <array>
33
#include <vector>
44
#include <boost/asio.hpp>
5-
#include "msg.pb.h"
5+
#include "../gen/msg.pb.h"
66

77

88
#include "asio_server.h"

Python/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import socket
22
from struct import pack
3-
import msg_pb2
3+
from gen import msg_pb2
44

55
sock = socket.socket(socket.AF_UNIX)
66
address = './socket'

Python/server.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SocketServer
22
from struct import unpack
33
from os import unlink
4-
import msg_pb2
4+
from gen import msg_pb2
55

66

77
address = './socket'
@@ -19,7 +19,10 @@ def handle(self):
1919
print("Message: " + pb_message.cont)
2020

2121

22+
try:
23+
unlink(address)
24+
except OSError as e:
25+
pass
2226

23-
unlink(address)
2427
server = SocketServer.UnixStreamServer(address, Session)
2528
server.serve_forever()

makefile

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11

2-
BINS = client_sync server_sync server_async
2+
CPP_BINS = client_sync server_sync server_async
33

44
# consider also -lboost_thread-mt -lpthread
5-
LIBS = -lboost_system-mt -lprotobuf
6-
CFLAGS = -Wall -O2 --std=c++11 -L/usr/local/lib
5+
CPP_LIBS = -lboost_system-mt -lprotobuf
6+
CPP_FLAGS = -Wall -O2 --std=c++11 -L/usr/local/lib
77

8-
all: $(BINS) msg_pb2.py
8+
all: CPP Python
99

10+
CPP: $(CPP_BINS)
1011

11-
$(BINS): %: %.cc msg.pb.cc asio_server.h
12-
clang++ $(CFLAGS) $@.cc msg.pb.cc -o $@ $(LIBS)
12+
Python: Python/gen/msg_pb2.py
1313

14-
msg.pb.cc: msg.proto
15-
protoc --cpp_out=. msg.proto
14+
$(CPP_BINS): %: C++/src/%.cc C++/gen/msg.pb.cc C++/src/asio_server.h
15+
clang++ $(CPP_FLAGS) C++/src/$@.cc C++/gen/msg.pb.cc -o C++/bin/$@ $(CPP_LIBS)
16+
cp C++/bin/$@ bin/cpp_$@
1617

17-
msg_pb2.py: msg.proto
18-
protoc --python_out=. msg.proto
18+
C++/gen/msg.pb.cc: msg.proto
19+
protoc --cpp_out=C++/gen msg.proto
20+
21+
Python/gen/msg_pb2.py: msg.proto
22+
touch Python/gen/__init__.py # I hate this.
23+
protoc --python_out=Python/gen msg.proto
24+
echo "#!/bin/sh\n\npython Python/client.py" > bin/python_client.sh
25+
chmod +x bin/python_client.sh
26+
echo "#!/bin/sh\n\npython Python/server.py" > bin/python_server.sh
27+
chmod +x bin/python_server.sh
1928

2029
.PHONY : clean
2130
clean:
22-
rm -f $(BINS) msg.pb.cc msg.pb.h msg_pb2.py msg_pb2.pyc
31+
rm -f C++/bin/* C++/gen/* Python/gen/* bin/*

msg.proto

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package asio;
2+
3+
4+
//option optimize_for = LITE_RUNTIME;
5+
6+
message Boring {
7+
required string cont = 1;
8+
}

0 commit comments

Comments
 (0)