diff --git a/build.sh b/build.sh index 5dd2902..cce7128 100755 --- a/build.sh +++ b/build.sh @@ -238,7 +238,8 @@ clang++ -D NDEBUG -I src/ -O3 -c src/parser/dbs/dbs_parser.cpp \ if [ ! -e build/release/src/rpc/client/ ]; then mkdir build/release/src/rpc/client/; fi echo Compile src/rpc/client/client.cpp clang++ -D NDEBUG -I src/ -O3 -c src/rpc/client/client.cpp \ - -isystem protobuf/include/ -isystem src/system/ \ + -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ \ + -isystem boost/include/ -isystem protobuf/include/ -isystem src/system/ \ -o build/release/src/rpc/client/client.cpp.o -std=c++14 & echo Compile src/rpc/rpc.pb.cc clang++ -D NDEBUG -I src/ -O3 -c src/rpc/rpc.pb.cc -isystem protobuf/include/ \ diff --git a/prepare.sh b/prepare.sh index 5a4d5d5..9a75cc6 100755 --- a/prepare.sh +++ b/prepare.sh @@ -76,8 +76,11 @@ then git submodule update --init tools/build || exit 1 git submodule update --init tools/inspect || exit 1 + + git submodule update --init libs/align || exit 1 git submodule update --init libs/algorithm || exit 1 git submodule update --init libs/array || exit 1 + git submodule update --init libs/asio || exit 1 git submodule update --init libs/assert || exit 1 git submodule update --init libs/atomic || exit 1 git submodule update --init libs/bind || exit 1 @@ -93,7 +96,6 @@ then git submodule update --init libs/filesystem || exit 1 git submodule update --init libs/function || exit 1 git submodule update --init libs/functional || exit 1 - git submodule update --init libs/fusion || exit 1 git submodule update --init libs/hana || exit 1 git submodule update --init libs/heap || exit 1 git submodule update --init libs/integer || exit 1 @@ -111,6 +113,7 @@ then git submodule update --init libs/preprocessor || exit 1 git submodule update --init libs/range || exit 1 git submodule update --init libs/ratio || exit 1 + git submodule update --init libs/regex || exit 1 git submodule update --init libs/throw_exception || exit 1 git submodule update --init libs/thread || exit 1 git submodule update --init libs/tuple || exit 1 diff --git a/src/3rdparty/boost.dbs b/src/3rdparty/boost.dbs index 501bcd3..33bc285 100644 --- a/src/3rdparty/boost.dbs +++ b/src/3rdparty/boost.dbs @@ -5,6 +5,7 @@ cxx_library /boost_template @visibility=public @directory=../../boost/include: + boost/asio.hpp boost/crc.hpp boost/functional/hash.hpp boost/functional/hash/hash.hpp @@ -15,9 +16,10 @@ cxx_library /boost_template boost/hana.hpp boost/hana/ext/std/tuple.hpp boost/hana/for_each.hpp + boost/regex_fwd.hpp + boost/type_index.hpp boost/variant/variant.hpp boost/variant/get.hpp - boost/type_index.hpp ; cxx_header diff --git a/src/rpc/client/client.cpp b/src/rpc/client/client.cpp index c176863..a71993d 100644 --- a/src/rpc/client/client.cpp +++ b/src/rpc/client/client.cpp @@ -2,7 +2,72 @@ // #include "rpc/client/client.h" +#include +#include +#include +#include +#include -namespace rpc1 +namespace rpc { +using boost::asio::ip::tcp; + +const int max_length = 1024; + +void session(tcp::socket sock) +{ + try + { + for (;;) + { + char data[max_length]; + + boost::system::error_code error; + size_t length = sock.read_some(boost::asio::buffer(data), error); + if (error == boost::asio::error::eof) + break; // Connection closed cleanly by peer. + else if (error) + throw boost::system::system_error(error); // Some other error. + + boost::asio::write(sock, boost::asio::buffer(data, length)); + } + } + catch (std::exception& e) + { + std::cerr << "Exception in thread: " << e.what() << "\n"; + } +} + +void server(boost::asio::io_service& io_service, unsigned short port) +{ + tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port)); + for (;;) + { + tcp::socket sock(io_service); + a.accept(sock); + std::thread(session, std::move(sock)).detach(); + } +} + +int main(int argc, char* argv[]) +{ + try + { + if (argc != 2) + { + std::cerr << "Usage: blocking_tcp_echo_server \n"; + return 1; + } + + boost::asio::io_service io_service; + + server(io_service, std::atoi(argv[1])); + } + catch (std::exception& e) + { + std::cerr << "Exception: " << e.what() << "\n"; + } + + return 0; +} } diff --git a/src/rpc/rpc.dbs b/src/rpc/rpc.dbs index 462f1f2..f559e8f 100644 --- a/src/rpc/rpc.dbs +++ b/src/rpc/rpc.dbs @@ -29,6 +29,31 @@ cxx_library rpc_client ; cxx_library: + /cstd + /boost_template + + rpc + ; +; + +cxx_library rpc_server + @type=user: + + cxx_header + @visibility=public + @directory=..: + + rpc/server/server.h + ; + + cxx_file: + server/server.cpp + ; + + cxx_library: + /cstd + /boost_template + rpc ; ; \ No newline at end of file diff --git a/src/rpc/server/server.cpp b/src/rpc/server/server.cpp new file mode 100644 index 0000000..bac4a32 --- /dev/null +++ b/src/rpc/server/server.cpp @@ -0,0 +1,13 @@ +// Copyright © 2016 George Georgiev. All rights reserved. +// + +#include "rpc/server/server.h" +#include +#include +#include +#include +#include + +namespace rpc +{ +} diff --git a/src/rpc/server/server.h b/src/rpc/server/server.h new file mode 100644 index 0000000..9b02de9 --- /dev/null +++ b/src/rpc/server/server.h @@ -0,0 +1,8 @@ +// Copyright © 2016 George Georgiev. All rights reserved. +// + +#pragma once + +namespace rpc +{ +} diff --git a/src/system/cstd.dbs b/src/system/cstd.dbs index c5890a6..770035b 100644 --- a/src/system/cstd.dbs +++ b/src/system/cstd.dbs @@ -10,6 +10,7 @@ cxx_library /cstd cstddef cstdio cstdint + cstdlib stddef.h stdio.h stdlib.h diff --git a/xcode/dbs-build.xcodeproj/project.pbxproj b/xcode/dbs-build.xcodeproj/project.pbxproj index 497571f..9167e55 100644 --- a/xcode/dbs-build.xcodeproj/project.pbxproj +++ b/xcode/dbs-build.xcodeproj/project.pbxproj @@ -145,6 +145,8 @@ 5E8079AC1D093CF900BB6C1C /* hex.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E8079AB1D093CF900BB6C1C /* hex.h */; }; 5E8079AE1D09CF8B00BB6C1C /* hex-utest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E8079AD1D09CF8B00BB6C1C /* hex-utest.cpp */; }; 5E8079B01D09D18800BB6C1C /* hex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E8079AF1D09D18800BB6C1C /* hex.cpp */; }; + 5E8079B61D0C693F00BB6C1C /* server.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E8079B41D0C693F00BB6C1C /* server.cpp */; }; + 5E8079B71D0C693F00BB6C1C /* server.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E8079B51D0C693F00BB6C1C /* server.h */; }; 5E83145F1CDC5A7F00344DB5 /* framework.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E83145E1CDC5A7F00344DB5 /* framework.h */; }; 5E874FAA1CEC175F00C7C123 /* tool_command.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E874FA81CEC175F00C7C123 /* tool_command.cpp */; }; 5E874FAB1CEC175F00C7C123 /* tool_command.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E874FA91CEC175F00C7C123 /* tool_command.h */; }; @@ -395,6 +397,8 @@ 5E8079AB1D093CF900BB6C1C /* hex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hex.h; sourceTree = ""; }; 5E8079AD1D09CF8B00BB6C1C /* hex-utest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "hex-utest.cpp"; sourceTree = ""; }; 5E8079AF1D09D18800BB6C1C /* hex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hex.cpp; sourceTree = ""; }; + 5E8079B41D0C693F00BB6C1C /* server.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = server.cpp; sourceTree = ""; }; + 5E8079B51D0C693F00BB6C1C /* server.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = server.h; sourceTree = ""; }; 5E83145E1CDC5A7F00344DB5 /* framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = framework.h; sourceTree = ""; }; 5E874FA81CEC175F00C7C123 /* tool_command.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tool_command.cpp; sourceTree = ""; }; 5E874FA91CEC175F00C7C123 /* tool_command.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tool_command.h; sourceTree = ""; }; @@ -1123,6 +1127,7 @@ isa = PBXGroup; children = ( 5E0AEFC21D027FBD0094AD34 /* client */, + 5E8079B31D0C686D00BB6C1C /* server */, 5E5A050D1CFA835D00DA4443 /* rpc.dbs */, 5E5A050E1CFA835D00DA4443 /* rpc.proto */, ); @@ -1148,6 +1153,15 @@ path = logex/gtest; sourceTree = ""; }; + 5E8079B31D0C686D00BB6C1C /* server */ = { + isa = PBXGroup; + children = ( + 5E8079B41D0C693F00BB6C1C /* server.cpp */, + 5E8079B51D0C693F00BB6C1C /* server.h */, + ); + path = server; + sourceTree = ""; + }; 5E874FA31CEC173D00C7C123 /* tool */ = { isa = PBXGroup; children = ( @@ -1316,6 +1330,7 @@ 5E875BBB1CFAC7EB008AC423 /* element_manager.hpp in Headers */, 5E283C1A1CF23BC600852F24 /* element_manager.hpp in Headers */, 5E290B391CBAB92500F10210 /* tpool.h in Headers */, + 5E8079B71D0C693F00BB6C1C /* server.h in Headers */, 5E10B3E51C70F272009C73E4 /* log.h in Headers */, 5E875BC81CFBBDE8008AC423 /* cxx_iwyu.h in Headers */, 5EABCABC1CE057FD00E79FFD /* sys_executable.h in Headers */, @@ -1514,6 +1529,7 @@ 5E290B2F1CB9F4FC00F10210 /* verbose-utest.cpp in Sources */, 5E217B681C713CDC00F082A1 /* cxx_program_crc_task.cpp in Sources */, 5E10B3D51C70F272009C73E4 /* err-utest.cpp in Sources */, + 5E8079B61D0C693F00BB6C1C /* server.cpp in Sources */, 5EAE67781C72AFE4005B3F8D /* cxx_include_directory.cpp in Sources */, 5E10B4041C70F272009C73E4 /* priority-utest.cpp in Sources */, 5E5A050F1CFA835D00DA4443 /* rpc.proto in Sources */,