mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
IPv4: Do the TCP-to-socket mapping in the same way as UDP.
We don't actually have TCP support yet, but we'll get there soon. :^)
This commit is contained in:
parent
3ad9561b80
commit
ef5d0a397c
1 changed files with 21 additions and 4 deletions
|
@ -58,6 +58,10 @@ IPv4Socket::~IPv4Socket()
|
|||
LOCKER(sockets_by_udp_port().lock());
|
||||
sockets_by_udp_port().resource().remove(m_source_port);
|
||||
}
|
||||
if (type() == SOCK_STREAM) {
|
||||
LOCKER(sockets_by_tcp_port().lock());
|
||||
sockets_by_tcp_port().resource().remove(m_source_port);
|
||||
}
|
||||
}
|
||||
|
||||
bool IPv4Socket::get_address(sockaddr* address, socklen_t* address_size)
|
||||
|
@ -107,17 +111,17 @@ bool IPv4Socket::can_read(SocketRole) const
|
|||
return m_can_read;
|
||||
}
|
||||
|
||||
ssize_t IPv4Socket::read(SocketRole role, byte* buffer, ssize_t size)
|
||||
ssize_t IPv4Socket::read(SocketRole, byte*, ssize_t)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
ssize_t IPv4Socket::write(SocketRole role, const byte* data, ssize_t size)
|
||||
ssize_t IPv4Socket::write(SocketRole, const byte*, ssize_t)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool IPv4Socket::can_write(SocketRole role) const
|
||||
bool IPv4Socket::can_write(SocketRole) const
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -140,6 +144,20 @@ void IPv4Socket::allocate_source_port_if_needed()
|
|||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
if (type() == SOCK_STREAM) {
|
||||
// This is not a very efficient allocation algorithm.
|
||||
// FIXME: Replace it with a bitmap or some other fast-paced looker-upper.
|
||||
LOCKER(sockets_by_tcp_port().lock());
|
||||
for (word port = 2000; port < 60000; ++port) {
|
||||
auto it = sockets_by_tcp_port().resource().find(port);
|
||||
if (it == sockets_by_tcp_port().resource().end()) {
|
||||
m_source_port = port;
|
||||
sockets_by_tcp_port().resource().set(port, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t IPv4Socket::sendto(const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
||||
|
@ -201,7 +219,6 @@ ssize_t IPv4Socket::recvfrom(void* buffer, size_t buffer_length, int flags, sock
|
|||
if (*addr_length < sizeof(sockaddr_in))
|
||||
return -EINVAL;
|
||||
|
||||
auto peer_address = IPv4Address((const byte*)&((const sockaddr_in*)addr)->sin_addr.s_addr);
|
||||
#ifdef IPV4_SOCKET_DEBUG
|
||||
kprintf("recvfrom: type=%d, source_port=%u\n", type(), source_port());
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue