Commit Graph

48 Commits

Author SHA1 Message Date
Peter Johnson
77edf1e103 Add FRC Driver Station connection support.
The 2017 FRC Driver Station supports getting the robot IP via a TCP
connection that returns JSON.  Use this to support overriding the
server IP address used for client connections.

Default to using this approach for client connections in the NetworkTable
interfaces.

Add support for setting the server address without stopping and
restarting the client.

SetTeam now also round-robins by default.
2016-11-04 23:42:41 -07:00
Thad House
05ca76ea99 Runs clang-format on ntcore (#150)
Also updates .clang-format to match allwpilib

WPIUtil was skipped
2016-11-03 21:03:45 -07:00
Peter Johnson
273a395a2f Client: when reconnecting, default to NT3. (#143)
Previously once the client fell back once to NT2, it would never try
connecting as NT3 even if the server was replaced with a NT3-capable
one.

Fixes #142.
2016-10-25 21:44:47 -07:00
Peter Johnson
1d336996be Dispatcher: Minimize amount of time m_flush_mutex is held. (#132) 2016-10-21 20:01:41 -07:00
Peter Johnson
86c43df8d1 Fix connection notification races. (#130)
Use a mutex on the connection state and one-shot all change notifications.

Fixes #127.
2016-10-21 19:40:56 -07:00
Thad House
780e9580b7 Ignores KeepAlive messages during initial handshakes (#128)
Shouldn't happen normally, but could happen if handshakes take a longer
then normal period of time.
Closes #126
2016-10-19 22:47:33 -07:00
Peter Johnson
1635cba827 Reduced minimum update rate from 100 ms to 10 ms. (#89) 2016-08-16 12:07:17 -07:00
Peter Johnson
a73166a665 Make many more utility classes/headers public. (#76)
Moving these headers from src to include enables other libraries to use the
functionality provided.

* tcpsockets
* atomic_static
* raw_istream
* timestamp
* SafeThread
* Base64
* LEB128
* ConcurrentQueue

The classes have been moved into the wpi namespace as they're generic.
2016-07-27 00:39:38 -07:00
Peter Johnson
5ac68f74d4 Support client round robin to multiple server addresses.
Change-Id: If87dc64a485b1c8a340c5f6fa39ca09d40133e30
2016-04-08 22:02:52 -07:00
Peter Johnson
44821c3e3c Change how Dispatcher is shut down.
The previous use of a timeout resulting in thread detach instead of thread
join resulted in a race condition on Mac between destruction and thread
closeout.  This commit removes the detach functionality and uses dup2() to
on Linux/Mac and connecting to itself on Windows to try to ensure accept()
exits.
2015-12-23 08:08:53 -08:00
Peter Johnson
e25d9fc96a Use correct condition variable in DispatchThreadMain(). 2015-12-11 21:13:41 -08:00
Peter Johnson
9f5fe63aaa Reuse dead connection slots.
This fixes a memory leak on multiple disconnect/reconnect of the same client.
2015-11-01 22:48:11 -08:00
Peter Johnson
03ee425e5f Add additional debug messages. 2015-11-01 22:48:11 -08:00
Peter Johnson
dd0e3e4abb Implement join with timeout (and detach).
Under certain situations (notably JNI shutdown), it's possible to get
deadlock when using thread join().  To avoid this, implement a timeout.
Normally we try to simply join the thread, but if it times out, we
detach the thread instead.
2015-10-09 23:50:01 -07:00
Peter Johnson
6d8e796932 Disable logging on static instance destruction.
This avoids possible deadlocks on exit when a logger callback exists.
2015-09-12 21:44:51 -07:00
Peter Johnson
f7e603c7db Add DEBUG4 message for messages received during client handshake. 2015-09-11 19:19:15 -07:00
Peter Johnson
953a2ce807 Implement keep-alives. 2015-09-08 23:17:11 -07:00
Peter Johnson
e1efb7364e Don't allow update intervals slower than 1 second. 2015-09-06 11:41:35 -07:00
Peter Johnson
7565207242 StartClient(): Make a local copy of server_name.
Previously we just held onto the const char* provided by the user.
This does not work in cases such as Java which provide a temporary
string.
2015-08-29 00:07:10 -07:00
Peter Johnson
b488cdd6ff Support immediate notify of connection listener.
Also only perform immediate notification to the callback actually
requesting the notification, not all existing callbacks.

Offset returned uids by 1 so uid=0 can be used to indicate immediate
notification.
2015-08-28 00:13:56 -07:00
Peter Johnson
2d1bc2f4c7 Uninline constructors to reduce GetInstance() inlined code size. 2015-08-19 21:49:18 -07:00
Peter Johnson
c6bed1f464 Dispatcher: Move several fixed initial values to header. 2015-08-19 21:16:44 -07:00
Peter Johnson
ca9ce0f3a3 Implement automatic persistent saves.
Also loads persistent file on server start.
2015-08-19 19:18:09 -07:00
Peter Johnson
8d7cdeabbf Implement remote procedure calls. 2015-08-13 21:32:16 -07:00
Peter Johnson
a86f65db1e Dispatcher: Implement transmit combining.
This handles most of the major cases, but not a loop of delete/assign, which
should be uncommon anyway.
2015-08-02 23:21:23 -07:00
Peter Johnson
e9073a3cc0 Implement notifiers.
The notifier thread is lazily started when the first notifier is added.
This avoids the extra thread/processing overhead when notifiers are not used.
2015-08-02 21:47:01 -07:00
Peter Johnson
538a19fd47 Implement GetConnections(). 2015-08-02 10:47:05 -07:00
Peter Johnson
84ff80710c Refactor TCP-specific pieces of Dispatcher. 2015-08-02 00:33:41 -07:00
Peter Johnson
6703968f73 Dispatcher: Fix shutdown order race.
We need to wait until after the dispatch and client/server threads have
been stopped before closing connections, as these threads can add connections.
2015-08-01 23:37:13 -07:00
Peter Johnson
b5274a495e Dispatcher: Don't call Storage::GetInstance() internally.
This makes it difficult to test.  Instead, store reference as member variable,
and populate it at constuction (with an alternate constructor available for
test purposes).
2015-08-01 11:15:04 -07:00
Peter Johnson
11508b77d1 Ensure initial synchronization is atomic. 2015-07-31 23:56:06 -07:00
Peter Johnson
c2eb4a766e Dispatcher: Provide some INFO-level connection messages. 2015-07-31 23:26:38 -07:00
Peter Johnson
3a71acec52 Automatically reconnect client.
Also clean up some condition variable handling to make it more robust.
2015-07-31 23:14:26 -07:00
Peter Johnson
a9af4589ac Don't send empty message lists from dispatch.
This terminates the write thread.
2015-07-31 22:49:43 -07:00
Peter Johnson
4356e313ec Add logging framework.
DEBUG messages are completely optimized out if NDEBUG is defined.
2015-07-31 22:41:26 -07:00
Peter Johnson
ead125555c Implement client/server handshaking. 2015-07-31 20:32:52 -07:00
Peter Johnson
138ebf5b4d Storage: generate messages rather than intermediate updates. 2015-07-31 13:21:19 -07:00
Peter Johnson
83be99e78c Immediately process incoming messages.
This required moving message processing into the Storage class.
2015-07-29 23:45:04 -07:00
Peter Johnson
5b5e3ae6aa Dispatcher: Start implementing processing of incoming messages. 2015-07-29 20:33:26 -07:00
Peter Johnson
b4c65dc210 Make global instance init thread-safe.
Use local statics except for Visual C++ < 2015.
2015-07-20 23:36:22 -07:00
Peter Johnson
6b2fb02bed Dispatcher: Don't in-place construct atomics.
Visual C++ 2013 doesn't support this.
2015-07-20 20:21:37 -07:00
Peter Johnson
8938a19810 Dispatcher: Avoid warning by using for(;;) instead of while(true). 2015-07-20 20:20:01 -07:00
Peter Johnson
158ae61811 Dispatcher::SetUpdateRate(): Explicitly convert to int. 2015-07-20 20:19:01 -07:00
Peter Johnson
c9260ea785 Change GetEntryTypeFunc to std::function.
Also implement it as a member function of Dispatcher.
2015-07-19 23:17:14 -07:00
Peter Johnson
9b7e265762 Continue implementing client. 2015-07-18 01:29:24 -07:00
Peter Johnson
412e8034de Start implementing client and server. 2015-07-17 22:39:36 -07:00
Peter Johnson
fcbd2751ba Provide C++ API. Move all classes to "nt" namespace.
The C API is now just simple wrappers around the C++ API.
2015-07-17 07:21:07 -07:00
Peter Johnson
56f1481c24 Add Dispatcher. 2015-07-16 22:55:50 -07:00