ladybird/Kernel/LocalSocket.h
Andreas Kling 6f966ca51d Kernel: Accepting sockets don't need to retain the client sockets.
This is all taken care of by the respective FileDescriptors.
Before this patch, we were leaking every single socket, not great!
2019-03-20 02:48:02 +01:00

40 lines
1.3 KiB
C++

#pragma once
#include <Kernel/Socket.h>
#include <Kernel/DoubleBuffer.h>
class FileDescriptor;
class LocalSocket final : public Socket {
public:
static Retained<LocalSocket> create(int type);
virtual ~LocalSocket() override;
virtual KResult bind(const sockaddr*, socklen_t) override;
virtual KResult connect(const sockaddr*, socklen_t) override;
virtual bool get_address(sockaddr*, socklen_t*) override;
virtual void attach_fd(SocketRole) override;
virtual void detach_fd(SocketRole) override;
virtual bool can_read(SocketRole) const override;
virtual ssize_t read(SocketRole, byte*, ssize_t) override;
virtual ssize_t write(SocketRole, const byte*, ssize_t) override;
virtual bool can_write(SocketRole) const override;
virtual ssize_t sendto(const void*, size_t, int, const sockaddr*, socklen_t) override;
virtual ssize_t recvfrom(void*, size_t, int flags, sockaddr*, socklen_t*) override;
private:
explicit LocalSocket(int type);
virtual bool is_local() const override { return true; }
RetainPtr<FileDescriptor> m_file;
bool m_bound { false };
int m_accepted_fds_open { 0 };
int m_connected_fds_open { 0 };
int m_connecting_fds_open { 0 };
sockaddr_un m_address;
DoubleBuffer m_for_client;
DoubleBuffer m_for_server;
};