2019-02-14 14:17:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-06 20:29:48 +02:00
|
|
|
#include <Kernel/Net/Socket.h>
|
2019-02-14 14:17:38 +01:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
|
|
|
|
2019-02-14 15:17:30 +01:00
|
|
|
class FileDescriptor;
|
|
|
|
|
2019-02-14 14:17:38 +01:00
|
|
|
class LocalSocket final : public Socket {
|
|
|
|
public:
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<LocalSocket> create(int type);
|
2019-02-14 14:17:38 +01:00
|
|
|
virtual ~LocalSocket() override;
|
|
|
|
|
2019-03-06 22:14:31 +01:00
|
|
|
virtual KResult bind(const sockaddr*, socklen_t) override;
|
2019-05-03 20:15:54 +02:00
|
|
|
virtual KResult connect(FileDescriptor&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
2019-05-20 20:33:03 +02:00
|
|
|
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
|
|
|
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
2019-05-03 20:15:54 +02:00
|
|
|
virtual void attach(FileDescriptor&) override;
|
|
|
|
virtual void detach(FileDescriptor&) override;
|
|
|
|
virtual bool can_read(FileDescriptor&) const override;
|
|
|
|
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
|
|
|
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
|
|
|
virtual bool can_write(FileDescriptor&) const override;
|
|
|
|
virtual ssize_t sendto(FileDescriptor&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
|
|
|
virtual ssize_t recvfrom(FileDescriptor&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
2019-02-14 16:01:08 +01:00
|
|
|
|
2019-02-14 14:17:38 +01:00
|
|
|
private:
|
|
|
|
explicit LocalSocket(int type);
|
2019-02-14 15:55:19 +01:00
|
|
|
virtual bool is_local() const override { return true; }
|
2019-05-20 02:54:52 +02:00
|
|
|
bool has_attached_peer(const FileDescriptor&) const;
|
2019-02-14 14:17:38 +01:00
|
|
|
|
2019-02-14 15:17:30 +01:00
|
|
|
RetainPtr<FileDescriptor> m_file;
|
|
|
|
|
|
|
|
bool m_bound { false };
|
2019-02-17 11:00:35 +01:00
|
|
|
int m_accepted_fds_open { 0 };
|
|
|
|
int m_connected_fds_open { 0 };
|
2019-03-20 02:33:51 +01:00
|
|
|
int m_connecting_fds_open { 0 };
|
2019-02-14 15:17:30 +01:00
|
|
|
sockaddr_un m_address;
|
|
|
|
|
2019-02-14 14:17:38 +01:00
|
|
|
DoubleBuffer m_for_client;
|
|
|
|
DoubleBuffer m_for_server;
|
|
|
|
};
|
|
|
|
|