1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:55:08 +00:00

Everywhere: Replace a bundle of dbg with dbgln.

These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
This commit is contained in:
asynts 2021-01-14 00:21:21 +01:00 committed by Andreas Kling
parent 67583bc424
commit dd727d1fec
4 changed files with 63 additions and 55 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <AK/Singleton.h>
#include <AK/StringBuilder.h>
#include <Kernel/FileSystem/FileDescription.h>
@ -67,9 +68,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
IPv4Socket::IPv4Socket(int type, int protocol)
: Socket(AF_INET, type, protocol)
{
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket{" << this << "} created with type=" << type << ", protocol=" << protocol;
#endif
dbgln<debug_ipv4_socket>("IPv4Socket({}) created with type={}, protocol={}", this, type, protocol);
m_buffer_mode = type == SOCK_STREAM ? BufferMode::Bytes : BufferMode::Packets;
if (m_buffer_mode == BufferMode::Bytes) {
m_scratch_buffer = KBuffer::create_with_size(65536);
@ -122,9 +121,7 @@ KResult IPv4Socket::bind(Userspace<const sockaddr*> user_address, socklen_t addr
m_local_address = IPv4Address((const u8*)&address.sin_addr.s_addr);
m_local_port = requested_local_port;
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket::bind " << class_name() << "{" << this << "} to " << m_local_address << ":" << m_local_port;
#endif
dbgln<debug_ipv4_socket>("IPv4Socket::bind {}({}) to {}:{}", class_name(), this, m_local_address, m_local_port);
return protocol_bind();
}
@ -140,9 +137,7 @@ KResult IPv4Socket::listen(size_t backlog)
m_role = Role::Listener;
evaluate_block_conditions();
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket{" << this << "} listening with backlog=" << backlog;
#endif
dbgln<debug_ipv4_socket>("IPv4Socket({}) listening with backlog={}", this, backlog);
return protocol_listen();
}
@ -293,9 +288,11 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
if (!m_receive_queue.is_empty()) {
packet = m_receive_queue.take_first();
set_can_read(!m_receive_queue.is_empty());
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom without blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size();
#endif
dbgln<debug_ipv4_socket>("IPv4Socket({}): recvfrom without blocking {} bytes, packets in queue: {}",
this,
packet.data.value().size(),
m_receive_queue.size());
}
}
if (!packet.data.has_value()) {
@ -320,18 +317,18 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
ASSERT(!m_receive_queue.is_empty());
packet = m_receive_queue.take_first();
set_can_read(!m_receive_queue.is_empty());
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom with blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size();
#endif
dbgln<debug_ipv4_socket>("IPv4Socket({}): recvfrom with blocking {} bytes, packets in queue: {}",
this,
packet.data.value().size(),
m_receive_queue.size());
}
ASSERT(packet.data.has_value());
packet_timestamp = packet.timestamp;
if (addr) {
#ifdef IPV4_SOCKET_DEBUG
dbg() << "Incoming packet is from: " << packet.peer_address << ":" << packet.peer_port;
#endif
dbgln<debug_ipv4_socket>("Incoming packet is from: {}:{}", packet.peer_address, packet.peer_port);
sockaddr_in out_addr {};
memcpy(&out_addr.sin_addr, &packet.peer_address, sizeof(IPv4Address));
@ -415,12 +412,18 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
set_can_read(true);
}
m_bytes_received += packet_size;
#ifdef IPV4_SOCKET_DEBUG
if (buffer_mode() == BufferMode::Bytes)
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received;
else
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received << ", packets in queue: " << m_receive_queue.size();
#endif
if constexpr (debug_ipv4_socket) {
if (buffer_mode() == BufferMode::Bytes)
dbgln("IPv4Socket({}): did_receive {} bytes, total_received={}", this, packet_size, m_bytes_received);
else
dbgln("IPv4Socket({}): did_receive {} bytes, total_received={}, packets in queue: {}",
this,
packet_size,
m_bytes_received,
m_receive_queue.size());
}
return true;
}