mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Kernel: Add Socket::set_role() and use it everywhere
Instead of having Socket subclasses write their role into Socket::m_role directly, add a setter to do this.
This commit is contained in:
parent
70b2225b3d
commit
a28cd921a1
|
@ -141,7 +141,7 @@ KResult IPv4Socket::listen(size_t backlog)
|
|||
return result.error_or_port.error();
|
||||
|
||||
set_backlog(backlog);
|
||||
m_role = Role::Listener;
|
||||
set_role(Role::Listener);
|
||||
evaluate_block_conditions();
|
||||
|
||||
dbgln_if(IPV4_SOCKET_DEBUG, "IPv4Socket({}) listening with backlog={}", this, backlog);
|
||||
|
|
|
@ -66,7 +66,7 @@ KResultOr<SocketPair> LocalSocket::try_create_connected_pair(int type)
|
|||
socket->set_acceptor(Process::current());
|
||||
socket->set_connected(true);
|
||||
socket->set_connect_side_role(Role::Connected);
|
||||
socket->m_role = Role::Accepted;
|
||||
socket->set_role(Role::Accepted);
|
||||
|
||||
auto description2_result = FileDescription::try_create(*socket);
|
||||
if (description2_result.is_error())
|
||||
|
@ -243,7 +243,7 @@ KResult LocalSocket::listen(size_t backlog)
|
|||
return set_so_error(EOPNOTSUPP);
|
||||
set_backlog(backlog);
|
||||
auto previous_role = m_role;
|
||||
m_role = Role::Listener;
|
||||
set_role(Role::Listener);
|
||||
set_connect_side_role(Role::Listener, previous_role != m_role);
|
||||
|
||||
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) listening with backlog={}", this, backlog);
|
||||
|
|
|
@ -63,7 +63,7 @@ RefPtr<Socket> Socket::accept()
|
|||
auto& process = Process::current();
|
||||
client->set_acceptor(process);
|
||||
client->m_connected = true;
|
||||
client->m_role = Role::Accepted;
|
||||
client->set_role(Role::Accepted);
|
||||
if (!m_pending.is_empty())
|
||||
evaluate_block_conditions();
|
||||
return client;
|
||||
|
|
|
@ -140,6 +140,8 @@ protected:
|
|||
void set_origin(Process const&);
|
||||
void set_acceptor(Process const&);
|
||||
|
||||
void set_role(Role role) { m_role = role; }
|
||||
|
||||
protected:
|
||||
ucred m_origin { 0, 0, 0 };
|
||||
ucred m_acceptor { 0, 0, 0 };
|
||||
|
|
|
@ -39,7 +39,7 @@ void TCPSocket::set_state(State new_state)
|
|||
m_state = new_state;
|
||||
|
||||
if (new_state == State::Established && m_direction == Direction::Outgoing) {
|
||||
m_role = Role::Connected;
|
||||
set_role(Role::Connected);
|
||||
[[maybe_unused]] auto rc = set_so_error(KSuccess);
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
|||
if (auto result = send_tcp_packet(TCPFlags::SYN); result.is_error())
|
||||
return result;
|
||||
m_state = State::SynSent;
|
||||
m_role = Role::Connecting;
|
||||
set_role(Role::Connecting);
|
||||
m_direction = Direction::Outgoing;
|
||||
|
||||
evaluate_block_conditions();
|
||||
|
@ -429,7 +429,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
|||
locker.lock();
|
||||
VERIFY(setup_state() == SetupState::Completed);
|
||||
if (has_error()) { // TODO: check unblock_flags
|
||||
m_role = Role::None;
|
||||
set_role(Role::None);
|
||||
if (error() == TCPSocket::Error::RetransmitTimeout)
|
||||
return set_so_error(ETIMEDOUT);
|
||||
else
|
||||
|
|
|
@ -100,7 +100,7 @@ KResultOr<size_t> UDPSocket::protocol_send(const UserOrKernelBuffer& data, size_
|
|||
|
||||
KResult UDPSocket::protocol_connect(FileDescription&, ShouldBlock)
|
||||
{
|
||||
m_role = Role::Connected;
|
||||
set_role(Role::Connected);
|
||||
set_connected(true);
|
||||
return KSuccess;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue