mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
Kernel: Move socket role tracking to the Socket class itself
This is more logical and allows us to solve the problem of non-blocking TCP sockets getting stuck in SocketRole::None. The only complication is that a single LocalSocket may be shared between two file descriptions (on the connect and accept sides), and should have two different roles depending from which side you look at it. To deal with it, Socket::role() is made a virtual method that accepts a file description, and LocalSocket internally tracks which FileDescription is the which one and returns a correct role.
This commit is contained in:
parent
d46c3b0b5b
commit
43ce6c5474
11 changed files with 103 additions and 95 deletions
|
@ -108,6 +108,8 @@ KResult IPv4Socket::connect(FileDescription& description, const sockaddr* addres
|
|||
return KResult(-EINVAL);
|
||||
if (address->sa_family != AF_INET)
|
||||
return KResult(-EINVAL);
|
||||
if (m_role == Role::Connected)
|
||||
return KResult(-EISCONN);
|
||||
|
||||
auto& ia = *(const sockaddr_in*)address;
|
||||
m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr);
|
||||
|
@ -124,9 +126,9 @@ void IPv4Socket::detach(FileDescription&)
|
|||
{
|
||||
}
|
||||
|
||||
bool IPv4Socket::can_read(FileDescription& description) const
|
||||
bool IPv4Socket::can_read(FileDescription&) const
|
||||
{
|
||||
if (description.socket_role() == SocketRole::Listener)
|
||||
if (m_role == Role::Listener)
|
||||
return can_accept();
|
||||
if (protocol_is_disconnected())
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue