From 66e5d0bdf39a34afa2f95ae2dc376ba31f977a9b Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 10 Aug 2019 18:58:06 +0300 Subject: Net: Store all the LocalSockets in an InlineLinkedList --- Kernel/Net/LocalSocket.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Kernel/Net/LocalSocket.cpp') diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index d9453c5e1f..11e18fd7e9 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,6 +8,21 @@ //#define DEBUG_LOCAL_SOCKET +Lockable>& LocalSocket::all_sockets() +{ + static Lockable>* s_list; + if (!s_list) + s_list = new Lockable>(); + return *s_list; +} + +void LocalSocket::for_each(Function callback) +{ + LOCKER(all_sockets().lock()); + for (auto& socket : all_sockets().resource()) + callback(socket); +} + NonnullRefPtr LocalSocket::create(int type) { return adopt(*new LocalSocket(type)); @@ -15,6 +31,8 @@ NonnullRefPtr LocalSocket::create(int type) LocalSocket::LocalSocket(int type) : Socket(AF_LOCAL, type, 0) { + LOCKER(all_sockets().lock()); + all_sockets().resource().append(this); #ifdef DEBUG_LOCAL_SOCKET kprintf("%s(%u) LocalSocket{%p} created with type=%u\n", current->process().name().characters(), current->pid(), this, type); #endif @@ -22,6 +40,8 @@ LocalSocket::LocalSocket(int type) LocalSocket::~LocalSocket() { + LOCKER(all_sockets().lock()); + all_sockets().resource().remove(this); } bool LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size) @@ -91,6 +111,7 @@ KResult LocalSocket::connect(FileDescription& description, const sockaddr* addre auto description_or_error = VFS::the().open(safe_address, 0, 0, current->process().current_directory()); if (description_or_error.is_error()) return KResult(-ECONNREFUSED); + m_file = move(description_or_error.value()); ASSERT(m_file->inode()); -- cgit v1.2.3