Skip to content

Commit e396c8b

Browse files
committed
initial commit
0 parents  commit e396c8b

File tree

2,079 files changed

+245165
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,079 files changed

+245165
-0
lines changed

Diff for: .clang-format

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 0
3+
DerivePointerBinding: true
4+
AllowShortIfStatementsOnASingleLine: true
5+
AllowShortBlocksOnASingleLine: true
6+
PointerAlignment: Left
7+
IndentCaseLabels: true

Diff for: .editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[Makefile]
12+
indent_style = tab

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

Diff for: .markdownlint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"MD013": false,
3+
"MD030": {
4+
"ol_single": 2,
5+
"ol_multi": 2
6+
},
7+
"MD033": {
8+
"allowed_elements": ["br"]
9+
},
10+
"MD041": false
11+
}

Diff for: .travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: cpp
2+
os: osx
3+
osx_image: xcode10.1
4+
compiler: clang
5+
install: true
6+
script: make -C example && make -C tests

Diff for: .vscode/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse.vc.db*

Diff for: .vscode/c_cpp_properties.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"browse": {
6+
"path": [
7+
"${workspaceFolder}/include",
8+
"${workspaceFolder}/tests/vendor/include",
9+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
10+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
11+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
12+
"/opt/local/include",
13+
"/usr/include",
14+
"/usr/include/c++/4.2.1",
15+
"/usr/local/include"
16+
],
17+
"limitSymbolsToIncludedHeaders": true,
18+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
19+
},
20+
"defines": [],
21+
"includePath": [
22+
"${workspaceFolder}/include",
23+
"${workspaceFolder}/tests/vendor/include",
24+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
25+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
26+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
27+
"/opt/local/include",
28+
"/usr/include",
29+
"/usr/include/c++/4.2.1",
30+
"/usr/local/include"
31+
],
32+
"macFrameworkPath": []
33+
}
34+
],
35+
"version": 4
36+
}

Diff for: .vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.exclude": {
3+
"**/build/": true,
4+
"**/vendor/cget/": true,
5+
".vscode/browse.vc.*": true
6+
},
7+
"search.exclude": {
8+
"**/vendor/": true
9+
}
10+
}

Diff for: LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

Diff for: README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[![Build Status](https://travis-ci.org/pqrs-org/cpp-local_datagram.svg?branch=master)](https://travis-ci.org/pqrs-org/cpp-local_datagram)
2+
[![License](https://img.shields.io/badge/license-Boost%20Software%20License-blue.svg)](https://github.com/pqrs-org/cpp-local_datagram/blob/master/LICENSE.md)
3+
4+
# cpp-local_datagram
5+
6+
local datagram server and client.
7+
8+
## Requirements
9+
10+
cpp-local_datagram depends the following classes.
11+
12+
- [asio](https://github.com/chriskohlhoff/asio/)
13+
- [Nod](https://github.com/fr00b0/nod)
14+
- [pqrs::dispatcher](https://github.com/pqrs-org/cpp-dispatcher)
15+
16+
## Install
17+
18+
### Using package manager
19+
20+
You can install `include/pqrs` by using [cget](https://github.com/pfultz2/cget).
21+
22+
```shell
23+
cget install pqrs-org/cget-recipes
24+
cget install pqrs-org/cpp-local_datagram
25+
```
26+
27+
### Manual install
28+
29+
Copy `include/pqrs` directory into your include directory.

Diff for: example/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/cget/pkg/pqrs-org__cget-recipes/
3+
/vendor/etc/
4+
/vendor/**/pkgconfig/

Diff for: example/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 17)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
project (example)
10+
11+
include_directories(${CMAKE_CURRENT_LIST_DIR}/../include)
12+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/vendor/include)
13+
14+
add_executable(
15+
example
16+
main.cpp
17+
)

Diff for: example/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
7+
clean:
8+
rm -rf build
9+
10+
run:
11+
./build/example
12+
13+
update_vendor:
14+
rm -rf vendor
15+
cget install pqrs-org/cget-recipes --prefix vendor
16+
cget install -f cget-requirements.txt --prefix vendor

Diff for: example/cget-requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
chriskohlhoff/asio@asio-1-12-2 --cmake header -DINCLUDE_DIR=asio/include
2+
fr00b0/[email protected] --cmake header
3+
pqrs-org/cpp-dispatcher

Diff for: example/main.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <csignal>
2+
#include <iostream>
3+
#include <pqrs/local_datagram.hpp>
4+
5+
namespace {
6+
auto global_wait = pqrs::make_thread_wait();
7+
}
8+
9+
int main(void) {
10+
std::signal(SIGINT, [](int) {
11+
global_wait->notify();
12+
});
13+
14+
auto time_source = std::make_shared<pqrs::dispatcher::hardware_time_source>();
15+
auto dispatcher = std::make_shared<pqrs::dispatcher::dispatcher>(time_source);
16+
17+
std::string socket_file_path("tmp/server.sock");
18+
size_t buffer_size = 32 * 1024;
19+
std::chrono::milliseconds server_check_interval(3000);
20+
std::chrono::milliseconds reconnect_interval(1000);
21+
22+
// server
23+
24+
auto server = std::make_shared<pqrs::local_datagram::server>(dispatcher,
25+
socket_file_path,
26+
buffer_size,
27+
server_check_interval,
28+
reconnect_interval);
29+
server->bound.connect([] {
30+
std::cout << "server bound" << std::endl;
31+
});
32+
server->bind_failed.connect([](auto&& error_code) {
33+
std::cout << "server bind_failed" << std::endl;
34+
});
35+
server->closed.connect([] {
36+
std::cout << "server closed" << std::endl;
37+
});
38+
server->received.connect([](auto&& buffer) {
39+
std::cout << "server received size:" << buffer->size() << std::endl;
40+
41+
if (!buffer->empty()) {
42+
std::cout << "buffer: ";
43+
for (const auto& c : *buffer) {
44+
std::cout << c;
45+
}
46+
std::cout << std::endl;
47+
}
48+
});
49+
server->async_start();
50+
51+
// client
52+
53+
auto client = std::make_shared<pqrs::local_datagram::client>(dispatcher,
54+
socket_file_path,
55+
server_check_interval,
56+
reconnect_interval);
57+
client->connected.connect([&client] {
58+
std::cout << "client connected" << std::endl;
59+
60+
std::vector<uint8_t> buffer;
61+
buffer.push_back('h');
62+
buffer.push_back('e');
63+
buffer.push_back('l');
64+
buffer.push_back('l');
65+
buffer.push_back('o');
66+
client->async_send(buffer);
67+
});
68+
client->connect_failed.connect([](auto&& error_code) {
69+
std::cout << "client connect_failed" << std::endl;
70+
});
71+
client->closed.connect([] {
72+
std::cout << "client closed" << std::endl;
73+
});
74+
client->async_start();
75+
76+
// ============================================================
77+
78+
global_wait->wait_notice();
79+
80+
// ============================================================
81+
82+
client = nullptr;
83+
server = nullptr;
84+
85+
dispatcher->terminate();
86+
dispatcher = nullptr;
87+
88+
std::cout << "finished" << std::endl;
89+
90+
return 0;
91+
}

Diff for: example/tmp/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sock

0 commit comments

Comments
 (0)