summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CSocket.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-07-13 19:42:03 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-13 22:57:24 +0200
commitffa8cb668faffd4c417cc7ff60215d732a088122 (patch)
treeb2b562056ba6bec73b7999335c2e9d9484cb4b2f /Libraries/LibCore/CSocket.cpp
parent983245113afe1961376f5381ea4a77e4364b9d2d (diff)
downloadserenity-ffa8cb668faffd4c417cc7ff60215d732a088122.zip
AudioServer: Assorted infrastructure work
* Add a LibAudio, and move WAV file parsing there (via AWavFile and AWavLoader) * Add CLocalSocket, and CSocket::connect() variant for local address types. We make some small use of this in WindowServer (as that's where we modelled it from), but don't get too invasive as this PR is already quite large, and the WS I/O is a bit carefully done * Add an AClientConnection which will eventually be used to talk to AudioServer (and make use of it in Piano, though right now it really doesn't do anything except connect, using our new CLocalSocket...)
Diffstat (limited to 'Libraries/LibCore/CSocket.cpp')
-rw-r--r--Libraries/LibCore/CSocket.cpp23
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);