Skip to content

Commit

Permalink
[ntcore] Fix EALREADY errors by tracking read state (#7202)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored and katzuv committed Oct 14, 2024
1 parent 88bd0e8 commit 709c553
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions ntcore/src/main/native/cpp/net/WebSocketConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ class WebSocketConnection final
return m_ws.GetLastReceivedTime();
}

void StopRead() final { m_ws.GetStream().StopRead(); }
void StartRead() final { m_ws.GetStream().StartRead(); }
void StopRead() final {
if (m_readActive) {
m_ws.GetStream().StopRead();
m_readActive = false;
}
}
void StartRead() final {
if (!m_readActive) {
m_ws.GetStream().StartRead();
m_readActive = true;
}
}

void Disconnect(std::string_view reason) final;

Expand All @@ -80,6 +90,7 @@ class WebSocketConnection final

wpi::WebSocket& m_ws;
wpi::Logger& m_logger;
bool m_readActive = true;

class Stream;

Expand Down
15 changes: 13 additions & 2 deletions ntcore/src/main/native/cpp/net3/UvStreamConnection3.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ class UvStreamConnection3 final

uint64_t GetLastFlushTime() const final { return m_lastFlushTime; }

void StopRead() final { m_stream.StopRead(); }
void StartRead() final { m_stream.StartRead(); }
void StopRead() final {
if (m_readActive) {
m_stream.StopRead();
m_readActive = false;
}
}
void StartRead() final {
if (!m_readActive) {
m_stream.StartRead();
m_readActive = true;
}
}

void Disconnect(std::string_view reason) final;

Expand All @@ -62,6 +72,7 @@ class UvStreamConnection3 final
std::string m_reason;
uint64_t m_lastFlushTime = 0;
int m_sendsActive = 0;
bool m_readActive = true;
};

} // namespace nt::net3

0 comments on commit 709c553

Please sign in to comment.