mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +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
6 changed files with 10 additions and 8 deletions
|
@ -141,7 +141,7 @@ KResult IPv4Socket::listen(size_t backlog)
|
||||||
return result.error_or_port.error();
|
return result.error_or_port.error();
|
||||||
|
|
||||||
set_backlog(backlog);
|
set_backlog(backlog);
|
||||||
m_role = Role::Listener;
|
set_role(Role::Listener);
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
|
|
||||||
dbgln_if(IPV4_SOCKET_DEBUG, "IPv4Socket({}) listening with backlog={}", this, backlog);
|
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_acceptor(Process::current());
|
||||||
socket->set_connected(true);
|
socket->set_connected(true);
|
||||||
socket->set_connect_side_role(Role::Connected);
|
socket->set_connect_side_role(Role::Connected);
|
||||||
socket->m_role = Role::Accepted;
|
socket->set_role(Role::Accepted);
|
||||||
|
|
||||||
auto description2_result = FileDescription::try_create(*socket);
|
auto description2_result = FileDescription::try_create(*socket);
|
||||||
if (description2_result.is_error())
|
if (description2_result.is_error())
|
||||||
|
@ -243,7 +243,7 @@ KResult LocalSocket::listen(size_t backlog)
|
||||||
return set_so_error(EOPNOTSUPP);
|
return set_so_error(EOPNOTSUPP);
|
||||||
set_backlog(backlog);
|
set_backlog(backlog);
|
||||||
auto previous_role = m_role;
|
auto previous_role = m_role;
|
||||||
m_role = Role::Listener;
|
set_role(Role::Listener);
|
||||||
set_connect_side_role(Role::Listener, previous_role != m_role);
|
set_connect_side_role(Role::Listener, previous_role != m_role);
|
||||||
|
|
||||||
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) listening with backlog={}", this, backlog);
|
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) listening with backlog={}", this, backlog);
|
||||||
|
|
|
@ -63,7 +63,7 @@ RefPtr<Socket> Socket::accept()
|
||||||
auto& process = Process::current();
|
auto& process = Process::current();
|
||||||
client->set_acceptor(process);
|
client->set_acceptor(process);
|
||||||
client->m_connected = true;
|
client->m_connected = true;
|
||||||
client->m_role = Role::Accepted;
|
client->set_role(Role::Accepted);
|
||||||
if (!m_pending.is_empty())
|
if (!m_pending.is_empty())
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
return client;
|
return client;
|
||||||
|
|
|
@ -140,6 +140,8 @@ protected:
|
||||||
void set_origin(Process const&);
|
void set_origin(Process const&);
|
||||||
void set_acceptor(Process const&);
|
void set_acceptor(Process const&);
|
||||||
|
|
||||||
|
void set_role(Role role) { m_role = role; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ucred m_origin { 0, 0, 0 };
|
ucred m_origin { 0, 0, 0 };
|
||||||
ucred m_acceptor { 0, 0, 0 };
|
ucred m_acceptor { 0, 0, 0 };
|
||||||
|
|
|
@ -39,7 +39,7 @@ void TCPSocket::set_state(State new_state)
|
||||||
m_state = new_state;
|
m_state = new_state;
|
||||||
|
|
||||||
if (new_state == State::Established && m_direction == Direction::Outgoing) {
|
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);
|
[[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())
|
if (auto result = send_tcp_packet(TCPFlags::SYN); result.is_error())
|
||||||
return result;
|
return result;
|
||||||
m_state = State::SynSent;
|
m_state = State::SynSent;
|
||||||
m_role = Role::Connecting;
|
set_role(Role::Connecting);
|
||||||
m_direction = Direction::Outgoing;
|
m_direction = Direction::Outgoing;
|
||||||
|
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
|
@ -429,7 +429,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
||||||
locker.lock();
|
locker.lock();
|
||||||
VERIFY(setup_state() == SetupState::Completed);
|
VERIFY(setup_state() == SetupState::Completed);
|
||||||
if (has_error()) { // TODO: check unblock_flags
|
if (has_error()) { // TODO: check unblock_flags
|
||||||
m_role = Role::None;
|
set_role(Role::None);
|
||||||
if (error() == TCPSocket::Error::RetransmitTimeout)
|
if (error() == TCPSocket::Error::RetransmitTimeout)
|
||||||
return set_so_error(ETIMEDOUT);
|
return set_so_error(ETIMEDOUT);
|
||||||
else
|
else
|
||||||
|
|
|
@ -100,7 +100,7 @@ KResultOr<size_t> UDPSocket::protocol_send(const UserOrKernelBuffer& data, size_
|
||||||
|
|
||||||
KResult UDPSocket::protocol_connect(FileDescription&, ShouldBlock)
|
KResult UDPSocket::protocol_connect(FileDescription&, ShouldBlock)
|
||||||
{
|
{
|
||||||
m_role = Role::Connected;
|
set_role(Role::Connected);
|
||||||
set_connected(true);
|
set_connected(true);
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue