Skip to content

Commit

Permalink
[ntcore] Add StopRead/StartRead to WireConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Oct 11, 2024
1 parent 28cb7cf commit 0e59f2c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ntcore/src/main/native/cpp/net/WebSocketConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <wpi/function_ref.h>
#include <wpinet/WebSocket.h>
#include <wpinet/uv/Buffer.h>
#include <wpinet/uv/Stream.h>

#include "WireConnection.h"

Expand Down Expand Up @@ -58,6 +59,9 @@ class WebSocketConnection final
return m_ws.GetLastReceivedTime();
}

void StopRead() final { m_ws.GetStream().StopRead(); }
void StartRead() final { m_ws.GetStream().StartRead(); }

void Disconnect(std::string_view reason) final;

std::string_view GetDisconnectReason() const { return m_reason; }
Expand Down
3 changes: 3 additions & 0 deletions ntcore/src/main/native/cpp/net/WireConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class WireConnection {
// Gets the timestamp of the last incoming data
virtual uint64_t GetLastReceivedTime() const = 0; // in microseconds

virtual void StopRead() = 0;
virtual void StartRead() = 0;

virtual void Disconnect(std::string_view reason) = 0;
};

Expand Down
4 changes: 4 additions & 0 deletions ntcore/src/main/native/cpp/net3/UvStreamConnection3.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <wpi/SmallVector.h>
#include <wpinet/raw_uv_ostream.h>
#include <wpinet/uv/Buffer.h>
#include <wpinet/uv/Stream.h>

#include "net3/WireConnection3.h"

Expand Down Expand Up @@ -40,6 +41,9 @@ class UvStreamConnection3 final

uint64_t GetLastFlushTime() const final { return m_lastFlushTime; }

void StopRead() final { m_stream.StopRead(); }
void StartRead() final { m_stream.StartRead(); }

void Disconnect(std::string_view reason) final;

std::string_view GetDisconnectReason() const { return m_reason; }
Expand Down
3 changes: 3 additions & 0 deletions ntcore/src/main/native/cpp/net3/WireConnection3.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class WireConnection3 {

virtual uint64_t GetLastFlushTime() const = 0; // in microseconds

virtual void StopRead() = 0;
virtual void StartRead() = 0;

virtual void Disconnect(std::string_view reason) = 0;

protected:
Expand Down
3 changes: 3 additions & 0 deletions ntcore/src/test/native/cpp/net/MockWireConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class MockWireConnection : public WireConnection {
MOCK_METHOD(uint64_t, GetLastFlushTime, (), (const, override));
MOCK_METHOD(uint64_t, GetLastReceivedTime, (), (const, override));

MOCK_METHOD(void, StopRead, (), (override));
MOCK_METHOD(void, StartRead, (), (override));

MOCK_METHOD(void, Disconnect, (std::string_view reason), (override));
};

Expand Down
3 changes: 3 additions & 0 deletions ntcore/src/test/native/cpp/net3/MockWireConnection3.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class MockWireConnection3 : public WireConnection3 {

MOCK_METHOD(uint64_t, GetLastFlushTime, (), (const, override));

MOCK_METHOD(void, StopRead, (), (override));
MOCK_METHOD(void, StartRead, (), (override));

MOCK_METHOD(void, Disconnect, (std::string_view reason), (override));

protected:
Expand Down

0 comments on commit 0e59f2c

Please sign in to comment.