diff options
Diffstat (limited to 'Libraries/LibCore/CSocket.cpp')
-rw-r--r-- | Libraries/LibCore/CSocket.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Libraries/LibCore/CSocket.cpp b/Libraries/LibCore/CSocket.cpp index 4479969c40..cbe2bd9dd4 100644 --- a/Libraries/LibCore/CSocket.cpp +++ b/Libraries/LibCore/CSocket.cpp @@ -35,6 +35,8 @@ 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()); + ASSERT(port > 0 && port <= 65535); struct sockaddr_in addr; @@ -47,7 +49,6 @@ bool CSocket::connect(const CSocketAddress& address, int port) m_destination_address = address; m_destination_port = port; - dbgprintf("Connecting to %s...", address.to_string().characters()); fflush(stdout); int rc = ::connect(fd(), (struct sockaddr*)&addr, sizeof(addr)); if (rc < 0) { @@ -71,6 +72,26 @@ bool CSocket::connect(const CSocketAddress& address, int port) return true; } +bool CSocket::connect(const CSocketAddress& address) +{ + ASSERT(!is_connected()); + ASSERT(address.type() == CSocketAddress::Type::Local); + dbgprintf("Connecting to %s...", address.to_string().characters()); + + sockaddr_un saddr; + saddr.sun_family = AF_LOCAL; + strcpy(saddr.sun_path, address.to_string().characters()); + + int rc = ::connect(fd(), (const sockaddr*)&saddr, sizeof(saddr)); + if (rc < 0) { + perror("connect"); + return false; + } + + m_connected = true; + return true; +} + ByteBuffer CSocket::receive(int max_size) { auto buffer = read(max_size); |