mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
Kernel: Make File's can_read/can_write take a const FileDescription&
Asking a File if we could possibly read or write it will never mutate the asking FileDescription&, so it should be const.
This commit is contained in:
parent
e8fee92357
commit
1b2ef8582c
47 changed files with 97 additions and 91 deletions
|
@ -144,7 +144,7 @@ void IPv4Socket::detach(FileDescription&)
|
|||
{
|
||||
}
|
||||
|
||||
bool IPv4Socket::can_read(FileDescription&) const
|
||||
bool IPv4Socket::can_read(const FileDescription&) const
|
||||
{
|
||||
if (m_role == Role::Listener)
|
||||
return can_accept();
|
||||
|
@ -153,7 +153,7 @@ bool IPv4Socket::can_read(FileDescription&) const
|
|||
return m_can_read;
|
||||
}
|
||||
|
||||
bool IPv4Socket::can_write(FileDescription&) const
|
||||
bool IPv4Socket::can_write(const FileDescription&) const
|
||||
{
|
||||
return is_connected();
|
||||
}
|
||||
|
@ -282,9 +282,13 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t
|
|||
return protocol_receive(packet.data.value(), buffer, buffer_length, flags);
|
||||
}
|
||||
|
||||
void IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet)
|
||||
bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet)
|
||||
{
|
||||
LOCKER(lock());
|
||||
if (m_receive_queue.size_slow() > 2000) {
|
||||
kprintf("IPv4Socket(%p): did_receive refusing packet since queue is full.\n", this);
|
||||
return false;
|
||||
}
|
||||
auto packet_size = packet.size();
|
||||
m_receive_queue.append({ source_address, source_port, move(packet) });
|
||||
m_can_read = true;
|
||||
|
@ -292,6 +296,7 @@ void IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
|
|||
#ifdef IPV4_SOCKET_DEBUG
|
||||
kprintf("IPv4Socket(%p): did_receive %d bytes, total_received=%u, packets in queue: %d\n", this, packet_size, m_bytes_received, m_receive_queue.size_slow());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
String IPv4Socket::absolute_path(const FileDescription&) const
|
||||
|
|
|
@ -27,8 +27,8 @@ public:
|
|||
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
||||
virtual void attach(FileDescription&) override;
|
||||
virtual void detach(FileDescription&) override;
|
||||
virtual bool can_read(FileDescription&) const override;
|
||||
virtual bool can_write(FileDescription&) const override;
|
||||
virtual bool can_read(const FileDescription&) const override;
|
||||
virtual bool can_write(const FileDescription&) const override;
|
||||
virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||
virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||
virtual KResult setsockopt(int level, int option, const void*, socklen_t) override;
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
|
||||
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override;
|
||||
|
||||
void did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&);
|
||||
bool did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&);
|
||||
|
||||
const IPv4Address& local_address() const { return m_local_address; }
|
||||
u16 local_port() const { return m_local_port; }
|
||||
|
|
|
@ -186,7 +186,7 @@ void LocalSocket::detach(FileDescription& description)
|
|||
}
|
||||
}
|
||||
|
||||
bool LocalSocket::can_read(FileDescription& description) const
|
||||
bool LocalSocket::can_read(const FileDescription& description) const
|
||||
{
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Listener)
|
||||
|
@ -208,7 +208,7 @@ bool LocalSocket::has_attached_peer(const FileDescription& description) const
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool LocalSocket::can_write(FileDescription& description) const
|
||||
bool LocalSocket::can_write(const FileDescription& description) const
|
||||
{
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Accepted)
|
||||
|
|
|
@ -25,8 +25,8 @@ public:
|
|||
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
||||
virtual void attach(FileDescription&) override;
|
||||
virtual void detach(FileDescription&) override;
|
||||
virtual bool can_read(FileDescription&) const override;
|
||||
virtual bool can_write(FileDescription&) const override;
|
||||
virtual bool can_read(const FileDescription&) const override;
|
||||
virtual bool can_write(const FileDescription&) const override;
|
||||
virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||
virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||
|
||||
|
|
|
@ -574,9 +574,12 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
|
|||
socket->sequence_number());
|
||||
#endif
|
||||
|
||||
socket->send_tcp_packet(TCPFlags::ACK);
|
||||
bool should_ack = true;
|
||||
if (payload_size != 0) {
|
||||
should_ack = socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
|
||||
}
|
||||
|
||||
if (payload_size != 0)
|
||||
socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
|
||||
if (should_ack)
|
||||
socket->send_tcp_packet(TCPFlags::ACK);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue