Commit Graph

56 Commits

Author SHA1 Message Date
Peter Johnson
0c6f24562f Fix bug in ULEB128 decoding (#2195) 2019-12-24 14:12:42 -06:00
Thad House
9cb69c5b46 Add a way to pass in a preconstructed value to ManagedStatic (#2175)
A lot of our cases don't need the lazy construction, but do need manual destruction.
2019-12-20 14:06:22 -08:00
Peter Johnson
971303da8c Add PortForwarder class (#1890)
This class provides an easy way to forward local ports to another host/port.
This is primarily useful to provide a way to access Ethernet-connected devices
from a computer tethered to the RoboRIO USB port.

The most natural spot to put the shared implementation of this class was into
wpiutil, so a wpiutilJNI library has been added.
2019-09-26 22:53:21 -07:00
Peter Johnson
10731f3d6b Update uv Udp wrapper for latest features 2019-07-15 20:15:37 -05:00
Tyler Veness
62be0392b6 Replace std::lock_guard and std::lock with std::scoped_lock (#1758)
std::scoped_lock was introduced in C++17 and is strictly better than
std::lock_guard as it supports locking any number of mutexes safely.
It's also easier to use than std::lock for locking multiple mutexes at
once.
2019-07-08 22:58:39 -07:00
Tyler Veness
841ef5d739 Remove template types from lock RAII wrapper usages (#1756)
C++17 has template type autodeduction. These wrappers include
std::lock_guard and std::unique_lock.
2019-07-07 19:17:14 -07:00
Peter Johnson
8757bc471b Remove pre-C++17 shims (#1752)
Now that all compilers support C++17, remove some old C++14/C++17 shims.
2019-07-07 15:44:43 -07:00
Peter Johnson
eedb3a1adc Fix GCC 9 warnings (#1730) 2019-06-30 00:28:32 -07:00
Peter Johnson
60dce66a4f Remove wpi::ArrayRef std::initializer_list constructor (#1745)
This can be dangerous as it refers to a temporary, and GCC 9.0 warns about
its use.  Instead add std::initializer_list overloads to common places it
was used in an initializer_list sense.
2019-06-29 23:54:02 -07:00
Peter Johnson
4b1b92bb74 Replace wpi::optional with C++17 std::optional (#1732)
Keep wpi/optional.h as a shim with deprecated warnings.
2019-06-29 11:20:22 -07:00
Peter Johnson
ee8a33c568 wpiutil: SafeThread: Add thread id, support getting shared_ptr (#1722)
Rename base class function from GetThread to GetThreadSharedPtr.
2019-06-20 19:51:09 -07:00
Peter Johnson
f07569df19 Fix newer GCC/clang compiler warnings (#1718) 2019-06-14 18:32:27 -07:00
Thad House
221011494d Update for C++17 and fix MSVC warnings (#1694)
* Update MSVC arguments
* Fix json allocator
* Fix simulation diamond
* Bump gtest
* Remove empty varargs in unit tests
* Replace test case with test suite
* Remove deprecation warning in optional
* Remove need for NOMIXMAX to be defined in wpilib headers
2019-05-31 15:43:32 -05:00
Tyler Veness
f432f65bef Update copyright year in license to 2019 (#1524)
Also update clang-format to 6.0.
2019-05-17 17:35:09 -07:00
Thad House
620bec9cae wpiutil: uv: Add LoopClosing status to Handle (#1647)
Useful for EventLoopRunner to know if a stop is requested, or close is happening for another reason.
2019-05-05 17:38:56 -07:00
Peter Johnson
2de3bf7f58 Update LLVM from stable upstream (#1653)
Replace CheckedMalloc with upstream safe_malloc.
2019-04-27 20:33:08 -07:00
Thad House
76d9e26633 uv: Add reuse to pipe (#1577)
Needed for a reconnection API
2019-02-09 00:09:22 -08:00
Thad House
f156a00117 wpiutil uv: Pass IPC value of listening pipe to accepted pipe (#1576)
Otherwise, the acception fails.
2019-01-30 20:37:28 -08:00
Peter Johnson
608d82423d wpiutil: Use scoped connections to ensure cleanup (#1474) 2018-12-09 01:36:36 -08:00
Peter Johnson
0fb24538a7 wpiutil: HttpServerConnection: add SendStaticResponse
This function is intended for use when the content is a static const variable.
It allows gzipped static data, but doesn't provide the functionality to ungzip
it if the client doesn't support gzip.  This is because it would add a
dependency on zlib and basically all clients support gzip.

Change extraHeader on all Send functions to include the final newline,
this makes it easier to build up extra headers incrementally.

Expose sig::Connection for messageComplete and headerConn to allow them to
be disconnected by users of the class.  This is commonly needed for things
like WebSocket upgrades.
2018-12-09 00:58:04 -08:00
Peter Johnson
0b03454366 wpiutil: Replace LLVM Optional with C++17-compatible optional
Imported from https://github.com/akrzemi1/Optional with minor changes:
- Compiler conditional simplifications (we only use recent versions)
- Move from std::experimental to wpi namespace
- Change tests to integrate with Google Test

Update LLVM use cases.
2018-11-28 12:23:56 -08:00
Peter Johnson
df347e3d80 wpiutil: uv::Process: Revamp args/options approach (#1434) 2018-11-19 19:54:54 -08:00
Peter Johnson
e4aa45f34b wpiutil: WebSocket: Fix Sec-Websocket-Accept computation
It needs to use the raw SHA1 bytes, not the hex-decoded text.
2018-11-19 19:24:28 -08:00
Peter Johnson
75cc3cda28 wpiutil: SHA1: Add method to get raw bytes instead of hex 2018-11-19 19:24:28 -08:00
Peter Johnson
76f5d153fa wpiutil: Add Stop() to EventLoopRunner
This allows stopping the event loop without having to destroy the object.

Also fix ExecSync() to actually wait for the call to complete.
2018-11-09 23:33:55 -08:00
Peter Johnson
9a38a3e188 Don't use static for raw_ostream outs/errs (#1401)
Static destruction order is not well defined, so it was possible for outs()
or errs() return value to be destroyed even while other code was running,
resulting in a crash.  Instead dynamically allocate the static so the
destructor never runs.  While this technically leaks, valgrind generally
supresses such leaks as the data is still "reachable" from the static pointer.
2018-11-01 10:48:50 -07:00
Peter Johnson
9a1af132bf Unify GetHostname() and use libuv implementation (#1391) 2018-10-28 19:01:48 -07:00
Peter Johnson
172e438cd6 wpiutil: uv::Async: Keep weak reference to loop
Other handles can only be used within the loop itself, but Async is intended
to be used from another thread.  This introduces the possibility of a race
condition between the loop being destroyed and the Async being destroyed.
Change Async to keep a weak reference to a loop and check it before performing
libuv operations.
2018-10-16 09:40:59 -07:00
Peter Johnson
1a7a0db1ff wpiutil: Change uv::AsyncFunction to use promise/future.
This allows the called function to pass along the promise to another
asynchronous callback.

To avoid memory allocations, add a home-rolled, simplified, non-allocating
version of std::promise and std::future as wpi::promise and wpi::future.
2018-10-16 09:40:59 -07:00
Peter Johnson
7933d2cbe5 wpiutil: uv: Don't close uninitialized handles (#1372) 2018-10-16 00:38:48 -07:00
Peter Johnson
0a937bb5b9 wpiutil: SafeThread: Ensure thread is released in destructor (#1358)
The thread must be released with either a detach or a join, otherwise
std::terminate is called.
2018-10-06 18:07:56 -07:00
Peter Johnson
613d5eda0d wpiutil: SafeThread: join on thread exit (#1357)
This can be conditionally disabled (for cases like JNI callbacks where the JVM
may block callbacks into it during shutdown).
2018-10-06 15:17:13 -07:00
Peter Johnson
18c8cce6a7 SafeThread: Avoid use-after-free risk in thread shutdown (#1355)
Use shared_ptr to keep data alive until the thread has terminated.
2018-10-05 16:32:43 -07:00
Peter Johnson
de6d6c9a5c wpiutil: EventLoopRunner: Allow getting the loop shared_ptr. 2018-10-05 13:32:51 -07:00
Peter Johnson
164e9a2c7d wpiutil: uv::Work: Don't connect work and afterWork if they're null 2018-10-05 13:32:51 -07:00
Peter Johnson
f3fb95af70 wpiutil: uv::Tcp: Simplify reuse function 2018-10-05 13:32:51 -07:00
Peter Johnson
40a9fc44ff wpiutil: uv::Poll: add reuse functionality 2018-10-05 13:32:51 -07:00
Peter Johnson
c8482cd6d2 wpiutil: Add WebSocket implementation (#1186)
This is a RFC 6455 compliant implementation with both client and server support.
2018-08-24 20:54:23 -07:00
Peter Johnson
8d8f120cc3 EventLoopRunner: Use AsyncFunction 2018-08-20 22:21:53 -07:00
Peter Johnson
1de1900dbb Change uv::Async to accept data parameters
This is a breaking change as it makes Async a template (e.g. Async<> must
be used instead of just Async).  When data parameters are provided, an
internal mutex and vector is used to hold the parameter packs until the loop
runs.
2018-08-20 22:21:53 -07:00
Peter Johnson
4a3e43d4a7 Add HttpMultipartScanner (#1197)
This is a non-blocking version of FindMultipartBoundary.
2018-08-20 22:00:54 -07:00
Peter Johnson
9e37ee13de Add wpi::HttpServerConnection and an example of its use (#1281) 2018-08-20 13:11:39 -07:00
Peter Johnson
c25d48fd0c HttpParser: Add Reset() function (#1210)
This allows reuse of the HttpParser object for multiple requests.
2018-07-22 19:41:23 -07:00
Peter Johnson
739267d36d Add Reuse function to uv::Tcp (#1208)
This allows reusing the Tcp object in cases when the connection errors out.
2018-07-22 12:31:50 -07:00
Peter Johnson
70b0d7cb03 UDPClient: Add receive functionality (#1204) 2018-07-21 23:49:16 -07:00
Peter Johnson
297863b17a Add HttpParser and UrlParser C++ wrappers for http_parser. 2018-07-17 02:24:56 -07:00
Peter Johnson
1992b67ee3 Import nodejs/http-parser.
Upstream version: 5b76466c6b9063e2c5982423962a16f7319c81f8
2018-07-17 02:24:56 -07:00
Peter Johnson
e2314f3528 wpiutil: Add C++ libuv wrappers (#1166)
- Provide an EventLoopRunner to run uv::Loop on a separate thread.

- Add raw_ostream wrapper for uv::Buffer.
2018-07-17 01:06:24 -07:00
Tyler Veness
8c680a26f8 Moved C++ comments from source files to headers (#1111)
Also sorted functions in C++ sources to match order in related headers.
2018-05-31 20:47:15 -07:00
Peter Johnson
a2ecb1027a Update LLVM to latest upstream. (#1080)
Also change header guards to WPI header guards.
Remove StringRef::c_str() customization, replacing the handful of uses with Twine or SmallString.
TCPStream: Include errno.h and make Windows includes lowercase for consistency.

Upstream LLVM version: eb4186cca7924fb1706357545311a2fa3de40c59
2018-05-22 23:31:08 -07:00