mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
LibIPC: Check if socket is still open before using socket descriptor
Writing to the socket may trigger a close of the socket descriptor if a disconnect was detected. We need to check if it is still valid when waiting for a response after attempting to send a synchronous message. Fixes #3515
This commit is contained in:
parent
1720030625
commit
5ee29e8a26
1 changed files with 5 additions and 2 deletions
|
@ -140,6 +140,8 @@ protected:
|
|||
return m_unprocessed_messages.take(i).template release_nonnull<MessageType>();
|
||||
}
|
||||
|
||||
if (!m_socket->is_open())
|
||||
break;
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(m_socket->fd(), &rfds);
|
||||
|
@ -150,14 +152,15 @@ protected:
|
|||
ASSERT(rc > 0);
|
||||
ASSERT(FD_ISSET(m_socket->fd(), &rfds));
|
||||
if (!drain_messages_from_peer())
|
||||
return nullptr;
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool drain_messages_from_peer()
|
||||
{
|
||||
Vector<u8> bytes;
|
||||
for (;;) {
|
||||
while (m_socket->is_open()) {
|
||||
u8 buffer[4096];
|
||||
ssize_t nread = recv(m_socket->fd(), buffer, sizeof(buffer), MSG_DONTWAIT);
|
||||
if (nread < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue