Skip to content

Commit 9ce80f2

Browse files
authored
BREAKING CHANGE: buffers exposed as binary, as a UTF-8 string (#94)
1 parent ce8c43d commit 9ce80f2

File tree

20 files changed

+1699
-1611
lines changed

20 files changed

+1699
-1611
lines changed

.clang-format

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignTrailingComments: 'true'
5+
AllowAllArgumentsOnNextLine: 'true'
6+
AllowAllConstructorInitializersOnNextLine: 'true'
7+
AllowAllParametersOfDeclarationOnNextLine: 'true'
8+
AllowShortBlocksOnASingleLine: 'false'
9+
AllowShortCaseLabelsOnASingleLine: 'false'
10+
AllowShortFunctionsOnASingleLine: None
11+
AllowShortIfStatementsOnASingleLine: Never
12+
AllowShortLambdasOnASingleLine: Inline
13+
AllowShortLoopsOnASingleLine: 'false'
14+
AlwaysBreakAfterReturnType: None
15+
AlwaysBreakBeforeMultilineStrings: 'true'
16+
AlwaysBreakTemplateDeclarations: 'Yes'
17+
BinPackArguments: 'false'
18+
BinPackParameters: 'false'
19+
BreakBeforeTernaryOperators: 'true'
20+
BreakConstructorInitializers: BeforeComma
21+
BreakInheritanceList: BeforeComma
22+
ColumnLimit: '80'
23+
CompactNamespaces: 'true'
24+
FixNamespaceComments: 'false'
25+
IndentWidth: '4'
26+
PointerAlignment: Left
27+
SortIncludes: 'false'
28+
SortUsingDeclarations: 'true'
29+
SpaceAfterTemplateKeyword: 'true'
30+
UseTab: Never
31+
IndentPPDirectives: AfterHash
32+
AccessModifierOffset: -4
33+
BreakBeforeBraces: Custom
34+
BraceWrapping:
35+
AfterExternBlock: false
36+
...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
target
22
build
3+
build_CXX20
34
cmake-build-debug
45
cmake-build-release
56
.vs

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ set(CMAKE_C_STANDARD 11)
1616
set(CMAKE_C_STANDARD_REQUIRED ON)
1717
set(CMAKE_C_EXTENSIONS OFF)
1818

19-
set(CMAKE_CXX_STANDARD 17)
19+
set(MINIMUM_REQUIRED_CXX_STANDARD 17)
20+
21+
if((NOT CMAKE_CXX_STANDARD) OR (CMAKE_CXX_STANDARD LESS MINIMUM_REQUIRED_CXX_STANDARD))
22+
set(CMAKE_CXX_STANDARD ${MINIMUM_REQUIRED_CXX_STANDARD})
23+
endif()
24+
message(STATUS "C++ standard: ${CMAKE_CXX_STANDARD}")
25+
2026
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2127
set(CMAKE_CXX_EXTENSIONS OFF)
2228

ci/compile.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ steps:
1212
env:
1313
JAVA_HOME: $(JAVA_HOME_11_X64)
1414
displayName: "Make"
15+
- script: cmake -S . -B build_CXX20 -DCMAKE_BUILD_TYPE=Release -DQUESTDB_TESTS_AND_EXAMPLES=ON -DCMAKE_CXX_STANDARD=20
16+
env:
17+
JAVA_HOME: $(JAVA_HOME_11_X64)
18+
displayName: "Build Makefile with CMake"
19+
- script: cmake --build build_CXX20 --config Release
20+
env:
21+
JAVA_HOME: $(JAVA_HOME_11_X64)
22+
displayName: "Make"

ci/format_cpp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Format all the C and C++ code using `clang-format`.
5+
If --check is passed, check for formatting issues instead of modifying files.
6+
"""
7+
8+
import sys
9+
sys.dont_write_bytecode = True
10+
import subprocess
11+
12+
FILES = [
13+
'include/questdb/ingress/line_sender.h',
14+
'include/questdb/ingress/line_sender.hpp',
15+
'cpp_test/build_env.h',
16+
'cpp_test/mock_server.hpp',
17+
'cpp_test/mock_server.cpp',
18+
'cpp_test/test_line_sender.cpp',
19+
]
20+
21+
if __name__ == '__main__':
22+
check_mode = '--check' in sys.argv
23+
command = [
24+
'clang-format',
25+
'--style=file',
26+
'--dry-run' if check_mode else '-i'
27+
] + FILES
28+
subprocess.check_call(command)

ci/run_all_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@ def run_cmd(*args, cwd=None):
3131
sys.stderr.write(f'Command {args!r} failed with return code {cpe.returncode}.\n')
3232
sys.exit(cpe.returncode)
3333

34-
3534
def main():
3635
build_dir = pathlib.Path('build')
3736
exe_suffix = '.exe' if platform.system() == 'Windows' else ''
3837
test_line_sender_path = next(iter(
3938
build_dir.glob(f'**/test_line_sender{exe_suffix}')))
39+
build_cxx20_dir = pathlib.Path('build_CXX20')
40+
test_line_sender_path_CXX20 = next(iter(
41+
build_cxx20_dir.glob(f'**/test_line_sender{exe_suffix}')))
42+
4043
system_test_path = pathlib.Path('system_test') / 'test.py'
4144
qdb_v = '8.1.0' # The version of QuestDB we'll test against.
4245

4346
run_cmd('cargo', 'test', '--', '--nocapture', cwd='questdb-rs')
4447
run_cmd('cargo', 'test', '--all-features', '--', '--nocapture', cwd='questdb-rs')
4548
run_cmd(str(test_line_sender_path))
49+
run_cmd(str(test_line_sender_path_CXX20))
4650
run_cmd('python3', str(system_test_path), 'run', '--versions', qdb_v, '-v')
4751

4852

ci/run_tests_pipeline.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ stages:
6262
inputs:
6363
pathToPublish: ./build
6464
displayName: "Publish build directory"
65-
- job: CargoFmtAndClippy
65+
- job: FormatAndLinting
6666
displayName: "cargo fmt and clippy"
6767
pool:
6868
vmImage: 'ubuntu-latest'
6969
timeoutInMinutes: 10
7070
steps:
7171
- checkout: self
7272
- script: |
73+
apt install clang-format
7374
rustup component add clippy
7475
rustup component add rustfmt
75-
displayName: "Install clippy and rustfmt"
76+
displayName: "Install clang-format, clippy and rustfmt"
7677
- script: |
7778
cd questdb-rs
7879
cargo fmt --all -- --check
@@ -89,6 +90,9 @@ stages:
8990
cd questdb-rs-ffi
9091
cargo clippy --all-targets --all-features -- -D warnings
9192
displayName: "questdb-rs-ffi: clippy"
93+
- script: |
94+
python3 ci/format_cpp.py --check
95+
displayName: "C/C++ clang-format"
9296
- script: |
9397
cd system_test
9498
cd tls_proxy

cpp_test/mock_server.cpp

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@
2727
#include <string.h>
2828

2929
#if defined(PLATFORM_UNIX)
30-
#include <fcntl.h>
31-
#include <arpa/inet.h>
32-
#include <netdb.h>
33-
#include <netinet/in.h>
34-
#include <netinet/tcp.h>
35-
#include <sys/types.h>
36-
#include <sys/socket.h>
37-
#include <unistd.h>
30+
# include <fcntl.h>
31+
# include <arpa/inet.h>
32+
# include <netdb.h>
33+
# include <netinet/in.h>
34+
# include <netinet/tcp.h>
35+
# include <sys/types.h>
36+
# include <sys/socket.h>
37+
# include <unistd.h>
3838
#elif defined(PLATFORM_WINDOWS)
39-
#include <winsock2.h>
40-
#include <ws2tcpip.h>
39+
# include <winsock2.h>
40+
# include <ws2tcpip.h>
4141
#endif
4242

4343
#if defined(PLATFORM_UNIX)
44-
#define CLOSESOCKET ::close
44+
# define CLOSESOCKET ::close
4545
typedef const void* setsockopt_arg_t;
46-
#ifndef INVALID_SOCKET
47-
#define INVALID_SOCKET -1
48-
#endif
46+
# ifndef INVALID_SOCKET
47+
# define INVALID_SOCKET -1
48+
# endif
4949
#elif defined(PLATFORM_WINDOWS)
50-
#define CLOSESOCKET ::closesocket
50+
# define CLOSESOCKET ::closesocket
5151
typedef const char* setsockopt_arg_t;
5252
typedef long suseconds_t;
5353
#endif
@@ -108,8 +108,8 @@ mock_server::mock_server()
108108
_listen_fd,
109109
SOL_SOCKET,
110110
SO_REUSEADDR,
111-
static_cast<setsockopt_arg_t>(static_cast<const void*>(
112-
&reuse_addr)),
111+
static_cast<setsockopt_arg_t>(
112+
static_cast<const void*>(&reuse_addr)),
113113
sizeof(reuse_addr)) != 0)
114114
{
115115
#if defined(PLATFORM_UNIX)
@@ -126,10 +126,8 @@ mock_server::mock_server()
126126
listen_addr.sin_family = AF_INET;
127127
listen_addr.sin_addr.s_addr = INADDR_ANY;
128128
listen_addr.sin_port = htons(0);
129-
if (bind(
130-
_listen_fd,
131-
(const sockaddr *)&listen_addr,
132-
sizeof(listen_addr)) == -1)
129+
if (bind(_listen_fd, (const sockaddr*)&listen_addr, sizeof(listen_addr)) ==
130+
-1)
133131
throw std::runtime_error{"Bad `bind()`."};
134132

135133
if (listen(_listen_fd, 1) == -1)
@@ -139,9 +137,7 @@ mock_server::mock_server()
139137
memset(&resolved_addr, 0, sizeof(resolved_addr));
140138
socklen_t resolved_addr_len = sizeof(resolved_addr);
141139
if (getsockname(
142-
_listen_fd,
143-
(sockaddr *)&resolved_addr,
144-
&resolved_addr_len) == -1)
140+
_listen_fd, (sockaddr*)&resolved_addr, &resolved_addr_len) == -1)
145141
throw std::runtime_error{"Bad `getsockname()`."};
146142
_port = ntohs(resolved_addr.sin_port);
147143
}
@@ -150,10 +146,7 @@ void mock_server::accept()
150146
{
151147
sockaddr_in remote_addr;
152148
socklen_t remote_addr_len = sizeof(remote_addr);
153-
_conn_fd = ::accept(
154-
_listen_fd,
155-
(sockaddr *)&remote_addr,
156-
&remote_addr_len);
149+
_conn_fd = ::accept(_listen_fd, (sockaddr*)&remote_addr, &remote_addr_len);
157150
if (_conn_fd == INVALID_SOCKET)
158151
throw std::runtime_error{"Bad `accept()`."};
159152
#if defined(PLATFORM_UNIX)
@@ -169,7 +162,7 @@ bool mock_server::wait_for_data(std::optional<double> wait_timeout_sec)
169162
fd_set read_set;
170163
FD_ZERO(&read_set);
171164
FD_SET(_conn_fd, &read_set);
172-
timeval* timeout_ptr = nullptr; // nullptr blocks indefinitely.
165+
timeval* timeout_ptr = nullptr; // nullptr blocks indefinitely.
173166
timeval timeout;
174167
if (wait_timeout_sec)
175168
{
@@ -178,9 +171,8 @@ bool mock_server::wait_for_data(std::optional<double> wait_timeout_sec)
178171
#elif defined(PLATFORM_WINDOWS)
179172
const long secs = static_cast<long>(*wait_timeout_sec);
180173
#endif
181-
const suseconds_t usec =
182-
static_cast<suseconds_t>(
183-
1000000.0 * (*wait_timeout_sec - static_cast<double>(secs)));
174+
const suseconds_t usec = static_cast<suseconds_t>(
175+
1000000.0 * (*wait_timeout_sec - static_cast<double>(secs)));
184176
timeout = timeval{secs, usec};
185177
timeout_ptr = &timeout;
186178
}
@@ -209,11 +201,8 @@ size_t mock_server::recv(double wait_timeout_sec)
209201
for (;;)
210202
{
211203
wait_for_data();
212-
sock_ssize_t count = ::recv(
213-
_conn_fd,
214-
&chunk[0],
215-
static_cast<sock_len_t>(chunk_len),
216-
0);
204+
sock_ssize_t count =
205+
::recv(_conn_fd, &chunk[0], static_cast<sock_len_t>(chunk_len), 0);
217206
if (count == -1)
218207
throw std::runtime_error{"Bad `recv()`."};
219208
const size_t u_count = static_cast<size_t>(count);
@@ -266,4 +255,4 @@ mock_server::~mock_server()
266255
#endif
267256
}
268257

269-
}
258+
} // namespace questdb::ingress::test

cpp_test/mock_server.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#if defined(PLATFORM_UNIX)
3636
typedef int socketfd_t;
3737
#elif defined(PLATFORM_WINDOWS)
38-
#include <winsock2.h>
38+
# include <winsock2.h>
3939
typedef SOCKET socketfd_t;
4040
#endif
4141

@@ -45,17 +45,20 @@ namespace questdb::ingress::test
4545
/**
4646
* Bug-ridden mock server to handle line requests.
4747
* YMMV, but should be just good enough for testing.
48-
*/
48+
*/
4949
class mock_server
5050
{
5151
public:
5252
mock_server();
5353

54-
uint16_t port() const { return _port; }
54+
uint16_t port() const
55+
{
56+
return _port;
57+
}
5558

5659
void accept();
5760

58-
size_t recv(double wait_timeout_sec=0.1);
61+
size_t recv(double wait_timeout_sec = 0.1);
5962

6063
const std::vector<std::string>& msgs() const
6164
{
@@ -75,4 +78,4 @@ class mock_server
7578
std::vector<std::string> _msgs;
7679
};
7780

78-
}
81+
} // namespace questdb::ingress::test

0 commit comments

Comments
 (0)