opuntiaOS - an operating system targeting x86 and ARMv7
at master 43 lines 1.2 kB view raw
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include "Connection.h" 10#include "Event.h" 11#include <libfoundation/EventLoop.h> 12#include <sys/socket.h> 13 14namespace WinServer { 15 16Connection* s_WinServer_Connection_the = nullptr; 17 18Connection::Connection(int connection_fd) 19 : m_connection_fd(connection_fd) 20 , m_server_decoder() 21 , m_client_decoder() 22 , m_connection_with_clients(m_connection_fd, m_server_decoder, m_client_decoder) 23{ 24 s_WinServer_Connection_the = this; 25 int err = bind(m_connection_fd, "/tmp/win.sock", 13); 26 if (!err) { 27 LFoundation::EventLoop::the().add( 28 m_connection_fd, [] { 29 Connection::the().listen(); 30 }, 31 nullptr); 32 } 33} 34 35void Connection::receive_event(std::unique_ptr<LFoundation::Event> event) 36{ 37 if (event->type() == WinServer::Event::Type::SendEvent) { 38 std::unique_ptr<SendEvent> send_event = std::move(event); 39 m_connection_with_clients.send_message(*send_event->message()); 40 } 41} 42 43} // namespace WinServer