Skip to content

Commit

Permalink
[ntcore] Disable WebSocket fragmentation (#6149)
Browse files Browse the repository at this point in the history
There seems to be a latent bug in the fragmentation code that we've not
been able to isolate.
  • Loading branch information
PeterJohnson authored Jan 4, 2024
1 parent f29a7d2 commit 0f060af
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ntcore/src/main/native/cpp/net/WebSocketConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ void WebSocketConnection::Stream::write_impl(const char* data, size_t len) {
// flush_nonempty() case
m_conn.m_bufs.back().len = len;
if (!m_disableAlloc) {
#ifdef NT_ENABLE_WS_FRAG
m_conn.m_frames.back().opcode &= ~wpi::WebSocket::kFlagFin;
m_conn.StartFrame(wpi::WebSocket::Frame::kFragment);
#else
m_conn.m_bufs.emplace_back(m_conn.AllocBuf());
m_conn.m_bufs.back().len = 0;
++m_conn.m_frames.back().end;
#endif
SetBuffer(m_conn.m_bufs.back().base, kAllocSize);
}
return;
Expand All @@ -76,9 +82,15 @@ void WebSocketConnection::Stream::write_impl(const char* data, size_t len) {
len -= amt;
}
if (buf.len >= kAllocSize && (len > 0 || !m_disableAlloc)) {
#ifdef NT_ENABLE_WS_FRAG
// fragment the current frame and start a new one
m_conn.m_frames.back().opcode &= ~wpi::WebSocket::kFlagFin;
m_conn.StartFrame(wpi::WebSocket::Frame::kFragment);
#else
m_conn.m_bufs.emplace_back(m_conn.AllocBuf());
m_conn.m_bufs.back().len = 0;
++m_conn.m_frames.back().end;
#endif
updateBuffer = true;
}
}
Expand Down

0 comments on commit 0f060af

Please sign in to comment.