mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
Kernel: Robustify and rename Inode bound socket API
Rename the bound socket accessor from socket() to bound_socket(). Also return RefPtr<LocalSocket> instead of a raw pointer, to make it harder for callers to mess up.
This commit is contained in:
parent
4bfed6a5ed
commit
cda56f8049
Notes:
sideshowbarker
2024-07-17 19:40:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cda56f8049d
@ -136,21 +136,26 @@ void Inode::set_shared_vmobject(Memory::SharedInodeVMObject& vmobject)
|
||||
m_shared_vmobject = vmobject;
|
||||
}
|
||||
|
||||
RefPtr<LocalSocket> Inode::bound_socket() const
|
||||
{
|
||||
return m_bound_socket;
|
||||
}
|
||||
|
||||
bool Inode::bind_socket(LocalSocket& socket)
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
if (m_socket)
|
||||
if (m_bound_socket)
|
||||
return false;
|
||||
m_socket = socket;
|
||||
m_bound_socket = socket;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Inode::unbind_socket()
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
if (!m_socket)
|
||||
if (!m_bound_socket)
|
||||
return false;
|
||||
m_socket = nullptr;
|
||||
m_bound_socket = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,7 @@ public:
|
||||
|
||||
virtual ErrorOr<int> get_block_address(int) { return ENOTSUP; }
|
||||
|
||||
LocalSocket* socket() { return m_socket.ptr(); }
|
||||
const LocalSocket* socket() const { return m_socket.ptr(); }
|
||||
RefPtr<LocalSocket> bound_socket() const;
|
||||
bool bind_socket(LocalSocket&);
|
||||
bool unbind_socket();
|
||||
|
||||
@ -117,7 +116,7 @@ private:
|
||||
FileSystem& m_file_system;
|
||||
InodeIndex m_index { 0 };
|
||||
WeakPtr<Memory::SharedInodeVMObject> m_shared_vmobject;
|
||||
RefPtr<LocalSocket> m_socket;
|
||||
RefPtr<LocalSocket> m_bound_socket;
|
||||
SpinlockProtected<HashTable<InodeWatcher*>> m_watchers;
|
||||
bool m_metadata_dirty { false };
|
||||
RefPtr<FIFO> m_fifo;
|
||||
|
@ -174,7 +174,9 @@ ErrorOr<void> LocalSocket::connect(OpenFileDescription& description, Userspace<c
|
||||
m_inode = inode;
|
||||
|
||||
VERIFY(inode);
|
||||
if (!inode->socket())
|
||||
|
||||
auto peer = inode->bound_socket();
|
||||
if (!peer)
|
||||
return set_so_error(ECONNREFUSED);
|
||||
|
||||
m_path = move(path);
|
||||
@ -182,7 +184,6 @@ ErrorOr<void> LocalSocket::connect(OpenFileDescription& description, Userspace<c
|
||||
VERIFY(m_connect_side_fd == &description);
|
||||
set_connect_side_role(Role::Connecting);
|
||||
|
||||
auto peer = file->inode()->socket();
|
||||
auto result = peer->queue_connection_from(*this);
|
||||
if (result.is_error()) {
|
||||
set_connect_side_role(Role::None);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Net/LocalSocket.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
namespace Kernel {
|
||||
@ -56,7 +57,7 @@ ErrorOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> use
|
||||
|
||||
auto description = TRY(VirtualFileSystem::the().open(path->view(), options, mode & ~umask(), *base));
|
||||
|
||||
if (description->inode() && description->inode()->socket())
|
||||
if (description->inode() && description->inode()->bound_socket())
|
||||
return ENXIO;
|
||||
|
||||
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||
|
Loading…
Reference in New Issue
Block a user