1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 22:58:12 +00:00

LibCore: Port CSocket over to using dbg().

Also added a LogStream operator<< for CSocketAddress.
This commit is contained in:
Andreas Kling 2019-07-14 11:02:40 +02:00
parent b4329a8eec
commit c9ee481cdf
2 changed files with 13 additions and 8 deletions

View file

@ -22,12 +22,12 @@ bool CSocket::connect(const String& hostname, int port)
{ {
auto* hostent = gethostbyname(hostname.characters()); auto* hostent = gethostbyname(hostname.characters());
if (!hostent) { if (!hostent) {
dbgprintf("CSocket::connect: Unable to resolve '%s'\n", hostname.characters()); dbg() << "CSocket::connect: Unable to resolve '" << hostname << "'";
return false; return false;
} }
IPv4Address host_address((const u8*)hostent->h_addr_list[0]); IPv4Address host_address((const u8*)hostent->h_addr_list[0]);
dbgprintf("CSocket::connect: Resolved '%s' to %s\n", hostname.characters(), host_address.to_string().characters()); dbg() << "CSocket::connect: Resolved '" << hostname << "' to " << host_address;
return connect(host_address, port); return connect(host_address, port);
} }
@ -35,7 +35,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
{ {
ASSERT(!is_connected()); ASSERT(!is_connected());
ASSERT(address.type() == CSocketAddress::Type::IPv4); ASSERT(address.type() == CSocketAddress::Type::IPv4);
dbgprintf("Connecting to %s...", address.to_string().characters()); dbg() << *this << " connecting to " << address << "...";
ASSERT(port > 0 && port <= 65535); ASSERT(port > 0 && port <= 65535);
@ -53,10 +53,10 @@ bool CSocket::connect(const CSocketAddress& address, int port)
int rc = ::connect(fd(), (struct sockaddr*)&addr, sizeof(addr)); int rc = ::connect(fd(), (struct sockaddr*)&addr, sizeof(addr));
if (rc < 0) { if (rc < 0) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
dbgprintf("in progress.\n"); dbg() << *this << " connection in progress (EINPROGRESS)";
m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write); m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write);
m_notifier->on_ready_to_write = [this] { m_notifier->on_ready_to_write = [this] {
dbgprintf("%s{%p} connected!\n", class_name(), this); dbg() << *this << " connected!";
m_connected = true; m_connected = true;
m_notifier->set_event_mask(CNotifier::Event::None); m_notifier->set_event_mask(CNotifier::Event::None);
if (on_connected) if (on_connected)
@ -67,7 +67,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
perror("connect"); perror("connect");
exit(1); exit(1);
} }
dbgprintf("ok!\n"); dbg() << *this << " connected ok!";
m_connected = true; m_connected = true;
return true; return true;
} }
@ -76,7 +76,7 @@ bool CSocket::connect(const CSocketAddress& address)
{ {
ASSERT(!is_connected()); ASSERT(!is_connected());
ASSERT(address.type() == CSocketAddress::Type::Local); ASSERT(address.type() == CSocketAddress::Type::Local);
dbgprintf("Connecting to %s...", address.to_string().characters()); dbg() << *this << " connecting to " << address << "...";
sockaddr_un saddr; sockaddr_un saddr;
saddr.sun_family = AF_LOCAL; saddr.sun_family = AF_LOCAL;
@ -96,7 +96,7 @@ ByteBuffer CSocket::receive(int max_size)
{ {
auto buffer = read(max_size); auto buffer = read(max_size);
if (eof()) { if (eof()) {
dbgprintf("CSocket{%p}: Connection appears to have closed in receive().\n", this); dbg() << *this << " connection appears to have closed in receive().";
m_connected = false; m_connected = false;
} }
return buffer; return buffer;

View file

@ -46,3 +46,8 @@ private:
IPv4Address m_ipv4_address; IPv4Address m_ipv4_address;
String m_local_address; String m_local_address;
}; };
inline const LogStream& operator<<(const LogStream& stream, const CSocketAddress& value)
{
return stream << value;
}