diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index bbb3601ebbe..5943df73318 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -135,7 +135,7 @@ KResult IPv4Socket::bind(Userspace user_address, socklen_t addr KResult IPv4Socket::listen(size_t backlog) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); auto result = allocate_local_port_if_needed(); if (result.error_or_port.is_error() && result.error_or_port.error() != ENOPROTOOPT) return result.error_or_port.error(); @@ -190,7 +190,7 @@ bool IPv4Socket::can_write(const FileDescription&, size_t) const PortAllocationResult IPv4Socket::allocate_local_port_if_needed() { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (m_local_port) return { m_local_port, false }; auto port_or_error = protocol_allocate_local_port(); @@ -202,7 +202,7 @@ PortAllocationResult IPv4Socket::allocate_local_port_if_needed() KResultOr IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& data, size_t data_length, [[maybe_unused]] int flags, Userspace addr, socklen_t addr_length) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (addr && addr_length != sizeof(sockaddr_in)) return set_so_error(EINVAL); @@ -261,7 +261,7 @@ KResultOr IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& KResultOr IPv4Socket::receive_byte_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace, Userspace) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (m_receive_buffer->is_empty()) { if (protocol_is_disconnected()) return 0; @@ -297,7 +297,7 @@ KResultOr IPv4Socket::receive_byte_buffered(FileDescription& description KResultOr IPv4Socket::receive_packet_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace addr, Userspace addr_length, Time& packet_timestamp) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); ReceivedPacket packet; { if (m_receive_queue.is_empty()) { @@ -412,7 +412,7 @@ KResultOr IPv4Socket::recvfrom(FileDescription& description, UserOrKerne bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, ReadonlyBytes packet, const Time& packet_timestamp) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (is_shut_down_for_reading()) return false; diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 620bb0027d2..5e222c33d79 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -238,7 +238,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace& LocalSocket::sendfd_queue_for(const FileDe KResult LocalSocket::sendfd(const FileDescription& socket_description, FileDescription& passing_description) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); auto role = this->role(socket_description); if (role != Role::Connected && role != Role::Accepted) return set_so_error(EINVAL); @@ -520,7 +520,7 @@ KResult LocalSocket::sendfd(const FileDescription& socket_description, FileDescr KResultOr> LocalSocket::recvfd(const FileDescription& socket_description) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); auto role = this->role(socket_description); if (role != Role::Connected && role != Role::Accepted) return set_so_error(EINVAL); diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index d38d9e9ff03..3ffa72526a0 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -298,7 +298,7 @@ void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) void send_delayed_tcp_ack(RefPtr socket) { - VERIFY(socket->lock().is_locked()); + VERIFY(socket->mutex().is_locked()); if (!socket->should_delay_next_ack()) { [[maybe_unused]] auto result = socket->send_ack(); return; @@ -311,7 +311,7 @@ void flush_delayed_tcp_acks() { Vector, 32> remaining_sockets; for (auto& socket : *delayed_ack_sockets) { - MutexLocker locker(socket->lock()); + MutexLocker locker(socket->mutex()); if (socket->should_delay_next_ack()) { remaining_sockets.append(socket); continue; @@ -418,7 +418,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) return; } - MutexLocker locker(socket->lock()); + MutexLocker locker(socket->mutex()); VERIFY(socket->type() == SOCK_STREAM); VERIFY(socket->local_port() == tcp_packet.destination_port()); @@ -448,7 +448,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) dmesgln("handle_tcp: couldn't create client socket"); return; } - MutexLocker locker(client->lock()); + MutexLocker locker(client->mutex()); dbgln_if(TCP_DEBUG, "handle_tcp: created new client socket with tuple {}", client->tuple().to_string()); client->set_sequence_number(1000); client->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); @@ -648,7 +648,7 @@ void retransmit_tcp_packets() }); for (auto& socket : sockets) { - MutexLocker socket_locker(socket.lock()); + MutexLocker socket_locker(socket.mutex()); socket.retransmit_packets(); } } diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 1d6260951d8..1bad59ab6c4 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -54,7 +54,7 @@ void Socket::set_setup_state(SetupState new_setup_state) RefPtr Socket::accept() { - MutexLocker locker(m_lock); + MutexLocker locker(mutex()); if (m_pending.is_empty()) return nullptr; dbgln_if(SOCKET_DEBUG, "Socket({}) de-queueing connection", this); @@ -72,7 +72,7 @@ RefPtr Socket::accept() KResult Socket::queue_connection_from(NonnullRefPtr peer) { dbgln_if(SOCKET_DEBUG, "Socket({}) queueing connection", this); - MutexLocker locker(m_lock); + MutexLocker locker(mutex()); if (m_pending.size() >= m_backlog) return set_so_error(ECONNREFUSED); if (!m_pending.try_append(peer)) @@ -243,7 +243,7 @@ KResultOr Socket::write(FileDescription& description, u64, const UserOrK KResult Socket::shutdown(int how) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (type() == SOCK_STREAM && !is_connected()) return set_so_error(ENOTCONN); if (m_role == Role::Listener) @@ -266,7 +266,7 @@ KResult Socket::stat(::stat& st) const void Socket::set_connected(bool connected) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); if (m_connected == connected) return; m_connected = connected; diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index 77e2d92352d..08c4ab2d1b1 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -99,7 +99,7 @@ public: GroupID acceptor_gid() const { return m_acceptor.gid; } const RefPtr bound_interface() const { return m_bound_interface; } - Mutex& lock() { return m_lock; } + Mutex& mutex() { return m_mutex; } // ^File virtual KResultOr read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override final; @@ -149,7 +149,7 @@ protected: private: virtual bool is_socket() const final { return true; } - Mutex m_lock { "Socket" }; + Mutex m_mutex { "Socket"sv }; int m_domain { 0 }; int m_type { 0 }; @@ -180,7 +180,7 @@ public: : m_socket(move(socket)) { if (m_socket) - m_socket->lock().lock(); + m_socket->mutex().lock(); } SocketHandle(SocketHandle&& other) @@ -191,7 +191,7 @@ public: ~SocketHandle() { if (m_socket) - m_socket->lock().unlock(); + m_socket->mutex().unlock(); } SocketHandle(const SocketHandle&) = delete; diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index be995302e0a..43c9ab1507c 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -398,7 +398,7 @@ KResult TCPSocket::protocol_listen(bool did_allocate_port) KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block) { - MutexLocker locker(lock()); + MutexLocker locker(mutex()); auto routing_decision = route_to(peer_address(), local_address()); if (routing_decision.is_zero()) @@ -497,7 +497,7 @@ void TCPSocket::shut_down_for_writing() KResult TCPSocket::close() { - MutexLocker socket_locker(lock()); + MutexLocker locker(mutex()); auto result = IPv4Socket::close(); if (state() == State::CloseWait) { dbgln_if(TCP_SOCKET_DEBUG, " Sending FIN from CloseWait and moving into LastAck");