mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Port CSocket over to using dbg().
Also added a LogStream operator<< for CSocketAddress.
This commit is contained in:
parent
b4329a8eec
commit
c9ee481cdf
Notes:
sideshowbarker
2024-07-19 13:16:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c9ee481cdf8
2 changed files with 13 additions and 8 deletions
|
@ -22,12 +22,12 @@ bool CSocket::connect(const String& hostname, int port)
|
|||
{
|
||||
auto* hostent = gethostbyname(hostname.characters());
|
||||
if (!hostent) {
|
||||
dbgprintf("CSocket::connect: Unable to resolve '%s'\n", hostname.characters());
|
||||
dbg() << "CSocket::connect: Unable to resolve '" << hostname << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
|
|||
{
|
||||
ASSERT(!is_connected());
|
||||
ASSERT(address.type() == CSocketAddress::Type::IPv4);
|
||||
dbgprintf("Connecting to %s...", address.to_string().characters());
|
||||
dbg() << *this << " connecting to " << address << "...";
|
||||
|
||||
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));
|
||||
if (rc < 0) {
|
||||
if (errno == EINPROGRESS) {
|
||||
dbgprintf("in progress.\n");
|
||||
dbg() << *this << " connection in progress (EINPROGRESS)";
|
||||
m_notifier = make<CNotifier>(fd(), CNotifier::Event::Write);
|
||||
m_notifier->on_ready_to_write = [this] {
|
||||
dbgprintf("%s{%p} connected!\n", class_name(), this);
|
||||
dbg() << *this << " connected!";
|
||||
m_connected = true;
|
||||
m_notifier->set_event_mask(CNotifier::Event::None);
|
||||
if (on_connected)
|
||||
|
@ -67,7 +67,7 @@ bool CSocket::connect(const CSocketAddress& address, int port)
|
|||
perror("connect");
|
||||
exit(1);
|
||||
}
|
||||
dbgprintf("ok!\n");
|
||||
dbg() << *this << " connected ok!";
|
||||
m_connected = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ bool CSocket::connect(const CSocketAddress& address)
|
|||
{
|
||||
ASSERT(!is_connected());
|
||||
ASSERT(address.type() == CSocketAddress::Type::Local);
|
||||
dbgprintf("Connecting to %s...", address.to_string().characters());
|
||||
dbg() << *this << " connecting to " << address << "...";
|
||||
|
||||
sockaddr_un saddr;
|
||||
saddr.sun_family = AF_LOCAL;
|
||||
|
@ -96,7 +96,7 @@ ByteBuffer CSocket::receive(int max_size)
|
|||
{
|
||||
auto buffer = read(max_size);
|
||||
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;
|
||||
}
|
||||
return buffer;
|
||||
|
|
|
@ -46,3 +46,8 @@ private:
|
|||
IPv4Address m_ipv4_address;
|
||||
String m_local_address;
|
||||
};
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const CSocketAddress& value)
|
||||
{
|
||||
return stream << value;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue