mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:27:35 +00:00
LibWebSocket: Fixed occasional infinite loop with TLS sockets
This was caused by a double notifier on the TLS socket, which caused the TLS code to freak out about not being able to read properly. In addition, the existing loop inside of drain_read() has been replaced by code that actually works, and which includes new warnings when the drain method is called before initialization is done or after the websocket gets closed.
This commit is contained in:
parent
2754112a7a
commit
812875bc89
3 changed files with 24 additions and 19 deletions
|
@ -114,19 +114,27 @@ void WebSocket::drain_read()
|
|||
return;
|
||||
}
|
||||
|
||||
while (m_impl->can_read()) {
|
||||
if (m_state == WebSocket::InternalState::WaitingForServerHandshake) {
|
||||
read_server_handshake();
|
||||
return;
|
||||
}
|
||||
if (m_state == WebSocket::InternalState::Open) {
|
||||
read_frame();
|
||||
return;
|
||||
}
|
||||
if (m_state == WebSocket::InternalState::Closing) {
|
||||
read_frame();
|
||||
return;
|
||||
}
|
||||
switch (m_state) {
|
||||
case InternalState::NotStarted:
|
||||
case InternalState::EstablishingProtocolConnection:
|
||||
case InternalState::SendingClientHandshake: {
|
||||
auto initializing_bytes = m_impl->read(1024);
|
||||
dbgln("drain_read() was called on a websocket that isn't opened yet. Read {} bytes from the socket.", initializing_bytes.size());
|
||||
} break;
|
||||
case InternalState::WaitingForServerHandshake: {
|
||||
read_server_handshake();
|
||||
} break;
|
||||
case InternalState::Open:
|
||||
case InternalState::Closing: {
|
||||
read_frame();
|
||||
} break;
|
||||
case InternalState::Closed:
|
||||
case InternalState::Errored: {
|
||||
auto closed_bytes = m_impl->read(1024);
|
||||
dbgln("drain_read() was called on a closed websocket. Read {} bytes from the socket.", closed_bytes.size());
|
||||
} break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue