mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Kernel: Use RefPtr instead of LockRefPtr for File and subclasses
This was mostly straightforward, as all the storage locations are guarded by some related mutex. The use of old-school associated mutexes instead of MutexProtected is unfortunate, but the process to modernize such code is ongoing.
This commit is contained in:
parent
61bb9103c2
commit
03cc45e5a2
Notes:
sideshowbarker
2024-07-16 23:23:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/03cc45e5a2
@ -13,9 +13,9 @@ namespace Kernel {
|
||||
|
||||
class AnonymousFile final : public File {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<AnonymousFile>> try_create(NonnullLockRefPtr<Memory::AnonymousVMObject> vmobject)
|
||||
static ErrorOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullLockRefPtr<Memory::AnonymousVMObject> vmobject)
|
||||
{
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
|
||||
}
|
||||
|
||||
virtual ~AnonymousFile() override;
|
||||
|
@ -16,10 +16,10 @@ namespace Kernel {
|
||||
|
||||
static Atomic<int> s_next_fifo_id = 1;
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<FIFO>> FIFO::try_create(UserID uid)
|
||||
ErrorOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
|
||||
{
|
||||
auto buffer = TRY(DoubleBuffer::try_create("FIFO: Buffer"sv));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
Writer
|
||||
};
|
||||
|
||||
static ErrorOr<NonnullLockRefPtr<FIFO>> try_create(UserID);
|
||||
static ErrorOr<NonnullRefPtr<FIFO>> try_create(UserID);
|
||||
virtual ~FIFO() override;
|
||||
|
||||
UserID uid() const { return m_uid; }
|
||||
|
@ -180,7 +180,7 @@ void Inode::unregister_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<FIFO>> Inode::fifo()
|
||||
ErrorOr<NonnullRefPtr<FIFO>> Inode::fifo()
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
VERIFY(metadata().is_fifo());
|
||||
@ -189,7 +189,7 @@ ErrorOr<NonnullLockRefPtr<FIFO>> Inode::fifo()
|
||||
if (!m_fifo)
|
||||
m_fifo = TRY(FIFO::try_create(metadata().uid));
|
||||
|
||||
return NonnullLockRefPtr { *m_fifo };
|
||||
return NonnullRefPtr { *m_fifo };
|
||||
}
|
||||
|
||||
void Inode::set_metadata_dirty(bool metadata_dirty)
|
||||
|
@ -102,7 +102,7 @@ public:
|
||||
ErrorOr<void> register_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<FIFO>> fifo();
|
||||
ErrorOr<NonnullRefPtr<FIFO>> fifo();
|
||||
|
||||
bool can_apply_flock(flock const&, Optional<OpenFileDescription const&> = {}) const;
|
||||
ErrorOr<void> apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>, ShouldBlock);
|
||||
@ -134,7 +134,7 @@ private:
|
||||
LockWeakPtr<LocalSocket> m_bound_socket;
|
||||
SpinlockProtected<HashTable<InodeWatcher*>, LockRank::None> m_watchers {};
|
||||
bool m_metadata_dirty { false };
|
||||
LockRefPtr<FIFO> m_fifo;
|
||||
RefPtr<FIFO> m_fifo;
|
||||
IntrusiveListNode<Inode> m_inode_list_node;
|
||||
|
||||
struct Flock {
|
||||
|
@ -14,9 +14,9 @@ class Inode;
|
||||
|
||||
class InodeFile final : public File {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<InodeFile>> create(NonnullRefPtr<Inode> inode)
|
||||
static ErrorOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode> inode)
|
||||
{
|
||||
auto file = adopt_lock_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
|
||||
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
|
||||
if (!file)
|
||||
return ENOMEM;
|
||||
return file.release_nonnull();
|
||||
|
@ -11,9 +11,9 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<InodeWatcher>> InodeWatcher::try_create()
|
||||
ErrorOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::try_create()
|
||||
{
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) InodeWatcher);
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) InodeWatcher);
|
||||
}
|
||||
|
||||
InodeWatcher::~InodeWatcher()
|
||||
|
@ -40,7 +40,7 @@ private:
|
||||
|
||||
class InodeWatcher final : public File {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<InodeWatcher>> try_create();
|
||||
static ErrorOr<NonnullRefPtr<InodeWatcher>> try_create();
|
||||
virtual ~InodeWatcher() override;
|
||||
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
||||
|
@ -141,7 +141,7 @@ private:
|
||||
}
|
||||
|
||||
RefPtr<Inode> m_inode;
|
||||
NonnullLockRefPtr<File> m_file;
|
||||
NonnullRefPtr<File> m_file;
|
||||
|
||||
struct State {
|
||||
OwnPtr<OpenFileDescriptionData> data;
|
||||
|
@ -40,7 +40,7 @@ ErrorOr<NonnullOwnPtr<DoubleBuffer>> IPv4Socket::try_create_receive_buffer()
|
||||
return DoubleBuffer::try_create("IPv4Socket: Receive buffer"sv, 256 * KiB);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||
ErrorOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||
{
|
||||
auto receive_buffer = TRY(IPv4Socket::try_create_receive_buffer());
|
||||
|
||||
@ -49,7 +49,7 @@ ErrorOr<NonnullLockRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||
if (type == SOCK_DGRAM)
|
||||
return TRY(UDPSocket::try_create(protocol, move(receive_buffer)));
|
||||
if (type == SOCK_RAW) {
|
||||
auto raw_socket = adopt_lock_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, move(receive_buffer), {}));
|
||||
auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, move(receive_buffer), {}));
|
||||
if (raw_socket)
|
||||
return raw_socket.release_nonnull();
|
||||
return ENOMEM;
|
||||
|
@ -28,7 +28,7 @@ struct PortAllocationResult {
|
||||
|
||||
class IPv4Socket : public Socket {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<Socket>> create(int type, int protocol);
|
||||
static ErrorOr<NonnullRefPtr<Socket>> create(int type, int protocol);
|
||||
virtual ~IPv4Socket() override;
|
||||
|
||||
virtual ErrorOr<void> close() override;
|
||||
|
@ -43,11 +43,11 @@ ErrorOr<void> LocalSocket::try_for_each(Function<ErrorOr<void>(LocalSocket const
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<LocalSocket>> LocalSocket::try_create(int type)
|
||||
ErrorOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
|
||||
{
|
||||
auto client_buffer = TRY(DoubleBuffer::try_create("LocalSocket: Client buffer"sv));
|
||||
auto server_buffer = TRY(DoubleBuffer::try_create("LocalSocket: Server buffer"sv));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) LocalSocket(type, move(client_buffer), move(server_buffer)));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) LocalSocket(type, move(client_buffer), move(server_buffer)));
|
||||
}
|
||||
|
||||
ErrorOr<SocketPair> LocalSocket::try_create_connected_pair(int type)
|
||||
|
@ -22,7 +22,7 @@ struct SocketPair {
|
||||
class LocalSocket final : public Socket {
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<LocalSocket>> try_create(int type);
|
||||
static ErrorOr<NonnullRefPtr<LocalSocket>> try_create(int type);
|
||||
static ErrorOr<SocketPair> try_create_connected_pair(int type);
|
||||
virtual ~LocalSocket() override;
|
||||
|
||||
|
@ -30,13 +30,13 @@ static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Time cons
|
||||
static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void handle_udp(IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void handle_tcp(IPv4Packet const&, Time const& packet_timestamp);
|
||||
static void send_delayed_tcp_ack(LockRefPtr<TCPSocket> socket);
|
||||
static void send_delayed_tcp_ack(TCPSocket& socket);
|
||||
static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, LockRefPtr<NetworkAdapter> adapter);
|
||||
static void flush_delayed_tcp_acks();
|
||||
static void retransmit_tcp_packets();
|
||||
|
||||
static Thread* network_task = nullptr;
|
||||
static HashTable<LockRefPtr<TCPSocket>>* delayed_ack_sockets;
|
||||
static HashTable<NonnullRefPtr<TCPSocket>>* delayed_ack_sockets;
|
||||
|
||||
[[noreturn]] static void NetworkTask_main(void*);
|
||||
|
||||
@ -57,7 +57,7 @@ bool NetworkTask::is_current()
|
||||
|
||||
void NetworkTask_main(void*)
|
||||
{
|
||||
delayed_ack_sockets = new HashTable<LockRefPtr<TCPSocket>>;
|
||||
delayed_ack_sockets = new HashTable<NonnullRefPtr<TCPSocket>>;
|
||||
|
||||
WaitQueue packet_wait_queue;
|
||||
int pending_packets = 0;
|
||||
@ -229,7 +229,7 @@ void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet,
|
||||
dbgln_if(ICMP_DEBUG, "handle_icmp: source={}, destination={}, type={:#02x}, code={:#02x}", ipv4_packet.source().to_string(), ipv4_packet.destination().to_string(), icmp_header.type(), icmp_header.code());
|
||||
|
||||
{
|
||||
Vector<NonnullLockRefPtr<IPv4Socket>> icmp_sockets;
|
||||
Vector<NonnullRefPtr<IPv4Socket>> icmp_sockets;
|
||||
IPv4Socket::all_sockets().with_exclusive([&](auto& sockets) {
|
||||
for (auto& socket : sockets) {
|
||||
if (socket.protocol() == (unsigned)IPv4Protocol::ICMP)
|
||||
@ -302,11 +302,11 @@ void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
|
||||
}
|
||||
|
||||
void send_delayed_tcp_ack(LockRefPtr<TCPSocket> socket)
|
||||
void send_delayed_tcp_ack(TCPSocket& socket)
|
||||
{
|
||||
VERIFY(socket->mutex().is_locked());
|
||||
if (!socket->should_delay_next_ack()) {
|
||||
[[maybe_unused]] auto result = socket->send_ack();
|
||||
VERIFY(socket.mutex().is_locked());
|
||||
if (!socket.should_delay_next_ack()) {
|
||||
[[maybe_unused]] auto result = socket.send_ack();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -315,11 +315,11 @@ void send_delayed_tcp_ack(LockRefPtr<TCPSocket> socket)
|
||||
|
||||
void flush_delayed_tcp_acks()
|
||||
{
|
||||
Vector<LockRefPtr<TCPSocket>, 32> remaining_sockets;
|
||||
Vector<NonnullRefPtr<TCPSocket>, 32> remaining_sockets;
|
||||
for (auto& socket : *delayed_ack_sockets) {
|
||||
MutexLocker locker(socket->mutex());
|
||||
if (socket->should_delay_next_ack()) {
|
||||
MUST(remaining_sockets.try_append(socket));
|
||||
MUST(remaining_sockets.try_append(*socket));
|
||||
continue;
|
||||
}
|
||||
[[maybe_unused]] auto result = socket->send_ack();
|
||||
@ -484,7 +484,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
return;
|
||||
case TCPFlags::ACK | TCPFlags::FIN:
|
||||
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
|
||||
send_delayed_tcp_ack(socket);
|
||||
send_delayed_tcp_ack(*socket);
|
||||
socket->set_state(TCPSocket::State::Closed);
|
||||
socket->set_error(TCPSocket::Error::FINDuringConnect);
|
||||
socket->set_setup_state(Socket::SetupState::Completed);
|
||||
@ -636,7 +636,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
|
||||
|
||||
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
|
||||
send_delayed_tcp_ack(socket);
|
||||
send_delayed_tcp_ack(*socket);
|
||||
socket->set_state(TCPSocket::State::CloseWait);
|
||||
socket->set_connected(false);
|
||||
return;
|
||||
@ -647,7 +647,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
|
||||
socket->set_ack_number(tcp_packet.sequence_number() + payload_size);
|
||||
dbgln_if(TCP_DEBUG, "Got packet with ack_no={}, seq_no={}, payload_size={}, acking it with new ack_no={}, seq_no={}",
|
||||
tcp_packet.ack_number(), tcp_packet.sequence_number(), payload_size, socket->ack_number(), socket->sequence_number());
|
||||
send_delayed_tcp_ack(socket);
|
||||
send_delayed_tcp_ack(*socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -657,7 +657,7 @@ void retransmit_tcp_packets()
|
||||
{
|
||||
// We must keep the sockets alive until after we've unlocked the hash table
|
||||
// in case retransmit_packets() realizes that it wants to close the socket.
|
||||
Vector<NonnullLockRefPtr<TCPSocket>, 16> sockets;
|
||||
Vector<NonnullRefPtr<TCPSocket>, 16> sockets;
|
||||
TCPSocket::sockets_for_retransmit().for_each_shared([&](auto const& socket) {
|
||||
// We ignore allocation failures above the first 16 guaranteed socket slots, as
|
||||
// we will just retransmit their packets the next time around
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
|
||||
ErrorOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
|
||||
{
|
||||
switch (domain) {
|
||||
case AF_LOCAL:
|
||||
@ -46,7 +46,7 @@ void Socket::set_setup_state(SetupState new_setup_state)
|
||||
evaluate_block_conditions();
|
||||
}
|
||||
|
||||
LockRefPtr<Socket> Socket::accept()
|
||||
RefPtr<Socket> Socket::accept()
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
if (m_pending.is_empty())
|
||||
@ -63,7 +63,7 @@ LockRefPtr<Socket> Socket::accept()
|
||||
return client;
|
||||
}
|
||||
|
||||
ErrorOr<void> Socket::queue_connection_from(NonnullLockRefPtr<Socket> peer)
|
||||
ErrorOr<void> Socket::queue_connection_from(NonnullRefPtr<Socket> peer)
|
||||
{
|
||||
dbgln_if(SOCKET_DEBUG, "Socket({}) queueing connection", this);
|
||||
MutexLocker locker(mutex());
|
||||
|
@ -20,7 +20,7 @@ class OpenFileDescription;
|
||||
|
||||
class Socket : public File {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<Socket>> create(int domain, int type, int protocol);
|
||||
static ErrorOr<NonnullRefPtr<Socket>> create(int domain, int type, int protocol);
|
||||
virtual ~Socket() override;
|
||||
|
||||
int domain() const { return m_domain; }
|
||||
@ -67,7 +67,7 @@ public:
|
||||
void set_connected(bool);
|
||||
|
||||
bool can_accept() const { return !m_pending.is_empty(); }
|
||||
LockRefPtr<Socket> accept();
|
||||
RefPtr<Socket> accept();
|
||||
|
||||
ErrorOr<void> shutdown(int how);
|
||||
|
||||
@ -111,7 +111,7 @@ public:
|
||||
protected:
|
||||
Socket(int domain, int type, int protocol);
|
||||
|
||||
ErrorOr<void> queue_connection_from(NonnullLockRefPtr<Socket>);
|
||||
ErrorOr<void> queue_connection_from(NonnullRefPtr<Socket>);
|
||||
|
||||
size_t backlog() const { return m_backlog; }
|
||||
void set_backlog(size_t backlog) { m_backlog = backlog; }
|
||||
@ -181,7 +181,7 @@ private:
|
||||
|
||||
Optional<ErrnoCode> m_so_error;
|
||||
|
||||
Vector<NonnullLockRefPtr<Socket>> m_pending;
|
||||
Vector<NonnullRefPtr<Socket>> m_pending;
|
||||
};
|
||||
|
||||
// This is a special variant of TRY() that also updates the socket's SO_ERROR field on error.
|
||||
|
@ -88,9 +88,9 @@ void TCPSocket::set_state(State new_state)
|
||||
evaluate_block_conditions();
|
||||
}
|
||||
|
||||
static Singleton<MutexProtected<HashMap<IPv4SocketTuple, LockRefPtr<TCPSocket>>>> s_socket_closing;
|
||||
static Singleton<MutexProtected<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>> s_socket_closing;
|
||||
|
||||
MutexProtected<HashMap<IPv4SocketTuple, LockRefPtr<TCPSocket>>>& TCPSocket::closing_sockets()
|
||||
MutexProtected<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& TCPSocket::closing_sockets()
|
||||
{
|
||||
return *s_socket_closing;
|
||||
}
|
||||
@ -102,9 +102,9 @@ MutexProtected<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tupl
|
||||
return *s_socket_tuples;
|
||||
}
|
||||
|
||||
LockRefPtr<TCPSocket> TCPSocket::from_tuple(IPv4SocketTuple const& tuple)
|
||||
RefPtr<TCPSocket> TCPSocket::from_tuple(IPv4SocketTuple const& tuple)
|
||||
{
|
||||
return sockets_by_tuple().with_shared([&](auto const& table) -> LockRefPtr<TCPSocket> {
|
||||
return sockets_by_tuple().with_shared([&](auto const& table) -> RefPtr<TCPSocket> {
|
||||
auto exact_match = table.get(tuple);
|
||||
if (exact_match.has_value())
|
||||
return { *exact_match.value() };
|
||||
@ -122,10 +122,10 @@ LockRefPtr<TCPSocket> TCPSocket::from_tuple(IPv4SocketTuple const& tuple)
|
||||
return {};
|
||||
});
|
||||
}
|
||||
ErrorOr<NonnullLockRefPtr<TCPSocket>> TCPSocket::try_create_client(IPv4Address const& new_local_address, u16 new_local_port, IPv4Address const& new_peer_address, u16 new_peer_port)
|
||||
ErrorOr<NonnullRefPtr<TCPSocket>> TCPSocket::try_create_client(IPv4Address const& new_local_address, u16 new_local_port, IPv4Address const& new_peer_address, u16 new_peer_port)
|
||||
{
|
||||
auto tuple = IPv4SocketTuple(new_local_address, new_local_port, new_peer_address, new_peer_port);
|
||||
return sockets_by_tuple().with_exclusive([&](auto& table) -> ErrorOr<NonnullLockRefPtr<TCPSocket>> {
|
||||
return sockets_by_tuple().with_exclusive([&](auto& table) -> ErrorOr<NonnullRefPtr<TCPSocket>> {
|
||||
if (table.contains(tuple))
|
||||
return EEXIST;
|
||||
|
||||
@ -154,7 +154,7 @@ void TCPSocket::release_to_originator()
|
||||
m_originator.clear();
|
||||
}
|
||||
|
||||
void TCPSocket::release_for_accept(NonnullLockRefPtr<TCPSocket> socket)
|
||||
void TCPSocket::release_for_accept(NonnullRefPtr<TCPSocket> socket)
|
||||
{
|
||||
VERIFY(m_pending_release_for_accept.contains(socket->tuple()));
|
||||
m_pending_release_for_accept.remove(socket->tuple());
|
||||
@ -175,11 +175,11 @@ TCPSocket::~TCPSocket()
|
||||
dbgln_if(TCP_SOCKET_DEBUG, "~TCPSocket in state {}", to_string(state()));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<TCPSocket>> TCPSocket::try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
|
||||
ErrorOr<NonnullRefPtr<TCPSocket>> TCPSocket::try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
|
||||
{
|
||||
// Note: Scratch buffer is only used for SOCK_STREAM sockets.
|
||||
auto scratch_buffer = TRY(KBuffer::try_create_with_size("TCPSocket: Scratch buffer"sv, 65536));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) TCPSocket(protocol, move(receive_buffer), move(scratch_buffer)));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) TCPSocket(protocol, move(receive_buffer), move(scratch_buffer)));
|
||||
}
|
||||
|
||||
ErrorOr<size_t> TCPSocket::protocol_size(ReadonlyBytes raw_ipv4_packet)
|
||||
|
@ -20,7 +20,7 @@ class TCPSocket final : public IPv4Socket {
|
||||
public:
|
||||
static void for_each(Function<void(TCPSocket const&)>);
|
||||
static ErrorOr<void> try_for_each(Function<ErrorOr<void>(TCPSocket const&)>);
|
||||
static ErrorOr<NonnullLockRefPtr<TCPSocket>> try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer);
|
||||
static ErrorOr<NonnullRefPtr<TCPSocket>> try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer);
|
||||
virtual ~TCPSocket() override;
|
||||
|
||||
virtual bool unref() const override;
|
||||
@ -146,15 +146,15 @@ public:
|
||||
bool should_delay_next_ack() const;
|
||||
|
||||
static MutexProtected<HashMap<IPv4SocketTuple, TCPSocket*>>& sockets_by_tuple();
|
||||
static LockRefPtr<TCPSocket> from_tuple(IPv4SocketTuple const& tuple);
|
||||
static RefPtr<TCPSocket> from_tuple(IPv4SocketTuple const& tuple);
|
||||
|
||||
static MutexProtected<HashMap<IPv4SocketTuple, LockRefPtr<TCPSocket>>>& closing_sockets();
|
||||
static MutexProtected<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& closing_sockets();
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<TCPSocket>> try_create_client(IPv4Address const& local_address, u16 local_port, IPv4Address const& peer_address, u16 peer_port);
|
||||
ErrorOr<NonnullRefPtr<TCPSocket>> try_create_client(IPv4Address const& local_address, u16 local_port, IPv4Address const& peer_address, u16 peer_port);
|
||||
void set_originator(TCPSocket& originator) { m_originator = originator; }
|
||||
bool has_originator() { return !!m_originator; }
|
||||
void release_to_originator();
|
||||
void release_for_accept(NonnullLockRefPtr<TCPSocket>);
|
||||
void release_for_accept(NonnullRefPtr<TCPSocket>);
|
||||
|
||||
void retransmit_packets();
|
||||
|
||||
@ -186,7 +186,7 @@ private:
|
||||
void dequeue_for_retransmit();
|
||||
|
||||
LockWeakPtr<TCPSocket> m_originator;
|
||||
HashMap<IPv4SocketTuple, NonnullLockRefPtr<TCPSocket>> m_pending_release_for_accept;
|
||||
HashMap<IPv4SocketTuple, NonnullRefPtr<TCPSocket>> m_pending_release_for_accept;
|
||||
Direction m_direction { Direction::Unspecified };
|
||||
Error m_error { Error::None };
|
||||
LockRefPtr<NetworkAdapter> m_adapter;
|
||||
|
@ -38,9 +38,9 @@ MutexProtected<HashMap<u16, UDPSocket*>>& UDPSocket::sockets_by_port()
|
||||
return *s_map;
|
||||
}
|
||||
|
||||
LockRefPtr<UDPSocket> UDPSocket::from_port(u16 port)
|
||||
RefPtr<UDPSocket> UDPSocket::from_port(u16 port)
|
||||
{
|
||||
return sockets_by_port().with_shared([&](auto const& table) -> LockRefPtr<UDPSocket> {
|
||||
return sockets_by_port().with_shared([&](auto const& table) -> RefPtr<UDPSocket> {
|
||||
auto it = table.find(port);
|
||||
if (it == table.end())
|
||||
return {};
|
||||
@ -60,9 +60,9 @@ UDPSocket::~UDPSocket()
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<UDPSocket>> UDPSocket::try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
|
||||
ErrorOr<NonnullRefPtr<UDPSocket>> UDPSocket::try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
|
||||
{
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) UDPSocket(protocol, move(receive_buffer)));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) UDPSocket(protocol, move(receive_buffer)));
|
||||
}
|
||||
|
||||
ErrorOr<size_t> UDPSocket::protocol_size(ReadonlyBytes raw_ipv4_packet)
|
||||
|
@ -14,10 +14,10 @@ namespace Kernel {
|
||||
|
||||
class UDPSocket final : public IPv4Socket {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<UDPSocket>> try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer);
|
||||
static ErrorOr<NonnullRefPtr<UDPSocket>> try_create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer);
|
||||
virtual ~UDPSocket() override;
|
||||
|
||||
static LockRefPtr<UDPSocket> from_port(u16);
|
||||
static RefPtr<UDPSocket> from_port(u16);
|
||||
static void for_each(Function<void(UDPSocket const&)>);
|
||||
static ErrorOr<void> try_for_each(Function<ErrorOr<void>(UDPSocket const&)>);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user