mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 10:07:40 +00:00
Kernel: Allow Socket subclasses to fail construction
For example, socket(AF_INET) should only succeed for valid SOCK_TYPEs.
This commit is contained in:
parent
a93f35ac71
commit
03d73cbaae
5 changed files with 7 additions and 6 deletions
|
@ -51,13 +51,15 @@ Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
|
||||||
return *s_table;
|
return *s_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<IPv4Socket> IPv4Socket::create(int type, int protocol)
|
KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||||
{
|
{
|
||||||
if (type == SOCK_STREAM)
|
if (type == SOCK_STREAM)
|
||||||
return TCPSocket::create(protocol);
|
return TCPSocket::create(protocol);
|
||||||
if (type == SOCK_DGRAM)
|
if (type == SOCK_DGRAM)
|
||||||
return UDPSocket::create(protocol);
|
return UDPSocket::create(protocol);
|
||||||
return adopt(*new IPv4Socket(type, protocol));
|
if (type == SOCK_RAW)
|
||||||
|
return adopt(*new IPv4Socket(type, protocol));
|
||||||
|
return KResult(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPv4Socket::IPv4Socket(int type, int protocol)
|
IPv4Socket::IPv4Socket(int type, int protocol)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class TCPSocket;
|
||||||
|
|
||||||
class IPv4Socket : public Socket {
|
class IPv4Socket : public Socket {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<IPv4Socket> create(int type, int protocol);
|
static KResultOr<NonnullRefPtr<Socket>> create(int type, int protocol);
|
||||||
virtual ~IPv4Socket() override;
|
virtual ~IPv4Socket() override;
|
||||||
|
|
||||||
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
||||||
|
|
|
@ -50,7 +50,7 @@ void LocalSocket::for_each(Function<void(LocalSocket&)> callback)
|
||||||
callback(socket);
|
callback(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<LocalSocket> LocalSocket::create(int type)
|
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
|
||||||
{
|
{
|
||||||
return adopt(*new LocalSocket(type));
|
return adopt(*new LocalSocket(type));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FileDescription;
|
||||||
class LocalSocket final : public Socket, public InlineLinkedListNode<LocalSocket> {
|
class LocalSocket final : public Socket, public InlineLinkedListNode<LocalSocket> {
|
||||||
friend class InlineLinkedListNode<LocalSocket>;
|
friend class InlineLinkedListNode<LocalSocket>;
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<LocalSocket> create(int type);
|
static KResultOr<NonnullRefPtr<Socket>> create(int type);
|
||||||
virtual ~LocalSocket() override;
|
virtual ~LocalSocket() override;
|
||||||
|
|
||||||
static void for_each(Function<void(LocalSocket&)>);
|
static void for_each(Function<void(LocalSocket&)>);
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
|
KResultOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
(void)protocol;
|
|
||||||
switch (domain) {
|
switch (domain) {
|
||||||
case AF_LOCAL:
|
case AF_LOCAL:
|
||||||
return LocalSocket::create(type & SOCK_TYPE_MASK);
|
return LocalSocket::create(type & SOCK_TYPE_MASK);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue