117 Commits

Author SHA1 Message Date
nikitalita
22779a0052 bump cmake package version 2023-01-05 12:40:05 +00:00
nikitalita
ebdcc5b9b4 fix semver require, config template 2023-01-05 12:40:05 +00:00
nikitalita
fe8695c502 Add package install and config 2023-01-05 12:40:05 +00:00
Ben Clayton
03e975779e Add a simple network client / server example
Issue: #77
2023-01-04 10:48:24 +00:00
Ben Clayton
8a320f56dc
Minor cleanup + kokoro ubuntu fix (#86)
* tools: Minor clean up of protocol_gen.go

* Fix kokoro/ubuntu builds
2022-12-16 13:53:50 +00:00
nikitalita
87f8b4a06b
Fix "oneOf" parsing, update to protocol version 1.58 (#85)
* fix "oneOf" parsing in protocol_gen

* update protocol version to 1.58.0
2022-12-16 13:43:39 +00:00
Ben Clayton
88e8952014
kokoro: Fix ASAN build (#76)
The VM has been updated to Kokoro 14.04, and now the docker instance requires escalated privileges in order to run some sanitizer builds.
2021-12-23 17:35:56 +00:00
luzhen
a841177c5b
Fix valid function invoke failed in future class (#75)
In C++11, shared_ptr has an explicit operator bool which
means that a shared_ptr can't be implicitly converted to a bool.
adding an explicit cast is a valid fix to the code.
2021-12-23 07:21:55 +00:00
Ben Clayton
5f3169421e
Fix reconnection of sockets (#70)
This was entirely broken:
* The `Server` `Impl` used a `do{}while(false)` block, which never attempted to accept another connection after the first connection closed (#69)
* The `Server` `Impl` could deadlock with the mutex being locked by both the thread calling `isRunning()` and `stopWithLock()` waiting on `thread.join()`.
* `Socket::accept()` didn't check that the returned socket was valid, and could return a `ReaderWriter` that would just error on IO.
* `Socket::accept()` could deadlock on macOS as `shutdown()` can seemingly fail to unblock an accept call. This has been worked around by calling `close()` outside of the mutex write-lock. This introduces a potential race, but I'm not sure of a better solution right now.
 
Fixes: #69
2021-09-07 18:55:02 +01:00
Ben Clayton
51cf2951d0 CMake: Remove installation target
CMake installation target has been broken for years.
cppdap is only internally used and tested as a library that is included as a sub-module of another project.

In order for a package to be installable, it really needs a stable ABI / API, which we've made no explicit guarantees about.
cppdap is small enough that it can easily be included in a third_party directory of another project.

Remove the broken, unmaintained installation rules.

Fixes: #54
2021-09-07 18:52:14 +01:00
Ben Clayton
323e91d80b Session: Expose 'protected' API.
Classify 'advanced' APIs from the 'basic' API.
Move `bind()` up top, which is the typical way to use the Session.
Comment on the other APIs that you should probably just use `bind()`.

Document all the members that are now public.

Fixes: #63
2021-09-07 18:43:12 +01:00
Ben Clayton
9a97ffce52 traits.h: Rename TRUE to TRUE_TY
A workaround for `TRUE` being a `#define` in Windows headers.
Fixes #62
2021-08-23 19:39:55 +01:00
Ben Clayton
ebe7143ef1 json serializers: Support 64-bit integers.
Fixes: #66
2021-08-23 19:39:43 +01:00
Ben Clayton
23c95f91b5 rapid_json_serializer: Fix warning about shadowing
Fixes: #65
2021-08-23 19:39:19 +01:00
Ben Clayton
be5b677c7b Fix generation of named enumerator types
Schema top-level definitions, such as `InvalidatedAreas` and `SteppingGranularity` were being emitted as empty structures, when they were actually enumerators.

Re-work protocol_gen.go to emit these correctly.

Also bumps the protocol to DAP version 1.46.0
2021-04-14 22:00:29 +01:00
Ben Clayton
ad185ee762 license-checker.cfg: Update rules
The license classification rules in github.com/google/licensecheck have been updated.
2021-02-11 21:58:21 +00:00
Ben Clayton
2a3ba20937
Merge pull request #58 from ben-clayton/response-callbacks
Add Session::registerHandler() overloads that support response callbacks
2021-02-03 19:08:27 +00:00
Ben Clayton
e10691ab3f Update DAP protocol to 1.43.0 2021-01-14 12:49:37 +00:00
Ben Clayton
6d6cbf17d7 Add support for rapidjson as the JSON library
nlohmann is still the default, but if `CPPDAP_JSON_DIR` points to rapidjson, then this will be used instead

Most of this was upstreamed from:
https://fuchsia-review.googlesource.com/c/third_party/github.com/google/cppdap/+/456566
2020-12-02 17:44:24 +00:00
Puneetha Ramachandra
77209caf04 Fix content reader for partial input
When there is partial message in reader, popping out the
characters lead to parse errors on the subsequent attempt
to parse. To avoid this, the last matched characters'
index is stored during parsing and reset on error.
2020-12-01 18:13:31 +00:00
Puneetha Ramachandra
e53575d272 Split bind API
Bind API is split into connect and startProcessingMessages calls.
This enables users to directly call connect and manage processing
messages on user threads.
2020-12-01 17:59:43 +00:00
Puneetha Ramachandra
ea6098df7f Added bindNoThread
bindNoThread in conjunction with OnDataAvailable will provide
users with a choice of thread to process requests on. This is
useful when the user relies on single threaded message loop based
design to avoid locking.
2020-12-01 17:59:43 +00:00
Ben Clayton
1fd23dda91 Add license checker config and kokoro presubmit
`license-checker` is a tool that verifies each file has contains a permitted license header.

See https://github.com/ben-clayton/license-checker for more information.

Also add missing licenses to presubmit scripts.
2020-07-21 16:31:05 +01:00
Ben Clayton
1e5ec3e405 Change dap::integer backing type to int64_t
`int` may be < 64 bit, and some dap protocols use a 64 bit integer. Chnage to `int64_t` to be consistent.

Fixes: #45
2020-06-30 11:57:51 +01:00
Ben Clayton
7b02b9f73a Add dap::initialize() and terminate() functions
Can be used to explicitly control when the TypeInfo static initializers / destructors are called.
Usually not needed.

Issue: #40
2020-06-22 19:51:39 +01:00
Ben Clayton
c9630a9aee TypeOf: Move Move TypeInfos to anon namespace
Instead of constructing them as static fields.
Slightly less cludgy.

Related issue: #40
2020-06-15 15:28:07 +01:00
Ben Clayton
ed0af8fa21 Add lots more tests for dap::any.
Exercise copy, assign, moves.
2020-06-15 15:16:10 +01:00
Ben Clayton
9d3f5c8f1d clang: Enable -Weverything, fix all warnings
This change fixes the following warnings:

```
    -Wc++98-compat-extra-semi
    -Wc++98-compat-local-type-template-args
    -Wc++98-compat-pedantic
    -Wc++98-compat
    -Wcomma
    -Wdeprecated-copy-dtor
    -Wexit-time-destructors
    -Wextra-semi-stmt
    -Wextra-semi
    -Wfloat-conversion
    -Wfloat-equal
    -Wformat-nonliteral
    -Wglobal-constructors
    -Winconsistent-missing-destructor-override
    -Wnon-virtual-dtor
    -Wold-style-cast
    -Wpadded
    -Wreturn-std-move-in-c++11
    -Wshadow-field-in-constructor
    -Wshadow-uncaptured-local
    -Wshift-sign-overflow
    -Wsign-conversion
    -Wundef
    -Wunreachable-code-return
    -Wused-but-marked-unused
    -Wweak-vtables
    -Wzero-as-null-pointer-constant
```
2020-06-10 15:10:57 +01:00
Ben Clayton
bb3dbcd2c3 Update DAP protocol to 1.41.0
Update the script to include the DAP version in the file headers.

Remove http file caching. Was never used.
2020-06-10 15:10:57 +01:00
Ben Clayton
f0c28f93dd Fix moves of any when value isInBuffer
This was copying the pointer to the other's value in other.buffer.
2020-06-10 15:10:57 +01:00
Ben Clayton
2f607e077a Fix deadlock closing socket on another thread
while another thread is stuck in read() or write().

Fixes: #37
2020-06-10 10:28:39 +01:00
Ben Clayton
9003ee55b9 Socket: Use the RWMutex to fix TSAN error
... about `close()`ing the socket on one thread while in a blocking `recv()` or `send()` call on another thread.

Fixes #35
2020-06-08 21:32:05 +01:00
Ben Clayton
53a62fd794 Add dap::RWMutex. A read / write mutex.
Also known as a shared mutex.
`std::shared_mutex` was introduced in C++17, but cppdap is C++11.

To be used to fix #35.
2020-06-08 21:32:05 +01:00
Ben Clayton
78dd3ab57a CMake: Handle building fuzzer with sanitizers
If any of the `CPPDAP_?SAN` sanitizers are enabled, then the build would fail as the compile flags would collide with hard-coded use of address sanitizer for the fuzzer.

Don't hard code address sanitizer for the fuzzer - just use the CMake flag options.
2020-06-08 21:32:05 +01:00
Ben Clayton
13c9e7d465 Implement timeouts for dap::Socket::connect
Fixes: #24
2020-06-08 20:22:05 +01:00
Ben Clayton
261d62d91e Remove unnecessary virtual inheritance
Looks like a copypasta mistake
2020-06-05 10:53:52 +01:00
Ben Clayton
aeb66147da json_serializer: Disable exceptions
Define `JSON_NOEXCEPTION` to avoid raising exceptions.
Exceptions are usually disabled for Google projects (https://google.github.io/styleguide/cppguide.html#Exceptions).

Also pass `false` to the `allow_exceptions` parameter of `nlohmann::json::parse()`.

Issue identified by @kuafuwang in #26.
2020-06-05 10:53:52 +01:00
Ben Clayton
773f0dff68 Add support for fuzzing cppdap
Add build rules, scripts, basic corpus, and dictionary.
Currently requires recent clang toolchain.
2020-06-05 10:53:52 +01:00
Ben Clayton
cc93ba9747 Add the ability to derive message types from one another.
`DAP_IMPLEMENT_STRUCT_TYPEINFO_EXT` and `DAP_STRUCT_TYPEINFO_EXT` are two new flavors of `DAP_IMPLEMENT_STRUCT_TYPEINFO` and `DAP_STRUCT_TYPEINFO` that allow you to derive message types.

This involved a bit of reworking on the serializer interfaces.

Added test.

Issue: #32
2020-06-02 17:18:32 +01:00
Ben Clayton
c9187480d1 Fix short reads in ContentReader::buffer()
The actual length of data read by `dap::Reader::read()` was not being correctly inspected.

Fixed, added test.

Bug identified by @kuafuwang.

Fixes #27
2020-05-27 18:40:48 +01:00
Ben Clayton
ad9b4588f2 Fix dap::Socket::read() when recv() errors
Identified by @kuafuwang.

Fixes #29
2020-05-27 18:40:08 +01:00
Ben Clayton
9e313445bb Kokoro Ubuntu: Switch to docker image
presubmit.sh now runs presubmit-docker.sh using the new radial
docker image which contains various toolchains.

The `/bin/using.sh` bash script exports the `using` bash function
which can be called to configure toolchains at specific versions.
2020-05-07 13:55:54 +01:00
Ben Clayton
4bc690cba8 Update DAP protocol to Version 1.40
Updated with:
 `go run scripts/protocol_gen/protocol_gen.go`
2020-05-05 13:03:20 +01:00
Ben Clayton
4dcca57756 Socket: Enable TCP_NODELAY
DAP usually consists of small packet requests, with small packet responses. When there are many frequent, blocking requests made, Nagle's algorithm can dramatically limit the request->response rates.
2020-03-13 07:01:42 +00:00
Ben Clayton
c4358807e2 Fix new gcc 9 'deprecated-copy' warning.
Example warning:

cppdap/include/dap/future.h:172:14: error: implicitly-declared ‘dap::ResponseOrError<dap::StackTraceResponse>& dap::ResponseOrError<dap::StackTraceResponse>::operator=(const dap::ResponseOrError<dap::StackTraceResponse>&)’ is deprecated [-Werror=deprecated-copy]

Add missing constructors and assignment operators.
This probably adds more than is absolutely necessary, but there's no
harm in being thorough.
2020-02-06 13:37:41 +00:00
Ben Clayton
de7dffaf66 Socket: Use SO_REUSEADDR, disable SO_LINGER
Use these to avoid "socket in use" errors when restarting a DAP that uses the same port.
2020-01-28 14:44:35 +00:00
Ben Clayton
9a9d46f6b6 Fix bad usage of std::move
Issue #16 describes the problem and solution perfectly.

Updated tests to cover this.

Fixes #16
2020-01-24 15:21:26 +00:00
Ben Clayton
3e6cfd6c2f CMake: Make the cppdap target's include directory public
Avoids having to pull this in as an explicit include directory for projects that depend on cppdap.
2020-01-24 12:53:20 +00:00
Ben Clayton
4abe43c131 optional: Remove the value() method that returns non-const-ref.
I'm not convinced that `opt.value() = foo` is a desirable pattern,
and worse still it confuses some compilers about which overload to
use.

Just remove it.
2020-01-24 07:25:33 +00:00
Ben Clayton
ced82a0501 examples: Change stdin and stdout to binary mode
On windows text mode for these plays with newline escape sequences, breaking the ContextStream encoding.

Fixes: #12
2020-01-17 20:07:55 +00:00