mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 22:07:36 +00:00
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...)
This commit is contained in:
parent
983245113a
commit
ffa8cb668f
22 changed files with 431 additions and 162 deletions
|
@ -6,11 +6,11 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/CLock.h>
|
||||
#include <LibCore/CEvent.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
class CEvent;
|
||||
class CObject;
|
||||
class CNotifier;
|
||||
|
||||
|
|
19
Libraries/LibCore/CLocalSocket.cpp
Normal file
19
Libraries/LibCore/CLocalSocket.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <LibCore/CLocalSocket.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
CLocalSocket::CLocalSocket(CObject* parent)
|
||||
: CSocket(CSocket::Type::Local, parent)
|
||||
{
|
||||
int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
set_error(fd);
|
||||
} else {
|
||||
set_fd(fd);
|
||||
set_mode(CIODevice::ReadWrite);
|
||||
set_error(0);
|
||||
}
|
||||
}
|
||||
|
||||
CLocalSocket::~CLocalSocket()
|
||||
{
|
||||
}
|
7
Libraries/LibCore/CLocalSocket.h
Normal file
7
Libraries/LibCore/CLocalSocket.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <LibCore/CSocket.h>
|
||||
|
||||
class CLocalSocket final : public CSocket {
|
||||
public:
|
||||
explicit CLocalSocket(CObject* parent = nullptr);
|
||||
virtual ~CLocalSocket() override;
|
||||
};
|
|
@ -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);
|
||||
|
|
|
@ -10,12 +10,14 @@ public:
|
|||
enum class Type {
|
||||
Invalid,
|
||||
TCP,
|
||||
UDP
|
||||
UDP,
|
||||
Local,
|
||||
};
|
||||
virtual ~CSocket() override;
|
||||
|
||||
bool connect(const String& hostname, int port);
|
||||
bool connect(const CSocketAddress&, int port);
|
||||
bool connect(const CSocketAddress&);
|
||||
|
||||
ByteBuffer receive(int max_size);
|
||||
bool send(const ByteBuffer&);
|
||||
|
|
|
@ -17,6 +17,14 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
static CSocketAddress local(const String& address)
|
||||
{
|
||||
CSocketAddress addr;
|
||||
addr.m_type = Type::Local;
|
||||
addr.m_local_address = address;
|
||||
return addr;
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
bool is_valid() const { return m_type != Type::Invalid; }
|
||||
IPv4Address ipv4_address() const { return m_ipv4_address; }
|
||||
|
@ -26,6 +34,8 @@ public:
|
|||
switch (m_type) {
|
||||
case Type::IPv4:
|
||||
return m_ipv4_address.to_string();
|
||||
case Type::Local:
|
||||
return m_local_address;
|
||||
default:
|
||||
return "[CSocketAddress]";
|
||||
}
|
||||
|
@ -34,4 +44,5 @@ public:
|
|||
private:
|
||||
Type m_type { Type::Invalid };
|
||||
IPv4Address m_ipv4_address;
|
||||
String m_local_address;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@ OBJS = \
|
|||
CIODevice.o \
|
||||
CFile.o \
|
||||
CSocket.o \
|
||||
CLocalSocket.o \
|
||||
CTCPSocket.o \
|
||||
CElapsedTimer.o \
|
||||
CNotifier.o \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue