2019-02-14 14:17:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <Kernel/Net/Socket.h>
|
2019-02-14 14:17:38 +01:00
|
|
|
|
2019-06-07 09:36:51 +02:00
|
|
|
class FileDescription;
|
2019-02-14 15:17:30 +01:00
|
|
|
|
2019-02-14 14:17:38 +01:00
|
|
|
class LocalSocket final : public Socket {
|
|
|
|
public:
|
2019-06-21 18:37:47 +02:00
|
|
|
static NonnullRefPtr<LocalSocket> create(int type);
|
2019-02-14 14:17:38 +01:00
|
|
|
virtual ~LocalSocket() override;
|
|
|
|
|
2019-08-05 10:03:19 +02:00
|
|
|
// ^Socket
|
2019-03-06 22:14:31 +01:00
|
|
|
virtual KResult bind(const sockaddr*, socklen_t) override;
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
2019-08-06 23:40:38 +10:00
|
|
|
virtual KResult listen(int) 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-06-07 09:36:51 +02:00
|
|
|
virtual void attach(FileDescription&) override;
|
|
|
|
virtual void detach(FileDescription&) override;
|
|
|
|
virtual bool can_read(FileDescription&) const override;
|
|
|
|
virtual bool can_write(FileDescription&) const override;
|
|
|
|
virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
|
|
|
virtual ssize_t recvfrom(FileDescription&, 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-06-07 09:36:51 +02:00
|
|
|
bool has_attached_peer(const FileDescription&) const;
|
2019-02-14 14:17:38 +01:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<FileDescription> m_file;
|
2019-02-14 15:17:30 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|