2019-03-12 15:51:42 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Kernel/Socket.h>
|
|
|
|
#include <Kernel/DoubleBuffer.h>
|
|
|
|
#include <Kernel/IPv4.h>
|
2019-03-12 17:27:07 +01:00
|
|
|
#include <AK/Lock.h>
|
|
|
|
#include <AK/SinglyLinkedList.h>
|
2019-03-12 15:51:42 +01:00
|
|
|
|
|
|
|
class IPv4Socket final : public Socket {
|
|
|
|
public:
|
|
|
|
static Retained<IPv4Socket> create(int type, int protocol);
|
|
|
|
virtual ~IPv4Socket() override;
|
|
|
|
|
2019-03-12 17:27:07 +01:00
|
|
|
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
|
|
|
|
2019-03-12 15:51:42 +01:00
|
|
|
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;
|
2019-03-12 17:27:07 +01:00
|
|
|
virtual ssize_t recvfrom(void*, size_t, int flags, const sockaddr*, socklen_t) override;
|
|
|
|
|
|
|
|
void did_receive(ByteBuffer&&);
|
|
|
|
|
|
|
|
Lock& lock() { return m_lock; }
|
2019-03-12 15:51:42 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
IPv4Socket(int type, int protocol);
|
|
|
|
virtual bool is_ipv4() const override { return true; }
|
|
|
|
|
|
|
|
bool m_bound { false };
|
|
|
|
int m_attached_fds { 0 };
|
|
|
|
IPv4Address m_peer_address;
|
|
|
|
|
|
|
|
DoubleBuffer m_for_client;
|
|
|
|
DoubleBuffer m_for_server;
|
2019-03-12 17:27:07 +01:00
|
|
|
|
|
|
|
SinglyLinkedList<ByteBuffer> m_receive_queue;
|
|
|
|
|
|
|
|
Lock m_lock;
|
|
|
|
bool m_can_read { false };
|
2019-03-12 15:51:42 +01:00
|
|
|
};
|
|
|
|
|