diff options
Diffstat (limited to 'Servers/AudioServer/ASEventLoop.cpp')
-rw-r--r-- | Servers/AudioServer/ASEventLoop.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Servers/AudioServer/ASEventLoop.cpp b/Servers/AudioServer/ASEventLoop.cpp new file mode 100644 index 0000000000..d68916efd6 --- /dev/null +++ b/Servers/AudioServer/ASEventLoop.cpp @@ -0,0 +1,37 @@ +#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; + new ASClientConnection(client_fd, s_next_client_id++, m_mixer); + } +} + |