1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00
serenity/Servers/AudioServer/ASEventLoop.cpp
Robin Burchell 9c8dd836fc Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic
("Connection") term without clashing, which is way easier to understand
than to try to come up with unique names for both.
2019-07-17 20:16:44 +02:00

37 lines
1.1 KiB
C++

#include "ASEventLoop.h"
#include "ASClientConnection.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
ASEventLoop::ASEventLoop()
{
unlink("/tmp/asportal");
sockaddr_un address;
address.sun_family = AF_LOCAL;
strcpy(address.sun_path, "/tmp/asportal");
int rc = bind(m_server_sock.fd(), (const sockaddr*)&address, sizeof(address));
ASSERT(rc == 0);
rc = listen(m_server_sock.fd(), 5);
ASSERT(rc == 0);
m_server_notifier = make<CNotifier>(m_server_sock.fd(), CNotifier::Read);
m_server_notifier->on_ready_to_read = [this] { drain_server(); };
}
void ASEventLoop::drain_server()
{
sockaddr_un address;
socklen_t address_size = sizeof(address);
int client_fd = accept(m_server_sock.fd(), (sockaddr*)&address, &address_size);
if (client_fd < 0) {
dbgprintf("AudioServer: accept() failed: %s\n", strerror(errno));
} else {
dbgprintf("AudioServer: accept()ed client %d\n", client_fd);
static int s_next_client_id = 0;
IPC::Server::new_connection_for_client<ASClientConnection>(client_fd, s_next_client_id++, m_mixer);
}
}