mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05: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;
|
||||
}
|
||||
|
||||
NonnullRefPtr<IPv4Socket> IPv4Socket::create(int type, int protocol)
|
||||
KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||
{
|
||||
if (type == SOCK_STREAM)
|
||||
return TCPSocket::create(protocol);
|
||||
if (type == SOCK_DGRAM)
|
||||
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)
|
||||
|
|
|
@ -41,7 +41,7 @@ class TCPSocket;
|
|||
|
||||
class IPv4Socket : public Socket {
|
||||
public:
|
||||
static NonnullRefPtr<IPv4Socket> create(int type, int protocol);
|
||||
static KResultOr<NonnullRefPtr<Socket>> create(int type, int protocol);
|
||||
virtual ~IPv4Socket() override;
|
||||
|
||||
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
||||
|
|
|
@ -50,7 +50,7 @@ void LocalSocket::for_each(Function<void(LocalSocket&)> callback)
|
|||
callback(socket);
|
||||
}
|
||||
|
||||
NonnullRefPtr<LocalSocket> LocalSocket::create(int type)
|
||||
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
|
||||
{
|
||||
return adopt(*new LocalSocket(type));
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class FileDescription;
|
|||
class LocalSocket final : public Socket, public InlineLinkedListNode<LocalSocket> {
|
||||
friend class InlineLinkedListNode<LocalSocket>;
|
||||
public:
|
||||
static NonnullRefPtr<LocalSocket> create(int type);
|
||||
static KResultOr<NonnullRefPtr<Socket>> create(int type);
|
||||
virtual ~LocalSocket() override;
|
||||
|
||||
static void for_each(Function<void(LocalSocket&)>);
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
KResultOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
|
||||
{
|
||||
(void)protocol;
|
||||
switch (domain) {
|
||||
case AF_LOCAL:
|
||||
return LocalSocket::create(type & SOCK_TYPE_MASK);
|
||||
|
|
Loading…
Add table
Reference in a new issue