mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
IPv4: Keep IPv4 socket locked during receive operations
We unlock/relock around blocking, but outside of that we now keep the socket locked. This fixes an intermittent ASSERT(m_can_read) failure.
This commit is contained in:
parent
7a9cb2dfca
commit
f2f16e1c24
1 changed files with 6 additions and 3 deletions
|
@ -238,15 +238,17 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
||||||
|
|
||||||
ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* buffer, size_t buffer_length, int, sockaddr*, socklen_t*)
|
ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* buffer, size_t buffer_length, int, sockaddr*, socklen_t*)
|
||||||
{
|
{
|
||||||
|
Locker locker(lock());
|
||||||
if (m_receive_buffer.is_empty()) {
|
if (m_receive_buffer.is_empty()) {
|
||||||
if (protocol_is_disconnected())
|
if (protocol_is_disconnected())
|
||||||
return 0;
|
return 0;
|
||||||
if (!description.is_blocking())
|
if (!description.is_blocking())
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
|
||||||
|
locker.unlock();
|
||||||
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
||||||
|
locker.lock();
|
||||||
|
|
||||||
LOCKER(lock());
|
|
||||||
if (!m_can_read) {
|
if (!m_can_read) {
|
||||||
if (res != Thread::BlockResult::WokeNormally)
|
if (res != Thread::BlockResult::WokeNormally)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
|
@ -267,9 +269,9 @@ ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* bu
|
||||||
|
|
||||||
ssize_t IPv4Socket::receive_packet_buffered(FileDescription& description, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
ssize_t IPv4Socket::receive_packet_buffered(FileDescription& description, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
||||||
{
|
{
|
||||||
|
Locker locker(lock());
|
||||||
ReceivedPacket packet;
|
ReceivedPacket packet;
|
||||||
{
|
{
|
||||||
LOCKER(lock());
|
|
||||||
if (m_receive_queue.is_empty()) {
|
if (m_receive_queue.is_empty()) {
|
||||||
// FIXME: Shouldn't this return -ENOTCONN instead of EOF?
|
// FIXME: Shouldn't this return -ENOTCONN instead of EOF?
|
||||||
// But if so, we still need to deliver at least one EOF read to userspace.. right?
|
// But if so, we still need to deliver at least one EOF read to userspace.. right?
|
||||||
|
@ -293,9 +295,10 @@ ssize_t IPv4Socket::receive_packet_buffered(FileDescription& description, void*
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locker.unlock();
|
||||||
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
auto res = Thread::current->block<Thread::ReadBlocker>(description);
|
||||||
|
locker.lock();
|
||||||
|
|
||||||
LOCKER(lock());
|
|
||||||
if (!m_can_read) {
|
if (!m_can_read) {
|
||||||
if (res != Thread::BlockResult::WokeNormally)
|
if (res != Thread::BlockResult::WokeNormally)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue