mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:27:43 +00:00
Kernel: Migrate TCP socket tables locking to ProtectedValue
Note: TCPSocket::create_client() has a dubious locking process where the sockets by tuple table is first shared lock to check if the socket exists and bail out if it does, then unlocks, then exclusively locks to add the tuple. There could be a race condition where two client creation requests for the same tuple happen at the same time and both cleared the shared lock check. When in doubt, lock exclusively the whole time.
This commit is contained in:
parent
583abc27d8
commit
9216c72bfe
3 changed files with 90 additions and 85 deletions
|
@ -11,7 +11,7 @@
|
|||
#include <AK/SinglyLinkedList.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <Kernel/KResult.h>
|
||||
#include <Kernel/Locking/Lockable.h>
|
||||
#include <Kernel/Locking/ProtectedValue.h>
|
||||
#include <Kernel/Net/IPv4Socket.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -142,10 +142,10 @@ public:
|
|||
|
||||
bool should_delay_next_ack() const;
|
||||
|
||||
static Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& sockets_by_tuple();
|
||||
static ProtectedValue<HashMap<IPv4SocketTuple, TCPSocket*>>& sockets_by_tuple();
|
||||
static RefPtr<TCPSocket> from_tuple(const IPv4SocketTuple& tuple);
|
||||
|
||||
static Lockable<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& closing_sockets();
|
||||
static ProtectedValue<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& closing_sockets();
|
||||
|
||||
RefPtr<TCPSocket> create_client(const IPv4Address& local_address, u16 local_port, const IPv4Address& peer_address, u16 peer_port);
|
||||
void set_originator(TCPSocket& originator) { m_originator = originator; }
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
void release_to_originator();
|
||||
void release_for_accept(RefPtr<TCPSocket>);
|
||||
|
||||
static Lockable<HashTable<TCPSocket*>>& sockets_for_retransmit();
|
||||
static ProtectedValue<HashTable<TCPSocket*>>& sockets_for_retransmit();
|
||||
void retransmit_packets();
|
||||
|
||||
virtual KResult close() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue